diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index d783dca883ff..7b1809e1c5f0 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -14,13 +14,10 @@ permissions: jobs: unit: - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed. - # Use ubuntu-22.04 until Python 3.7 is removed from the test matrix - # https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories runs-on: ubuntu-22.04 strategy: matrix: - python: ['3.7', '3.8', '3.9', '3.10', "3.11", "3.12", "3.13", "3.14"] + python: ['3.9', '3.10', "3.11", "3.12", "3.13", "3.14"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.librarian/generator-input/client-post-processing/add-dependency-google-cloud-common.yaml b/.librarian/generator-input/client-post-processing/add-dependency-google-cloud-common.yaml index c6992913b73f..2471e680d80b 100644 --- a/.librarian/generator-input/client-post-processing/add-dependency-google-cloud-common.yaml +++ b/.librarian/generator-input/client-post-processing/add-dependency-google-cloud-common.yaml @@ -19,14 +19,14 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -34,13 +34,13 @@ replacements: "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-filestore/testing/constraints-3.7.txt + packages/google-cloud-filestore/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 google-cloud-common==1.0.0 - google-auth==2.14.1 + google-auth==2.35.0 count: 1 diff --git a/.librarian/generator-input/client-post-processing/add-missing-dependencies-to-setup-py-constraints.yaml b/.librarian/generator-input/client-post-processing/add-missing-dependencies-to-setup-py-constraints.yaml index f3262d7936c2..9225c75bad4e 100644 --- a/.librarian/generator-input/client-post-processing/add-missing-dependencies-to-setup-py-constraints.yaml +++ b/.librarian/generator-input/client-post-processing/add-missing-dependencies-to-setup-py-constraints.yaml @@ -11,7 +11,7 @@ # 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. -description: setup.py and testing/constraints-3.7.txt are missing necessary dependencies +description: setup.py and testing/constraints-3.9.txt are missing necessary dependencies url: https://github.com/googleapis/gapic-generator-python/issues/1831 replacements: - paths: [ @@ -19,14 +19,14 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -34,29 +34,29 @@ replacements: "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-gke-hub/testing/constraints-3.7.txt + packages/google-cloud-gke-hub/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 grpc-google-iam-v1==0.12.4 - google-auth==2.14.1 + google-auth==2.35.0 count: 1 - paths: [ packages/google-cloud-build/setup.py ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -64,70 +64,70 @@ replacements: "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-build/testing/constraints-3.7.txt + packages/google-cloud-build/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 grpc-google-iam-v1==0.12.4 - google-auth==2.14.1 + google-auth==2.35.0 count: 1 - paths: [ packages/google-cloud-binary-authorization/setup.py ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "grafeas >= 1.1.2, <2.0", + "grafeas >= 1.7.0, <2.0", "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-binary-authorization/testing/constraints-3.7.txt + packages/google-cloud-binary-authorization/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 - grafeas==1.1.2 - google-auth==2.14.1 + google-api-core==2.21.0 + grafeas==1.7.0 + google-auth==2.35.0 count: 1 - paths: [ - packages/google-cloud-iam/testing/constraints-3.7.txt + packages/google-cloud-iam/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 grpc-google-iam-v1==0.12.4 - google-auth==2.14.1 + google-auth==2.35.0 count: 1 - paths: [ packages/google-cloud-iam/setup.py ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -139,14 +139,14 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -158,14 +158,14 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -173,13 +173,13 @@ replacements: "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-shopping-merchant-notifications/testing/constraints-3.7.txt + packages/google-shopping-merchant-notifications/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 google-shopping-type==1.0.0 - google-auth==2.14.1 + google-auth==2.35.0 count: 1 diff --git a/.librarian/generator-input/client-post-processing/bigquery-storage-integration.yaml b/.librarian/generator-input/client-post-processing/bigquery-storage-integration.yaml index 00b9e1682ab9..827f4779be03 100644 --- a/.librarian/generator-input/client-post-processing/bigquery-storage-integration.yaml +++ b/.librarian/generator-input/client-post-processing/bigquery-storage-integration.yaml @@ -121,10 +121,9 @@ replacements: extras = \{\} after: | extras = { - # 'importlib-metadata' is required for Python 3.7 compatibility - "pandas": ["pandas>=0.21.1", "importlib-metadata>=1.0.0; python_version<'3.8'"], - "fastavro": ["fastavro>=0.21.2"], - "pyarrow": ["pyarrow>=0.15.0"], + "pandas": ["pandas>=1.1.3"], + "fastavro": ["fastavro>=1.1.0"], + "pyarrow": ["pyarrow>=3.0.0"], } count: 1 - paths: [ @@ -452,20 +451,22 @@ replacements: ) count: 1 - paths: [ - packages/google-cloud-bigquery-storage/testing/constraints-3.7.txt, + packages/google-cloud-bigquery-storage/testing/constraints-3.9.txt, ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 libcst==0.2.5 - fastavro==0.21.2 + fastavro==1.1.0 # pytz is required by pandas pytz - pandas==1.0.5 - pyarrow==0.15.0 - google-auth==2.14.1 + pandas==1.1.3 + # numpy is a dependency of pandas + numpy==1.19.3 + pyarrow==3.0.0 + google-auth==2.35.0 count: 1 # Given that this file is mostly handwritten, we could omit the file during code generation # This will require a change to gapic-generator-python to provide the ability to omit files diff --git a/.librarian/generator-input/client-post-processing/containeranalysis-grafeas-integration.yaml b/.librarian/generator-input/client-post-processing/containeranalysis-grafeas-integration.yaml index 8b88081a2f26..5a06d4b842b5 100644 --- a/.librarian/generator-input/client-post-processing/containeranalysis-grafeas-integration.yaml +++ b/.librarian/generator-input/client-post-processing/containeranalysis-grafeas-integration.yaml @@ -19,30 +19,30 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "grafeas >=1.4.1, <2.0", + "grafeas >=1.7.0, <2.0", "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-containeranalysis/testing/constraints-3.7.txt + packages/google-cloud-containeranalysis/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 - grafeas==1.4.1 - google-auth==2.14.1 + google-api-core==2.21.0 + grafeas==1.7.0 + google-auth==2.35.0 count: 1 - paths: [ packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py, diff --git a/.librarian/generator-input/client-post-processing/firestore-integration.yaml b/.librarian/generator-input/client-post-processing/firestore-integration.yaml index 766a560ee5f0..1c0d4b03b998 100644 --- a/.librarian/generator-input/client-post-processing/firestore-integration.yaml +++ b/.librarian/generator-input/client-post-processing/firestore-integration.yaml @@ -16,15 +16,15 @@ description: Integrate Google Cloud Firestore Handwritten code url: https://github.com/googleapis/gapic-generator-python/issues/123 replacements: - paths: [ - "packages/google-cloud-firestore/testing/constraints-3.7.txt", + "packages/google-cloud-firestore/testing/constraints-3.9.txt", ] before: | proto-plus==1.22.3 - protobuf==3.20.2 + protobuf==4.25.8 after: | proto-plus==1.22.3 - google-cloud-core==1.4.1 - protobuf==3.20.2 + google-cloud-core==1.7.3 + protobuf==4.25.8 count: 1 - paths: [ "packages/google-cloud-firestore/google/cloud/firestore_bundle/types/bundle.py", @@ -539,7 +539,7 @@ replacements: \ "grpcio >= 1.33.2, < 2.0.0", after: | "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "google-cloud-core >= 1.4.1, <3.0.0", + "google-cloud-core >= 1.7.3, <3.0.0", "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ diff --git a/.librarian/generator-input/client-post-processing/integrate-isolated-handwritten-code.yaml b/.librarian/generator-input/client-post-processing/integrate-isolated-handwritten-code.yaml index 986ed5853c3a..27237c3df746 100644 --- a/.librarian/generator-input/client-post-processing/integrate-isolated-handwritten-code.yaml +++ b/.librarian/generator-input/client-post-processing/integrate-isolated-handwritten-code.yaml @@ -60,30 +60,30 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "google-cloud-core >= 1.4.4, <3.0.0", + "google-cloud-core >= 1.7.3, <3.0.0", "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - "packages/google-cloud-translate/testing/constraints-3.7.txt" + "packages/google-cloud-translate/testing/constraints-3.9.txt" ] before: | proto-plus==1.22.3 - protobuf==3.20.2 + protobuf==4.25.8 after: | proto-plus==1.22.3 - google-cloud-core==1.4.4 - protobuf==3.20.2 + google-cloud-core==1.7.3 + protobuf==4.25.8 count: 1 - paths: [ "packages/google-cloud-translate/docs/index.rst", @@ -164,18 +164,18 @@ replacements: ] before: extras = \{\} after: | - extras = {"pandas": "pandas >= 0.23.2"} + extras = {"pandas": "pandas >= 1.1.3"} count: 1 - paths: [ - packages/google-cloud-monitoring/testing/constraints-3.7.txt, + packages/google-cloud-monitoring/testing/constraints-3.9.txt, ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 - pandas==0.23.2 - google-auth==2.14.1 + google-api-core==2.21.0 + pandas==1.1.3 + google-auth==2.35.0 count: 1 - paths: [ packages/google-cloud-monitoring/noxfile.py, @@ -213,22 +213,22 @@ replacements: after: | extras = { "libcst": "libcst >= 0.2.5", - "pandas": ["pandas>=1.0.5"], + "pandas": ["pandas>=1.1.3"], "storage": ["google-cloud-storage >=1.18.0, <4.0.0"], } count: 1 - paths: [ - packages/google-cloud-automl/testing/constraints-3.7.txt, + packages/google-cloud-automl/testing/constraints-3.9.txt, ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 google-cloud-storage==1.18.0 libcst==0.2.5 - pandas==1.0.5 - google-auth==2.14.1 + pandas==1.1.3 + google-auth==2.35.0 count: 1 - paths: [ packages/google-cloud-automl/docs/automl_v1beta1/services_.rst, @@ -340,19 +340,19 @@ replacements: "grpcio >= 1.33.2, < 2.0.0", after: | "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "google-cloud-logging>=1.14.0, <4.0.0", + "google-cloud-logging>=1.15.2, <4.0.0", "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-error-reporting/testing/constraints-3.7.txt, + packages/google-cloud-error-reporting/testing/constraints-3.9.txt, ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 - google-cloud-logging==1.14.0 - google-auth==2.14.1 + google-api-core==2.21.0 + google-cloud-logging==1.15.2 + google-auth==2.35.0 count: 1 - paths: [ "packages/google-cloud-error-reporting/docs/index.rst", @@ -392,3 +392,45 @@ replacements: Changelog count: 1 + - paths: [ + "packages/google-cloud-bigquery-storage/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 + - paths: [ + "packages/google-cloud-datastore/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 + - paths: [ + "packages/google-cloud-error-reporting/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 + - paths: [ + "packages/google-cloud-monitoring-dashboards/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 + - paths: [ + "packages/google-cloud-monitoring/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 + - paths: [ + "packages/google-cloud-speech/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 + - paths: [ + "packages/google-cloud-vision/noxfile.py", + ] + before: '\n "--check-untyped-defs",' + after: '\n # TODO(https://github.com/googleapis/google-cloud-python/issues/16083)\n # "--check-untyped-defs",' + count: 1 diff --git a/.librarian/generator-input/client-post-processing/logging-integration.yaml b/.librarian/generator-input/client-post-processing/logging-integration.yaml index 885f18afc00e..dc7955067b7e 100644 --- a/.librarian/generator-input/client-post-processing/logging-integration.yaml +++ b/.librarian/generator-input/client-post-processing/logging-integration.yaml @@ -286,11 +286,11 @@ replacements: after: 'logging_v2.types.Tail' count: 2 - paths: [ - "packages/google-cloud-logging/testing/constraints-3.7.txt", + "packages/google-cloud-logging/testing/constraints-3.9.txt", ] before: | proto-plus==1.22.3 - protobuf==3.20.2 + protobuf==4.25.8 after: | proto-plus==1.22.3 google-cloud-core==2.0.0 @@ -306,7 +306,7 @@ replacements: markupsafe==2.0.1 itsdangerous==2.0.1 werkzeug==1.0.1 - protobuf==3.20.2 + protobuf==4.25.8 count: 1 - paths: [ "packages/google-cloud-logging/docs/conf.py", @@ -476,7 +476,10 @@ replacements: ] before: | """Run the type checker.""" - [\s\S]*?"google",\n \) + [\s\S]*?"google", + \ "--check-untyped-defs", + \ \*session.posargs, + \ \) after: | """Run the type checker.""" diff --git a/.librarian/generator-input/client-post-processing/mypy-error-with-org-policy-as-dependency.yaml b/.librarian/generator-input/client-post-processing/mypy-error-with-org-policy-as-dependency.yaml index 2c244b441296..76c32ad18dce 100644 --- a/.librarian/generator-input/client-post-processing/mypy-error-with-org-policy-as-dependency.yaml +++ b/.librarian/generator-input/client-post-processing/mypy-error-with-org-policy-as-dependency.yaml @@ -19,14 +19,14 @@ replacements: ] before: | dependencies = \[ - "google-api-core\[grpc\] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core\[grpc\] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", "grpcio >= 1.33.2, < 2.0.0", after: | dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -34,13 +34,13 @@ replacements: "grpcio >= 1.33.2, < 2.0.0", count: 1 - paths: [ - packages/google-cloud-asset/testing/constraints-3.7.txt + packages/google-cloud-asset/testing/constraints-3.9.txt ] before: | - google-api-core==1.34.1 - google-auth==2.14.1 + google-api-core==2.21.0 + google-auth==2.35.0 after: | - google-api-core==1.34.1 + google-api-core==2.21.0 google-cloud-org-policy==0.1.2 - google-auth==2.14.1 + google-auth==2.35.0 count: 1 diff --git a/.librarian/generator-input/client-post-processing/pubsub-integration.yaml b/.librarian/generator-input/client-post-processing/pubsub-integration.yaml index 8e2c953576b1..90cada35fa62 100644 --- a/.librarian/generator-input/client-post-processing/pubsub-integration.yaml +++ b/.librarian/generator-input/client-post-processing/pubsub-integration.yaml @@ -387,28 +387,6 @@ replacements: after: 'description = "Google Cloud Pub/Sub API client library"' count: 1 - # --- FIX: Drop Py 3.7/3.8 classifiers in setup.py --- - - paths: - - "packages/google-cloud-pubsub/setup.py" - before: '([ \t]+"Programming Language :: Python :: 3",\n)[ \t]+"Programming Language :: Python :: 3\.7",\n[ \t]+"Programming Language :: Python :: 3\.8",\n' - after: '\g<1>' - count: 1 - - # --- FIX: Restore setup.py python_requires to >=3.9 --- - - paths: - - "packages/google-cloud-pubsub/setup.py" - before: 'python_requires=">=3\.7",' - after: 'python_requires=">=3.9",' - count: 1 - - # --- FIX: Restore comment and allow google-api-core >= 1.34.0 --- - - paths: - - "packages/google-cloud-pubsub/setup.py" - before: '([ \t]+)"google-api-core\[grpc\] >= 1\.34\.1,([^"]+)",' - after: |- - \g<1># google-api-core >= 1.34.0 is allowed in order to support google-api-core 1.x - \g<1>"google-api-core[grpc] >= 1.34.0,\g<2>", - count: 1 # --- FIX: Restore pubsub-specific grpcio bound --- - paths: @@ -429,23 +407,6 @@ replacements: ] extras = {"libcst": "libcst >= 0.3.10"} count: 1 -# --- FIX: Blend README Python versions --- - - paths: - - "packages/google-cloud-pubsub/README.rst" - before: 'Supported Python Versions\n\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^[\s\S]+?\.\. _end-of-life: https://devguide\.python\.org/devcycle/#end-of-life-branches' - after: |- - Supported Python Versions - ^^^^^^^^^^^^^^^^^^^^^^^^^ - Python >= 3.9 - - Deprecated Python Versions - ^^^^^^^^^^^^^^^^^^^^^^^^^^ - Python < 3.9 - - The last version of this library compatible with Python 3.7 and 3.8 is google-cloud-pubsub==2.34.0. - - The last version of this library compatible with Python 2.7 is google-cloud-pubsub==1.7.0. - count: 1 - paths: - "packages/google-cloud-pubsub/noxfile.py" before: 'UNIT_TEST_DEPENDENCIES: List\[str\] = \[\]' @@ -548,17 +509,6 @@ replacements: \g<1> count: 1 - - paths: - - "packages/google-cloud-pubsub/noxfile.py" - before: '# Install all test dependencies, then install this package in-place\.\n\n([ \t]+)# TODO\(https://github\.com/googleapis/gapic-generator-python/issues/2388\):' - after: |- - # Install all test dependencies, then install this package in-place. - - \g<1>if session.python in ["3.7", "3.8"]: - \g<1> session.skip(f"Python {session.python} is no longer supported.") - - \g<1># TODO(https://github.com/googleapis/gapic-generator-python/issues/2388): - count: 1 - paths: - "packages/google-cloud-pubsub/noxfile.py" before: 'def core_deps_from_source\(session, protobuf_implementation\):[\s\S]+?PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,\n[ \t]+},\n[ \t]+\)' @@ -567,25 +517,11 @@ replacements: """Skipping until Pub/Sub migration is complete.""" session.skip("Skipping core_deps_from_source for google-cloud-pubsub.") count: 1 - - paths: - - "packages/google-cloud-pubsub/noxfile.py" - before: 'SYSTEM_TEST_PYTHON_VERSIONS: List\[str\] = ALL_PYTHON' - after: 'SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.12"]' - count: 1 - paths: - "packages/google-cloud-pubsub/noxfile.py" before: '"--cov=google",' after: '"--cov=google/cloud",' count: 1 - - paths: - - "packages/google-cloud-pubsub/noxfile.py" - before: '([ \t]+)session\.install\("--pre", "grpcio"\)' - after: |- - \g<1># Use pre-release gRPC for system tests. - \g<1># Exclude version 1.52.0rc1 which has a known issue. - \g<1># See https://github.com/grpc/grpc/issues/32163 - \g<1>session.install("--pre", "grpcio!=1.52.0rc1") - count: 1 - paths: - "packages/google-cloud-pubsub/docs/conf.py" before: 'exclude_patterns = \[\n([ \t]+)"_build",' diff --git a/.librarian/generator-input/client-post-processing/unique-grafeas-client.yaml b/.librarian/generator-input/client-post-processing/unique-grafeas-client.yaml index 2be1435ed04f..2721437f2b51 100644 --- a/.librarian/generator-input/client-post-processing/unique-grafeas-client.yaml +++ b/.librarian/generator-input/client-post-processing/unique-grafeas-client.yaml @@ -236,7 +236,7 @@ replacements: # Use backslashes to preserve leading spaces before: | \ @property - \ def api_endpoint\(self\): + \ def api_endpoint\(self\) -> str: [\s\S]*?return self\._client\._universe_domain\n after: "" count: 1 diff --git a/.librarian/state.yaml b/.librarian/state.yaml index 29d8d5333810..9270a6ef710e 100644 --- a/.librarian/state.yaml +++ b/.librarian/state.yaml @@ -1,4 +1,4 @@ -image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:160860d189ff1c2f7515638478823712fa5b243e27ccc33a2728669fa1e2ed0c +image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:7fb1dce6484988a22caf935598e5e0d95bc8659b3342058e824fa826bd9a73b0 libraries: - id: bigquery-magics version: 0.12.1 @@ -858,7 +858,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-bigquery-storage version: 2.36.2 - last_generated_commit: 6df3ecf4fd43b64826de6a477d1a535ec18b0d7c + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/cloud/bigquery/storage/v1beta2 service_config: bigquerystorage_v1beta2.yaml @@ -1407,7 +1407,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-datastore version: 2.23.0 - last_generated_commit: ce8678a96c8e1fc0d870d80fcf062e5be2b12877 + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/datastore/admin/v1 service_config: datastore_v1.yaml @@ -1697,7 +1697,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-error-reporting version: 1.14.0 - last_generated_commit: 6df3ecf4fd43b64826de6a477d1a535ec18b0d7c + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/devtools/clouderrorreporting/v1beta1 service_config: clouderrorreporting_v1beta1.yaml @@ -2371,7 +2371,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-monitoring version: 2.29.1 - last_generated_commit: 3322511885371d2b2253f209ccc3aa60d4100cfd + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/monitoring/v3 service_config: monitoring.yaml @@ -2391,7 +2391,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-monitoring-dashboards version: 2.20.1 - last_generated_commit: 3322511885371d2b2253f209ccc3aa60d4100cfd + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/monitoring/dashboard/v1 service_config: monitoring.yaml @@ -3163,7 +3163,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-speech version: 2.37.0 - last_generated_commit: c662840a94dbdf708caa44893a2d49119cdd391c + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/cloud/speech/v1 service_config: speech_v1.yaml @@ -3471,7 +3471,7 @@ libraries: tag_format: '{id}-v{version}' - id: google-cloud-vision version: 3.12.1 - last_generated_commit: 3322511885371d2b2253f209ccc3aa60d4100cfd + last_generated_commit: 256b575f6915282b20795c13414b21f2c0af65db apis: - path: google/cloud/vision/v1p3beta1 service_config: vision_v1p3beta1.yaml diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/client.py index 742c1e15e9a2..4980381126c8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/client.py @@ -114,7 +114,7 @@ class AdBreakServiceClient(metaclass=AdBreakServiceClientMeta): """Provides methods for handling ``AdBreak`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -556,7 +560,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -652,7 +656,7 @@ def __init__( self._universe_domain = AdBreakServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1376,7 +1380,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1402,8 +1406,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1412,7 +1420,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1421,7 +1429,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/README.rst index 1507fcb9b471..afa98614f702 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AdBreakServiceTransport` is the ABC for all transports. -- public child `AdBreakServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AdBreakServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAdBreakServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AdBreakServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AdBreakServiceTransport`` is the ABC for all transports. + +- public child ``AdBreakServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AdBreakServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAdBreakServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AdBreakServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/base.py index f62045ec90dc..a6ebf5da884f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/rest.py index 520f27684cd0..8bc970bf56a8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_break_service/transports/rest.py @@ -416,6 +416,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AdBreakServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/client.py index a05ef2f6d1b7..f596d396a8e4 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/client.py @@ -112,7 +112,7 @@ class AdReviewCenterAdServiceClient(metaclass=AdReviewCenterAdServiceClientMeta) """Provides methods for handling AdReviewCenterAd objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -457,7 +461,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -556,7 +560,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -658,7 +662,7 @@ def __init__( self._universe_domain = AdReviewCenterAdServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1213,7 +1217,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1239,8 +1243,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1249,7 +1257,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1258,7 +1266,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/README.rst index 6899571aa192..01ffa6b5e324 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AdReviewCenterAdServiceTransport` is the ABC for all transports. -- public child `AdReviewCenterAdServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AdReviewCenterAdServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAdReviewCenterAdServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AdReviewCenterAdServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AdReviewCenterAdServiceTransport`` is the ABC for all transports. + +- public child ``AdReviewCenterAdServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AdReviewCenterAdServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAdReviewCenterAdServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AdReviewCenterAdServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/base.py index fdc7dc2d9d84..a75220c0dabb 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/rest.py index 41dd10bbe278..9ed0470cb875 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_review_center_ad_service/transports/rest.py @@ -345,6 +345,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AdReviewCenterAdServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/client.py index d5e9814c0dfe..f47664da0a4b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/client.py @@ -115,7 +115,7 @@ class AdUnitServiceClient(metaclass=AdUnitServiceClientMeta): """Provides methods for handling AdUnit objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -484,7 +488,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -581,7 +585,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -677,7 +681,7 @@ def __init__( self._universe_domain = AdUnitServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1964,7 +1968,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1990,8 +1994,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2000,7 +2008,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2009,7 +2017,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/README.rst index 1158d0f6420d..2e007318cf42 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AdUnitServiceTransport` is the ABC for all transports. -- public child `AdUnitServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AdUnitServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAdUnitServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AdUnitServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AdUnitServiceTransport`` is the ABC for all transports. + +- public child ``AdUnitServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AdUnitServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAdUnitServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AdUnitServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/base.py index 08ed693dab8c..39240c0b8892 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/rest.py index 1850a8318b32..e54019b441ae 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/ad_unit_service/transports/rest.py @@ -755,6 +755,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AdUnitServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/client.py index 0e7a626845b9..331a67bbac32 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/client.py @@ -107,7 +107,7 @@ class ApplicationServiceClient(metaclass=ApplicationServiceClientMeta): """Provides methods for handling ``Application`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -641,7 +645,7 @@ def __init__( self._universe_domain = ApplicationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -988,7 +992,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1014,8 +1018,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1024,7 +1032,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1033,7 +1041,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/README.rst index 42bc947a9f22..adf6dbaa2303 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApplicationServiceTransport` is the ABC for all transports. -- public child `ApplicationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApplicationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApplicationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApplicationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApplicationServiceTransport`` is the ABC for all transports. + +- public child ``ApplicationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApplicationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApplicationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApplicationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/base.py index 9125ca11c6b5..2d7fa6100fc9 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/rest.py index 738d8c1dbbb3..1b7bce417c3d 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/application_service/transports/rest.py @@ -290,6 +290,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApplicationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/client.py index 8bd2e0a3ce73..de347302733c 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/client.py @@ -110,7 +110,7 @@ class AudienceSegmentServiceClient(metaclass=AudienceSegmentServiceClientMeta): """Provides methods for handling ``AudienceSegment`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = AudienceSegmentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -994,7 +998,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1020,8 +1024,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1030,7 +1038,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1039,7 +1047,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/README.rst index fe685a189df3..c23bfb49668a 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AudienceSegmentServiceTransport` is the ABC for all transports. -- public child `AudienceSegmentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AudienceSegmentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAudienceSegmentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AudienceSegmentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AudienceSegmentServiceTransport`` is the ABC for all transports. + +- public child ``AudienceSegmentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AudienceSegmentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAudienceSegmentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AudienceSegmentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/base.py index aabe0d0279c8..ffe53dfaf0e8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/rest.py index 188597bfcef6..007006d67f43 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/audience_segment_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AudienceSegmentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/client.py index 97f4267bad05..7fbdb799fe85 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/client.py @@ -110,7 +110,7 @@ class BandwidthGroupServiceClient(metaclass=BandwidthGroupServiceClientMeta): """Provides methods for handling ``BandwidthGroup`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = BandwidthGroupServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -995,7 +999,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1021,8 +1025,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1031,7 +1039,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1040,7 +1048,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/README.rst index 6639f2e3f77a..3b65f25365b2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BandwidthGroupServiceTransport` is the ABC for all transports. -- public child `BandwidthGroupServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BandwidthGroupServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBandwidthGroupServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BandwidthGroupServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BandwidthGroupServiceTransport`` is the ABC for all transports. + +- public child ``BandwidthGroupServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BandwidthGroupServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBandwidthGroupServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BandwidthGroupServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/base.py index 8337018ac15f..b6e697480b48 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/rest.py index 9d6b21cc5399..348a83cded1b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/bandwidth_group_service/transports/rest.py @@ -293,6 +293,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BandwidthGroupServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/client.py index 74307fada64e..60fe171fc507 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/client.py @@ -110,7 +110,7 @@ class BrowserLanguageServiceClient(metaclass=BrowserLanguageServiceClientMeta): """Provides methods for handling ``BrowserLanguage`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = BrowserLanguageServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -993,7 +997,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1019,8 +1023,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1029,7 +1037,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1038,7 +1046,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/README.rst index 0d8aa957ddb2..12032ad5a393 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BrowserLanguageServiceTransport` is the ABC for all transports. -- public child `BrowserLanguageServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BrowserLanguageServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBrowserLanguageServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BrowserLanguageServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BrowserLanguageServiceTransport`` is the ABC for all transports. + +- public child ``BrowserLanguageServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BrowserLanguageServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBrowserLanguageServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BrowserLanguageServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/base.py index 4b85e2f2d72f..43f518ed7ba2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/rest.py index 523d03a2b385..41b501c92680 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_language_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BrowserLanguageServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/client.py index 3b54412cc6dc..84310f0f2f5e 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/client.py @@ -107,7 +107,7 @@ class BrowserServiceClient(metaclass=BrowserServiceClientMeta): """Provides methods for handling ``Browser`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -637,7 +641,7 @@ def __init__( self._universe_domain = BrowserServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -977,7 +981,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1003,8 +1007,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1013,7 +1021,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1022,7 +1030,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/README.rst index 08bf910e6862..e6030c9eb06d 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BrowserServiceTransport` is the ABC for all transports. -- public child `BrowserServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BrowserServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBrowserServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BrowserServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BrowserServiceTransport`` is the ABC for all transports. + +- public child ``BrowserServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BrowserServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBrowserServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BrowserServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/base.py index 4786de410282..73a5843907d2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/rest.py index 242bc55dcb22..3cc65e4db600 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/browser_service/transports/rest.py @@ -285,6 +285,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BrowserServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/client.py index e5296369d232..340280f74bc3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/client.py @@ -111,7 +111,7 @@ class CmsMetadataKeyServiceClient(metaclass=CmsMetadataKeyServiceClientMeta): """Provides methods for handling ``CmsMetadataKey`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -648,7 +652,7 @@ def __init__( self._universe_domain = CmsMetadataKeyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -994,7 +998,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1020,8 +1024,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1030,7 +1038,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1039,7 +1047,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/README.rst index 5c39bcc3649b..42633ea171c0 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CmsMetadataKeyServiceTransport` is the ABC for all transports. -- public child `CmsMetadataKeyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CmsMetadataKeyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCmsMetadataKeyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CmsMetadataKeyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CmsMetadataKeyServiceTransport`` is the ABC for all transports. + +- public child ``CmsMetadataKeyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CmsMetadataKeyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCmsMetadataKeyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CmsMetadataKeyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/base.py index b6d059cee96f..fd538ab35bf0 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/rest.py index 44ff0a90719e..e5e4d06a8925 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_key_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CmsMetadataKeyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/client.py index 55d30c3d083e..5443834c6ff3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/client.py @@ -111,7 +111,7 @@ class CmsMetadataValueServiceClient(metaclass=CmsMetadataValueServiceClientMeta) """Provides methods for handling ``CmsMetadataValue`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -469,7 +473,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -670,7 +674,7 @@ def __init__( self._universe_domain = CmsMetadataValueServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1020,7 +1024,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1046,8 +1050,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1056,7 +1064,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1065,7 +1073,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/README.rst index 2c2ac8792a09..47acc0a489d6 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CmsMetadataValueServiceTransport` is the ABC for all transports. -- public child `CmsMetadataValueServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CmsMetadataValueServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCmsMetadataValueServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CmsMetadataValueServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CmsMetadataValueServiceTransport`` is the ABC for all transports. + +- public child ``CmsMetadataValueServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CmsMetadataValueServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCmsMetadataValueServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CmsMetadataValueServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/base.py index 2c11cd33402d..0d2c9eb686f8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/rest.py index ff26c2594d4f..d22eb3f9c2bc 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/cms_metadata_value_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CmsMetadataValueServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/client.py index 779d7304a55f..8d9a27e26e2f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/client.py @@ -113,7 +113,7 @@ class CompanyServiceClient(metaclass=CompanyServiceClientMeta): """Provides methods for handling ``Company`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -503,7 +507,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -600,7 +604,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -696,7 +700,7 @@ def __init__( self._universe_domain = CompanyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1034,7 +1038,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1060,8 +1064,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1070,7 +1078,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1079,7 +1087,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/README.rst index f44fab066f99..6ae8631f018a 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CompanyServiceTransport` is the ABC for all transports. -- public child `CompanyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CompanyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCompanyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CompanyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CompanyServiceTransport`` is the ABC for all transports. + +- public child ``CompanyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CompanyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCompanyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CompanyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/base.py index 6c52bec87938..9676a1f70dd3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/rest.py index 2541be08436d..a1953557ac95 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/company_service/transports/rest.py @@ -285,6 +285,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CompanyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/client.py index 47fa8c2bf3ec..f5098ec9be58 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/client.py @@ -112,7 +112,7 @@ class ContactServiceClient(metaclass=ContactServiceClientMeta): """Provides methods for handling ``Contact`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = ContactServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1492,7 +1496,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1518,8 +1522,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1528,7 +1536,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1537,7 +1545,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/README.rst index c419382d086e..549d3f69dd46 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContactServiceTransport` is the ABC for all transports. -- public child `ContactServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContactServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContactServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContactServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContactServiceTransport`` is the ABC for all transports. + +- public child ``ContactServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContactServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContactServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContactServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/base.py index b12f5ec0224e..22cdee1ddad9 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/rest.py index 411f40a746ed..9d20fc40049b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/contact_service/transports/rest.py @@ -517,6 +517,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContactServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/client.py index baf43d2ab53d..aa4e7298c557 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/client.py @@ -110,7 +110,7 @@ class ContentBundleServiceClient(metaclass=ContentBundleServiceClientMeta): """Provides methods for handling ``ContentBundle`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -545,7 +549,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -645,7 +649,7 @@ def __init__( self._universe_domain = ContentBundleServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -997,7 +1001,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1023,8 +1027,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1033,7 +1041,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1042,7 +1050,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/README.rst index 1b814a9be9b5..47899d93e78a 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContentBundleServiceTransport` is the ABC for all transports. -- public child `ContentBundleServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContentBundleServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContentBundleServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContentBundleServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContentBundleServiceTransport`` is the ABC for all transports. + +- public child ``ContentBundleServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContentBundleServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContentBundleServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContentBundleServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/base.py index 65333bb2a392..81b605be73d8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/rest.py index aad63c04ffbc..a7c5ae169f05 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_bundle_service/transports/rest.py @@ -293,6 +293,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContentBundleServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/client.py index 6e1af6c11bb3..506edfa50657 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/client.py @@ -107,7 +107,7 @@ class ContentLabelServiceClient(metaclass=ContentLabelServiceClientMeta): """Provides methods for handling ``ContentLabel`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -445,7 +449,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -542,7 +546,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -642,7 +646,7 @@ def __init__( self._universe_domain = ContentLabelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -985,7 +989,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1011,8 +1015,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1021,7 +1029,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1030,7 +1038,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/README.rst index 4f9d86d0a7e9..e49d0c03f25f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContentLabelServiceTransport` is the ABC for all transports. -- public child `ContentLabelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContentLabelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContentLabelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContentLabelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContentLabelServiceTransport`` is the ABC for all transports. + +- public child ``ContentLabelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContentLabelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContentLabelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContentLabelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/base.py index 001c8d304e88..0176cbf0dd2c 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/rest.py index e04874b0b718..eb55a0298192 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_label_service/transports/rest.py @@ -290,6 +290,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContentLabelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/client.py index 9c4686798997..021c7cb63bb2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/client.py @@ -107,7 +107,7 @@ class ContentServiceClient(metaclass=ContentServiceClientMeta): """Provides methods for handling ``Content`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = ContentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -975,7 +979,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1001,8 +1005,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1011,7 +1019,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1020,7 +1028,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/README.rst index f737919bf8e5..dc9359b99854 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContentServiceTransport` is the ABC for all transports. -- public child `ContentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContentServiceTransport`` is the ABC for all transports. + +- public child ``ContentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/base.py index 5ece053dc174..6de29b6f9879 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/rest.py index ae6fcbd7c6f2..57acef1fcff4 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/content_service/transports/rest.py @@ -285,6 +285,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/client.py index 13c2c5d09e9c..501786cfc3b3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/client.py @@ -111,7 +111,7 @@ class CreativeTemplateServiceClient(metaclass=CreativeTemplateServiceClientMeta) """Provides methods for handling ``CreativeTemplate`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -650,7 +654,7 @@ def __init__( self._universe_domain = CreativeTemplateServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1000,7 +1004,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1026,8 +1030,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1036,7 +1044,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1053,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/README.rst index f07f72e90564..d6f37e52bdec 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CreativeTemplateServiceTransport` is the ABC for all transports. -- public child `CreativeTemplateServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CreativeTemplateServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCreativeTemplateServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CreativeTemplateServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CreativeTemplateServiceTransport`` is the ABC for all transports. + +- public child ``CreativeTemplateServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CreativeTemplateServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCreativeTemplateServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CreativeTemplateServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/base.py index 056e0c6caa23..05f902d33956 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/rest.py index d168804fde63..0cb8564dd5ae 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/creative_template_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CreativeTemplateServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/client.py index 23aab254162b..cf9a98dc34a1 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/client.py @@ -112,7 +112,7 @@ class CustomFieldServiceClient(metaclass=CustomFieldServiceClientMeta): """Provides methods for handling ``CustomField`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -546,7 +550,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -646,7 +650,7 @@ def __init__( self._universe_domain = CustomFieldServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1724,7 +1728,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1750,8 +1754,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1760,7 +1768,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1769,7 +1777,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/README.rst index a51b3e4aa853..0519b7f9b0f0 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CustomFieldServiceTransport` is the ABC for all transports. -- public child `CustomFieldServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CustomFieldServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCustomFieldServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CustomFieldServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CustomFieldServiceTransport`` is the ABC for all transports. + +- public child ``CustomFieldServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CustomFieldServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCustomFieldServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CustomFieldServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/base.py index cd7d6a072413..806d95c5b050 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/rest.py index 2a4e4ccf071a..78a3a34359b5 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_field_service/transports/rest.py @@ -648,6 +648,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CustomFieldServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/client.py index 8bef80064aba..04561d2cdbac 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/client.py @@ -112,7 +112,7 @@ class CustomTargetingKeyServiceClient(metaclass=CustomTargetingKeyServiceClientM """Provides methods for handling ``CustomTargetingKey`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -452,7 +456,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -551,7 +555,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -653,7 +657,7 @@ def __init__( self._universe_domain = CustomTargetingKeyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1797,7 +1801,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1823,8 +1827,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1833,7 +1841,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1842,7 +1850,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/README.rst index bd23fcc2f0f5..161fadb29b66 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CustomTargetingKeyServiceTransport` is the ABC for all transports. -- public child `CustomTargetingKeyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CustomTargetingKeyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCustomTargetingKeyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CustomTargetingKeyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CustomTargetingKeyServiceTransport`` is the ABC for all transports. + +- public child ``CustomTargetingKeyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CustomTargetingKeyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCustomTargetingKeyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CustomTargetingKeyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/base.py index 4761253f6b5e..2f3bf31b97aa 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/rest.py index a2a1800122dd..082b65218469 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_key_service/transports/rest.py @@ -660,6 +660,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CustomTargetingKeyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/client.py index eec17123836d..680ef2c0a8da 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/client.py @@ -113,7 +113,7 @@ class CustomTargetingValueServiceClient( """Provides methods for handling ``CustomTargetingValue`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -473,7 +477,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -572,7 +576,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -674,7 +678,7 @@ def __init__( self._universe_domain = CustomTargetingValueServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1033,7 +1037,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1063,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1077,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1078,7 +1086,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/README.rst index 8d776582462b..3f504d85a1da 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CustomTargetingValueServiceTransport` is the ABC for all transports. -- public child `CustomTargetingValueServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CustomTargetingValueServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCustomTargetingValueServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CustomTargetingValueServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CustomTargetingValueServiceTransport`` is the ABC for all transports. + +- public child ``CustomTargetingValueServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CustomTargetingValueServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCustomTargetingValueServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CustomTargetingValueServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/base.py index 1171c65cb703..ba2dee8ece07 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/rest.py index bf5cae07c938..e73ba5149850 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/custom_targeting_value_service/transports/rest.py @@ -296,6 +296,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CustomTargetingValueServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/client.py index 5dac58d5681f..e910c3e9a828 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/client.py @@ -110,7 +110,7 @@ class DeviceCapabilityServiceClient(metaclass=DeviceCapabilityServiceClientMeta) """Provides methods for handling ``DeviceCapability`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = DeviceCapabilityServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -997,7 +1001,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1023,8 +1027,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1033,7 +1041,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1042,7 +1050,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/README.rst index 1f0d8b349ac9..73b0ca3abd37 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeviceCapabilityServiceTransport` is the ABC for all transports. -- public child `DeviceCapabilityServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeviceCapabilityServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeviceCapabilityServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeviceCapabilityServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeviceCapabilityServiceTransport`` is the ABC for all transports. + +- public child ``DeviceCapabilityServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeviceCapabilityServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeviceCapabilityServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeviceCapabilityServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/base.py index 6173a69e7ed6..e8d8ba9292f1 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/rest.py index 88dd94e252b1..f940f6a8dbab 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_capability_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeviceCapabilityServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/client.py index 920de19ba80c..55f468d900f4 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/client.py @@ -110,7 +110,7 @@ class DeviceCategoryServiceClient(metaclass=DeviceCategoryServiceClientMeta): """Provides methods for handling ``DeviceCategory`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = DeviceCategoryServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -993,7 +997,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1019,8 +1023,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1029,7 +1037,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1038,7 +1046,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/README.rst index 75ba4c00a654..b88b21353019 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeviceCategoryServiceTransport` is the ABC for all transports. -- public child `DeviceCategoryServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeviceCategoryServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeviceCategoryServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeviceCategoryServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeviceCategoryServiceTransport`` is the ABC for all transports. + +- public child ``DeviceCategoryServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeviceCategoryServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeviceCategoryServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeviceCategoryServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/base.py index 7809286c3508..3ee09eb4a6f8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/rest.py index a2e95d691c85..c147f4705b0f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_category_service/transports/rest.py @@ -293,6 +293,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeviceCategoryServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/client.py index be47ef9cb7f5..a04288687545 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/client.py @@ -110,7 +110,7 @@ class DeviceManufacturerServiceClient(metaclass=DeviceManufacturerServiceClientM """Provides methods for handling ``DeviceManufacturer`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -450,7 +454,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -549,7 +553,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -651,7 +655,7 @@ def __init__( self._universe_domain = DeviceManufacturerServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1003,7 +1007,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1029,8 +1033,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1039,7 +1047,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1048,7 +1056,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/README.rst index af021612bbfb..5334a13185ca 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeviceManufacturerServiceTransport` is the ABC for all transports. -- public child `DeviceManufacturerServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeviceManufacturerServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeviceManufacturerServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeviceManufacturerServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeviceManufacturerServiceTransport`` is the ABC for all transports. + +- public child ``DeviceManufacturerServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeviceManufacturerServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeviceManufacturerServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeviceManufacturerServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/base.py index de6aa6c097ce..de8ad3350a17 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/rest.py index 0eeb3a5bd708..665425560166 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/device_manufacturer_service/transports/rest.py @@ -296,6 +296,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeviceManufacturerServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/client.py index dd8a92913398..8fff463a494c 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/client.py @@ -113,7 +113,7 @@ class EntitySignalsMappingServiceClient( """Provides methods for handling ``EntitySignalsMapping`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -550,7 +554,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -652,7 +656,7 @@ def __init__( self._universe_domain = EntitySignalsMappingServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1567,7 +1571,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1593,8 +1597,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1603,7 +1611,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1612,7 +1620,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/README.rst index 23f5ee207da5..7019e1f4d762 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EntitySignalsMappingServiceTransport` is the ABC for all transports. -- public child `EntitySignalsMappingServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EntitySignalsMappingServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEntitySignalsMappingServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EntitySignalsMappingServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EntitySignalsMappingServiceTransport`` is the ABC for all transports. + +- public child ``EntitySignalsMappingServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EntitySignalsMappingServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEntitySignalsMappingServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EntitySignalsMappingServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/base.py index 06581914586f..41d700d02a17 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/rest.py index cdf41abad502..28598fb8f036 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/entity_signals_mapping_service/transports/rest.py @@ -538,6 +538,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EntitySignalsMappingServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/client.py index 0c1165777d5b..2cf2295c0484 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/client.py @@ -107,7 +107,7 @@ class GeoTargetServiceClient(metaclass=GeoTargetServiceClientMeta): """Provides methods for handling ``GeoTarget`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = GeoTargetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -980,7 +984,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1006,8 +1010,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1016,7 +1024,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1025,7 +1033,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/README.rst index a66054a56060..0160eff1a556 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeoTargetServiceTransport` is the ABC for all transports. -- public child `GeoTargetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeoTargetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeoTargetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeoTargetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeoTargetServiceTransport`` is the ABC for all transports. + +- public child ``GeoTargetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeoTargetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeoTargetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeoTargetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/base.py index 9c97fefd085a..89873f4b89ab 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/rest.py index 9e05825b9f05..ab7a7fdea2e5 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/geo_target_service/transports/rest.py @@ -287,6 +287,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeoTargetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/client.py index bcc7a3bd7201..ba9e963ec464 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/client.py @@ -115,7 +115,7 @@ class LineItemServiceClient(metaclass=LineItemServiceClientMeta): """Provides methods for handling ``LineItem`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -488,7 +492,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -585,7 +589,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -683,7 +687,7 @@ def __init__( self._universe_domain = LineItemServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1025,7 +1029,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1051,8 +1055,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1061,7 +1069,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1070,7 +1078,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/README.rst index a2fac4d37b12..081c1369ef95 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LineItemServiceTransport` is the ABC for all transports. -- public child `LineItemServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LineItemServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLineItemServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LineItemServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LineItemServiceTransport`` is the ABC for all transports. + +- public child ``LineItemServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LineItemServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLineItemServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LineItemServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/base.py index 09418cbc310b..c4e038a2f94b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/rest.py index 770d5a716b22..35b5f7e1f879 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/line_item_service/transports/rest.py @@ -285,6 +285,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LineItemServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/client.py index 8b531473dc60..d01e73e55021 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/client.py @@ -110,7 +110,7 @@ class MobileCarrierServiceClient(metaclass=MobileCarrierServiceClientMeta): """Provides methods for handling ``MobileCarrier`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -545,7 +549,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -645,7 +649,7 @@ def __init__( self._universe_domain = MobileCarrierServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -989,7 +993,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1015,8 +1019,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1025,7 +1033,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1034,7 +1042,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/README.rst index 2095ecbf7d0e..918efa15a455 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MobileCarrierServiceTransport` is the ABC for all transports. -- public child `MobileCarrierServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MobileCarrierServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMobileCarrierServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MobileCarrierServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MobileCarrierServiceTransport`` is the ABC for all transports. + +- public child ``MobileCarrierServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MobileCarrierServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMobileCarrierServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MobileCarrierServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/base.py index 64593884db9f..8da10acaee80 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/rest.py index 0d2f8727ea5a..3db67cb32f58 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_carrier_service/transports/rest.py @@ -293,6 +293,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MobileCarrierServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/client.py index a15f15a6bf30..6e3b1f678855 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/client.py @@ -107,7 +107,7 @@ class MobileDeviceServiceClient(metaclass=MobileDeviceServiceClientMeta): """Provides methods for handling ``MobileDevice`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = MobileDeviceServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1007,7 +1011,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1033,8 +1037,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1043,7 +1051,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1052,7 +1060,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/README.rst index 64872238c0aa..96fc1ae7c142 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MobileDeviceServiceTransport` is the ABC for all transports. -- public child `MobileDeviceServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MobileDeviceServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMobileDeviceServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MobileDeviceServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MobileDeviceServiceTransport`` is the ABC for all transports. + +- public child ``MobileDeviceServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MobileDeviceServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMobileDeviceServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MobileDeviceServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/base.py index 05d7769190cc..3f12c9a22b5c 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/rest.py index 64d13eefecf1..5df7394350d3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_service/transports/rest.py @@ -290,6 +290,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MobileDeviceServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/client.py index 7bba8bf9620e..a172852aea32 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/client.py @@ -112,7 +112,7 @@ class MobileDeviceSubmodelServiceClient( """Provides methods for handling ``MobileDeviceSubmodel`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -470,7 +474,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -671,7 +675,7 @@ def __init__( self._universe_domain = MobileDeviceSubmodelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1030,7 +1034,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1056,8 +1060,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1066,7 +1074,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1075,7 +1083,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/README.rst index b8ff4cf01ee3..e025d8ede468 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MobileDeviceSubmodelServiceTransport` is the ABC for all transports. -- public child `MobileDeviceSubmodelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MobileDeviceSubmodelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMobileDeviceSubmodelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MobileDeviceSubmodelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MobileDeviceSubmodelServiceTransport`` is the ABC for all transports. + +- public child ``MobileDeviceSubmodelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MobileDeviceSubmodelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMobileDeviceSubmodelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MobileDeviceSubmodelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/base.py index 127b7ed67ab7..1fff8b51ece0 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/rest.py index 309d2b5038c2..ce50074d0b6b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/mobile_device_submodel_service/transports/rest.py @@ -296,6 +296,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MobileDeviceSubmodelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/client.py index f9cfc6a97834..6f9d58a4b14f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/client.py @@ -107,7 +107,7 @@ class NetworkServiceClient(metaclass=NetworkServiceClientMeta): """Provides methods for handling ``Network`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = NetworkServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -942,7 +946,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -968,8 +972,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -978,7 +986,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -987,7 +995,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/README.rst index de16337bc162..2dfd064bc4dc 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkServiceTransport` is the ABC for all transports. -- public child `NetworkServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkServiceTransport`` is the ABC for all transports. + +- public child ``NetworkServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/base.py index 769ddd77fb18..ea9821a868f8 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/rest.py index 2e3fe5b080e5..7f63a71d4259 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/network_service/transports/rest.py @@ -285,6 +285,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/client.py index e4d4d148520e..bb647c71d8cd 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/client.py @@ -110,7 +110,7 @@ class OperatingSystemServiceClient(metaclass=OperatingSystemServiceClientMeta): """Provides methods for handling ``OperatingSystem`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = OperatingSystemServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -995,7 +999,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1021,8 +1025,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1031,7 +1039,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1040,7 +1048,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/README.rst index f81885735ee6..c14b9ba041f9 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`OperatingSystemServiceTransport` is the ABC for all transports. -- public child `OperatingSystemServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `OperatingSystemServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseOperatingSystemServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `OperatingSystemServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``OperatingSystemServiceTransport`` is the ABC for all transports. + +- public child ``OperatingSystemServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``OperatingSystemServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseOperatingSystemServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``OperatingSystemServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/base.py index 85b2c3deaa50..95cc9e9c863b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/rest.py index 486ec21b3272..073884429821 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[OperatingSystemServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/client.py index 68e5626177c6..576f81ddde27 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/client.py @@ -112,7 +112,7 @@ class OperatingSystemVersionServiceClient( """Provides methods for handling ``OperatingSystemVersion`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -454,7 +458,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -553,7 +557,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -657,7 +661,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1028,7 +1032,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1058,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1072,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1073,7 +1081,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/README.rst index c79eaec6eae2..6d9b79dbe34a 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`OperatingSystemVersionServiceTransport` is the ABC for all transports. -- public child `OperatingSystemVersionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `OperatingSystemVersionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseOperatingSystemVersionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `OperatingSystemVersionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``OperatingSystemVersionServiceTransport`` is the ABC for all transports. + +- public child ``OperatingSystemVersionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``OperatingSystemVersionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseOperatingSystemVersionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``OperatingSystemVersionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/base.py index 1692e88fbf9f..3e3f71f90ac1 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/rest.py index c7dbd5f9c529..876b32ef2987 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/operating_system_version_service/transports/rest.py @@ -297,6 +297,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[OperatingSystemVersionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/client.py index 62a0142aab7c..1654bb7e50fc 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/client.py @@ -114,7 +114,7 @@ class OrderServiceClient(metaclass=OrderServiceClientMeta): """Provides methods for handling ``Order`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -557,7 +561,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -654,7 +658,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -750,7 +754,7 @@ def __init__( self._universe_domain = OrderServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1091,7 +1095,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1117,8 +1121,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1127,7 +1135,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1136,7 +1144,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/README.rst index 679c35ce0f20..6b1893d86808 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`OrderServiceTransport` is the ABC for all transports. -- public child `OrderServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `OrderServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseOrderServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `OrderServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``OrderServiceTransport`` is the ABC for all transports. + +- public child ``OrderServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``OrderServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseOrderServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``OrderServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/base.py index 8fe8014579d2..96dd78a6ed07 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/rest.py index db92845e7713..7c8063c121ea 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/order_service/transports/rest.py @@ -281,6 +281,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[OrderServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/client.py index 94720a2e9545..e7d7b46a5f06 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/client.py @@ -113,7 +113,7 @@ class PlacementServiceClient(metaclass=PlacementServiceClientMeta): """Provides methods for handling ``Placement`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = PlacementServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1835,7 +1839,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1861,8 +1865,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1871,7 +1879,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1880,7 +1888,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/README.rst index 26be6d48dc21..7e85aac23e8d 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PlacementServiceTransport` is the ABC for all transports. -- public child `PlacementServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PlacementServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePlacementServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PlacementServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PlacementServiceTransport`` is the ABC for all transports. + +- public child ``PlacementServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PlacementServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePlacementServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PlacementServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/base.py index 7b43eb46372c..f206812c9efd 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/rest.py index 117a885ccc99..508b066d495b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/placement_service/transports/rest.py @@ -700,6 +700,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PlacementServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/client.py index 9e117fd86d2b..2cc478582f1b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/client.py @@ -117,7 +117,7 @@ class PrivateAuctionDealServiceClient(metaclass=PrivateAuctionDealServiceClientM """Provides methods for handling ``PrivateAuctionDeal`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -871,7 +875,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -970,7 +974,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1072,7 +1076,7 @@ def __init__( self._universe_domain = PrivateAuctionDealServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1676,7 +1680,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1702,8 +1706,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1712,7 +1720,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1721,7 +1729,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/README.rst index 5714a7948121..dbfc24f9849b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PrivateAuctionDealServiceTransport` is the ABC for all transports. -- public child `PrivateAuctionDealServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PrivateAuctionDealServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePrivateAuctionDealServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PrivateAuctionDealServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PrivateAuctionDealServiceTransport`` is the ABC for all transports. + +- public child ``PrivateAuctionDealServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PrivateAuctionDealServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePrivateAuctionDealServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PrivateAuctionDealServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/base.py index 03e871c09c3d..4eeb64792e7f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/rest.py index 64c41a68cb79..591af7199041 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_deal_service/transports/rest.py @@ -416,6 +416,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PrivateAuctionDealServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/client.py index 89216c65ae55..f6ba13736fc2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/client.py @@ -112,7 +112,7 @@ class PrivateAuctionServiceClient(metaclass=PrivateAuctionServiceClientMeta): """Provides methods for handling ``PrivateAuction`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -566,7 +570,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -666,7 +670,7 @@ def __init__( self._universe_domain = PrivateAuctionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1246,7 +1250,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1276,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1290,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1291,7 +1299,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/README.rst index 5e49cd9295dd..56829b326afe 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PrivateAuctionServiceTransport` is the ABC for all transports. -- public child `PrivateAuctionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PrivateAuctionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePrivateAuctionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PrivateAuctionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PrivateAuctionServiceTransport`` is the ABC for all transports. + +- public child ``PrivateAuctionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PrivateAuctionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePrivateAuctionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PrivateAuctionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/base.py index e90d84efa450..e26d9412ff0b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/rest.py index 9db728615a4c..d688a4647e2b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/private_auction_service/transports/rest.py @@ -411,6 +411,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PrivateAuctionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/client.py index b8012b83bcff..3cfb6520cae1 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/client.py @@ -110,7 +110,7 @@ class ProgrammaticBuyerServiceClient(metaclass=ProgrammaticBuyerServiceClientMet """Provides methods for handling ``ProgrammaticBuyer`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = ProgrammaticBuyerServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -997,7 +1001,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1023,8 +1027,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1033,7 +1041,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1042,7 +1050,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/README.rst index 6d8fcc76ddef..c1065578cc52 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProgrammaticBuyerServiceTransport` is the ABC for all transports. -- public child `ProgrammaticBuyerServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProgrammaticBuyerServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProgrammaticBuyerServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProgrammaticBuyerServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProgrammaticBuyerServiceTransport`` is the ABC for all transports. + +- public child ``ProgrammaticBuyerServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProgrammaticBuyerServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProgrammaticBuyerServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProgrammaticBuyerServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/base.py index 7a741064fec7..ff16de52708a 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/rest.py index a1fdd5bf449a..c90621015d31 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/programmatic_buyer_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProgrammaticBuyerServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/client.py index 6751cfb4f4ba..dea9966ebad0 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/client.py @@ -115,7 +115,7 @@ class ReportServiceClient(metaclass=ReportServiceClientMeta): """Provides methods for interacting with reports.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -450,7 +454,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = ReportServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1478,7 +1482,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1504,8 +1508,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1514,7 +1522,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1523,7 +1531,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/README.rst index 3ff494d6f149..41c61a7dc532 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReportServiceTransport` is the ABC for all transports. -- public child `ReportServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReportServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReportServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReportServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReportServiceTransport`` is the ABC for all transports. + +- public child ``ReportServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReportServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReportServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReportServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/base.py index a3329f3ba979..e88882ad5197 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/rest.py index 8ece1ffd362a..1af57f45dba6 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/report_service/transports/rest.py @@ -513,6 +513,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReportServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/client.py index dadab8476135..47f3d51dad8c 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/client.py @@ -107,7 +107,7 @@ class RoleServiceClient(metaclass=RoleServiceClientMeta): """Provides methods for handling ``Role`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = RoleServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -970,7 +974,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -996,8 +1000,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1006,7 +1014,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1015,7 +1023,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/README.rst index fce2a349752e..bf83d4c0897b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RoleServiceTransport` is the ABC for all transports. -- public child `RoleServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RoleServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRoleServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RoleServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RoleServiceTransport`` is the ABC for all transports. + +- public child ``RoleServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RoleServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRoleServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RoleServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/base.py index 9e51d0906149..8847c13dbdad 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/rest.py index bc5782b31c95..3f4189e87b09 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/role_service/transports/rest.py @@ -277,6 +277,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RoleServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/client.py index 8ae27a598bcf..b073f01823e2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/client.py @@ -109,7 +109,7 @@ class SiteServiceClient(metaclass=SiteServiceClientMeta): """Provides methods for handling ``Site`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -117,7 +117,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -127,6 +127,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -637,7 +641,7 @@ def __init__( self._universe_domain = SiteServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1690,7 +1694,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1716,8 +1720,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1726,7 +1734,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1735,7 +1743,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/README.rst index 765c3011c0b4..a1f37650399a 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SiteServiceTransport` is the ABC for all transports. -- public child `SiteServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SiteServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSiteServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SiteServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SiteServiceTransport`` is the ABC for all transports. + +- public child ``SiteServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SiteServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSiteServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SiteServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/base.py index 7689fb1da24f..edb3e4d29ec6 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/rest.py index 84af71b87da6..4354362220b2 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/site_service/transports/rest.py @@ -617,6 +617,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SiteServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/client.py index 865a53b31575..509a80d8d7eb 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/client.py @@ -111,7 +111,7 @@ class TaxonomyCategoryServiceClient(metaclass=TaxonomyCategoryServiceClientMeta) """Provides methods for handling ``TaxonomyCategory`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -650,7 +654,7 @@ def __init__( self._universe_domain = TaxonomyCategoryServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -998,7 +1002,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1024,8 +1028,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1034,7 +1042,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1043,7 +1051,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/README.rst index de1170531cd1..3c6377aea349 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TaxonomyCategoryServiceTransport` is the ABC for all transports. -- public child `TaxonomyCategoryServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TaxonomyCategoryServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTaxonomyCategoryServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TaxonomyCategoryServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TaxonomyCategoryServiceTransport`` is the ABC for all transports. + +- public child ``TaxonomyCategoryServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TaxonomyCategoryServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTaxonomyCategoryServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TaxonomyCategoryServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/base.py index 39b6e8284770..bc1bffbd3819 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/rest.py index 87bd41299405..9cd7f093ce4f 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/taxonomy_category_service/transports/rest.py @@ -294,6 +294,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TaxonomyCategoryServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/client.py index f779f2f11ddd..7ea3c762175e 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/client.py @@ -108,7 +108,7 @@ class TeamServiceClient(metaclass=TeamServiceClientMeta): """Provides methods for handling ``Team`` objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = TeamServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1674,7 +1678,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1700,8 +1704,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1710,7 +1718,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1719,7 +1727,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/README.rst index 5feeecaf4ccb..ebae90da7af9 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TeamServiceTransport` is the ABC for all transports. -- public child `TeamServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TeamServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTeamServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TeamServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TeamServiceTransport`` is the ABC for all transports. + +- public child ``TeamServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TeamServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTeamServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TeamServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/base.py index 951f10b63ec8..5325f038f0ac 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/rest.py index 26bfc31fd33f..31d1129ed72b 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/team_service/transports/rest.py @@ -615,6 +615,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TeamServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/client.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/client.py index 7876307940bb..e87a87736cfb 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/client.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/client.py @@ -106,7 +106,7 @@ class UserServiceClient(metaclass=UserServiceClientMeta): """Provides methods for handling User objects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -114,7 +114,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -124,6 +124,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = UserServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -852,7 +856,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -878,8 +882,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -888,7 +896,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -897,7 +905,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/README.rst b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/README.rst index 815387def1a4..aaf7e29f88e3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/README.rst +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserServiceTransport` is the ABC for all transports. -- public child `UserServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserServiceTransport`` is the ABC for all transports. + +- public child ``UserServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/base.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/base.py index 09a4cfde8dfc..63007c351e02 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/base.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/rest.py b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/rest.py index 1da40b44dcb6..7572a4070dd3 100644 --- a/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/rest.py +++ b/packages/google-ads-admanager/google/ads/admanager_v1/services/user_service/transports/rest.py @@ -223,6 +223,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-admanager/noxfile.py b/packages/google-ads-admanager/noxfile.py index 06ffa7e4be95..b722499c039b 100644 --- a/packages/google-ads-admanager/noxfile.py +++ b/packages/google-ads-admanager/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-ads-admanager/setup.py b/packages/google-ads-admanager/setup.py index 92f48e71b624..ace9506e296a 100644 --- a/packages/google-ads-admanager/setup.py +++ b/packages/google-ads-admanager/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-ads-admanager" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-ads-admanager/testing/constraints-3.7.txt b/packages/google-ads-admanager/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-ads-admanager/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-ads-admanager/testing/constraints-3.8.txt b/packages/google-ads-admanager/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-ads-admanager/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-ads-admanager/testing/constraints-3.9.txt b/packages/google-ads-admanager/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-ads-admanager/testing/constraints-3.9.txt +++ b/packages/google-ads-admanager/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_break_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_break_service.py index 91084d63a6a4..85840cc7e337 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_break_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_break_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AdBreakServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): assert ( AdBreakServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AdBreakServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2250,8 +2255,9 @@ def test_get_ad_break_rest_bad_request(request_type=ad_break_service.GetAdBreakR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2335,17 +2341,19 @@ def test_get_ad_break_rest_interceptors(null_interceptor): ) client = AdBreakServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_get_ad_break" - ) as post, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_get_ad_break_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "pre_get_ad_break" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "post_get_ad_break" + ) as post, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "post_get_ad_break_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "pre_get_ad_break" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2398,8 +2406,9 @@ def test_list_ad_breaks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2464,17 +2473,20 @@ def test_list_ad_breaks_rest_interceptors(null_interceptor): ) client = AdBreakServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_list_ad_breaks" - ) as post, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_list_ad_breaks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "pre_list_ad_breaks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "post_list_ad_breaks" + ) as post, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, + "post_list_ad_breaks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "pre_list_ad_breaks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2532,8 +2544,9 @@ def test_create_ad_break_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2695,17 +2708,20 @@ def test_create_ad_break_rest_interceptors(null_interceptor): ) client = AdBreakServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_create_ad_break" - ) as post, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_create_ad_break_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "pre_create_ad_break" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "post_create_ad_break" + ) as post, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, + "post_create_ad_break_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "pre_create_ad_break" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2762,8 +2778,9 @@ def test_update_ad_break_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2929,17 +2946,20 @@ def test_update_ad_break_rest_interceptors(null_interceptor): ) client = AdBreakServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_update_ad_break" - ) as post, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "post_update_ad_break_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "pre_update_ad_break" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "post_update_ad_break" + ) as post, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, + "post_update_ad_break_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "pre_update_ad_break" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2994,8 +3014,9 @@ def test_delete_ad_break_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3054,13 +3075,13 @@ def test_delete_ad_break_rest_interceptors(null_interceptor): ) client = AdBreakServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdBreakServiceRestInterceptor, "pre_delete_ad_break" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdBreakServiceRestInterceptor, "pre_delete_ad_break" + ) as pre, + ): pre.assert_not_called() pb_message = ad_break_service.DeleteAdBreakRequest.pb( ad_break_service.DeleteAdBreakRequest() @@ -3107,8 +3128,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3310,11 +3332,14 @@ def test_ad_break_service_base_transport(): def test_ad_break_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.ad_break_service.transports.AdBreakServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.ad_break_service.transports.AdBreakServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdBreakServiceTransport( @@ -3331,9 +3356,12 @@ def test_ad_break_service_base_transport_with_credentials_file(): def test_ad_break_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.ad_break_service.transports.AdBreakServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.ad_break_service.transports.AdBreakServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdBreakServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_review_center_ad_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_review_center_ad_service.py index 29c67887e2fa..385b4c9587f4 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_review_center_ad_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_review_center_ad_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AdReviewCenterAdServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): AdReviewCenterAdServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AdReviewCenterAdServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1970,8 +1975,9 @@ def test_search_ad_review_center_ads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2036,20 +2042,22 @@ def test_search_ad_review_center_ads_rest_interceptors(null_interceptor): ) client = AdReviewCenterAdServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "post_search_ad_review_center_ads", - ) as post, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "post_search_ad_review_center_ads_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "pre_search_ad_review_center_ads", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "post_search_ad_review_center_ads", + ) as post, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "post_search_ad_review_center_ads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "pre_search_ad_review_center_ads", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2111,8 +2119,9 @@ def test_batch_allow_ad_review_center_ads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2169,22 +2178,23 @@ def test_batch_allow_ad_review_center_ads_rest_interceptors(null_interceptor): ) client = AdReviewCenterAdServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "post_batch_allow_ad_review_center_ads", - ) as post, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "post_batch_allow_ad_review_center_ads_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "pre_batch_allow_ad_review_center_ads", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "post_batch_allow_ad_review_center_ads", + ) as post, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "post_batch_allow_ad_review_center_ads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "pre_batch_allow_ad_review_center_ads", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2237,8 +2247,9 @@ def test_batch_block_ad_review_center_ads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2295,22 +2306,23 @@ def test_batch_block_ad_review_center_ads_rest_interceptors(null_interceptor): ) client = AdReviewCenterAdServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "post_batch_block_ad_review_center_ads", - ) as post, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "post_batch_block_ad_review_center_ads_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdReviewCenterAdServiceRestInterceptor, - "pre_batch_block_ad_review_center_ads", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "post_batch_block_ad_review_center_ads", + ) as post, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "post_batch_block_ad_review_center_ads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdReviewCenterAdServiceRestInterceptor, + "pre_batch_block_ad_review_center_ads", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2365,8 +2377,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2554,11 +2567,14 @@ def test_ad_review_center_ad_service_base_transport(): def test_ad_review_center_ad_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.ad_review_center_ad_service.transports.AdReviewCenterAdServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.ad_review_center_ad_service.transports.AdReviewCenterAdServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdReviewCenterAdServiceTransport( @@ -2575,9 +2591,12 @@ def test_ad_review_center_ad_service_base_transport_with_credentials_file(): def test_ad_review_center_ad_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.ad_review_center_ad_service.transports.AdReviewCenterAdServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.ad_review_center_ad_service.transports.AdReviewCenterAdServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdReviewCenterAdServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_unit_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_unit_service.py index b2cfadb10b90..d1441280cedc 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_unit_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_ad_unit_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AdUnitServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): assert ( AdUnitServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AdUnitServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3304,8 +3309,9 @@ def test_get_ad_unit_rest_bad_request(request_type=ad_unit_service.GetAdUnitRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3411,17 +3417,19 @@ def test_get_ad_unit_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_get_ad_unit" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_get_ad_unit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_get_ad_unit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_get_ad_unit" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_get_ad_unit_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_get_ad_unit" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3474,8 +3482,9 @@ def test_list_ad_units_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3540,17 +3549,19 @@ def test_list_ad_units_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_list_ad_units" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_list_ad_units_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_list_ad_units" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_list_ad_units" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_list_ad_units_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_list_ad_units" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3608,8 +3619,9 @@ def test_list_ad_unit_sizes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3674,17 +3686,20 @@ def test_list_ad_unit_sizes_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_list_ad_unit_sizes" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_list_ad_unit_sizes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_list_ad_unit_sizes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_list_ad_unit_sizes" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, + "post_list_ad_unit_sizes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_list_ad_unit_sizes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3742,8 +3757,9 @@ def test_create_ad_unit_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3964,17 +3980,19 @@ def test_create_ad_unit_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_create_ad_unit" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_create_ad_unit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_create_ad_unit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_create_ad_unit" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_create_ad_unit_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_create_ad_unit" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4027,8 +4045,9 @@ def test_update_ad_unit_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4249,17 +4268,19 @@ def test_update_ad_unit_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_update_ad_unit" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_update_ad_unit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_update_ad_unit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_update_ad_unit" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_update_ad_unit_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_update_ad_unit" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4312,8 +4333,9 @@ def test_batch_create_ad_units_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4373,18 +4395,20 @@ def test_batch_create_ad_units_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_batch_create_ad_units" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, - "post_batch_create_ad_units_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_batch_create_ad_units" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_batch_create_ad_units" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, + "post_batch_create_ad_units_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_batch_create_ad_units" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4442,8 +4466,9 @@ def test_batch_update_ad_units_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4503,18 +4528,20 @@ def test_batch_update_ad_units_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_batch_update_ad_units" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, - "post_batch_update_ad_units_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_batch_update_ad_units" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_batch_update_ad_units" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, + "post_batch_update_ad_units_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_batch_update_ad_units" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4572,8 +4599,9 @@ def test_batch_activate_ad_units_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4633,18 +4661,20 @@ def test_batch_activate_ad_units_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_batch_activate_ad_units" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, - "post_batch_activate_ad_units_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_batch_activate_ad_units" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_batch_activate_ad_units" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, + "post_batch_activate_ad_units_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_batch_activate_ad_units" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4702,8 +4732,9 @@ def test_batch_deactivate_ad_units_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4763,18 +4794,20 @@ def test_batch_deactivate_ad_units_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_batch_deactivate_ad_units" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, - "post_batch_deactivate_ad_units_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_batch_deactivate_ad_units" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_batch_deactivate_ad_units" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, + "post_batch_deactivate_ad_units_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_batch_deactivate_ad_units" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4832,8 +4865,9 @@ def test_batch_archive_ad_units_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4893,18 +4927,20 @@ def test_batch_archive_ad_units_rest_interceptors(null_interceptor): ) client = AdUnitServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "post_batch_archive_ad_units" - ) as post, mock.patch.object( - transports.AdUnitServiceRestInterceptor, - "post_batch_archive_ad_units_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdUnitServiceRestInterceptor, "pre_batch_archive_ad_units" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "post_batch_archive_ad_units" + ) as post, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, + "post_batch_archive_ad_units_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdUnitServiceRestInterceptor, "pre_batch_archive_ad_units" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4964,8 +5000,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5284,11 +5321,14 @@ def test_ad_unit_service_base_transport(): def test_ad_unit_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.ad_unit_service.transports.AdUnitServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.ad_unit_service.transports.AdUnitServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdUnitServiceTransport( @@ -5305,9 +5345,12 @@ def test_ad_unit_service_base_transport_with_credentials_file(): def test_ad_unit_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.ad_unit_service.transports.AdUnitServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.ad_unit_service.transports.AdUnitServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdUnitServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_application_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_application_service.py index 1f0bf725e883..136f97148edd 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_application_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_application_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApplicationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): ApplicationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ApplicationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1707,8 +1712,9 @@ def test_get_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1773,18 +1779,20 @@ def test_get_application_rest_interceptors(null_interceptor): ) client = ApplicationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApplicationServiceRestInterceptor, "post_get_application" - ) as post, mock.patch.object( - transports.ApplicationServiceRestInterceptor, - "post_get_application_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApplicationServiceRestInterceptor, "pre_get_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApplicationServiceRestInterceptor, "post_get_application" + ) as post, + mock.patch.object( + transports.ApplicationServiceRestInterceptor, + "post_get_application_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApplicationServiceRestInterceptor, "pre_get_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1839,8 +1847,9 @@ def test_list_applications_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1905,18 +1914,20 @@ def test_list_applications_rest_interceptors(null_interceptor): ) client = ApplicationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApplicationServiceRestInterceptor, "post_list_applications" - ) as post, mock.patch.object( - transports.ApplicationServiceRestInterceptor, - "post_list_applications_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApplicationServiceRestInterceptor, "pre_list_applications" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApplicationServiceRestInterceptor, "post_list_applications" + ) as post, + mock.patch.object( + transports.ApplicationServiceRestInterceptor, + "post_list_applications_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApplicationServiceRestInterceptor, "pre_list_applications" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1976,8 +1987,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2118,11 +2130,14 @@ def test_application_service_base_transport(): def test_application_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.application_service.transports.ApplicationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.application_service.transports.ApplicationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApplicationServiceTransport( @@ -2139,9 +2154,12 @@ def test_application_service_base_transport_with_credentials_file(): def test_application_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.application_service.transports.ApplicationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.application_service.transports.ApplicationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApplicationServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_audience_segment_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_audience_segment_service.py index e3171ff07a6b..55402203bb7b 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_audience_segment_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_audience_segment_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AudienceSegmentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): AudienceSegmentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AudienceSegmentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1742,8 +1747,9 @@ def test_get_audience_segment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1808,18 +1814,21 @@ def test_get_audience_segment_rest_interceptors(null_interceptor): ) client = AudienceSegmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AudienceSegmentServiceRestInterceptor, "post_get_audience_segment" - ) as post, mock.patch.object( - transports.AudienceSegmentServiceRestInterceptor, - "post_get_audience_segment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AudienceSegmentServiceRestInterceptor, "pre_get_audience_segment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AudienceSegmentServiceRestInterceptor, + "post_get_audience_segment", + ) as post, + mock.patch.object( + transports.AudienceSegmentServiceRestInterceptor, + "post_get_audience_segment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AudienceSegmentServiceRestInterceptor, "pre_get_audience_segment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1877,8 +1886,9 @@ def test_list_audience_segments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1945,18 +1955,22 @@ def test_list_audience_segments_rest_interceptors(null_interceptor): ) client = AudienceSegmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AudienceSegmentServiceRestInterceptor, "post_list_audience_segments" - ) as post, mock.patch.object( - transports.AudienceSegmentServiceRestInterceptor, - "post_list_audience_segments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AudienceSegmentServiceRestInterceptor, "pre_list_audience_segments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AudienceSegmentServiceRestInterceptor, + "post_list_audience_segments", + ) as post, + mock.patch.object( + transports.AudienceSegmentServiceRestInterceptor, + "post_list_audience_segments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AudienceSegmentServiceRestInterceptor, + "pre_list_audience_segments", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2016,8 +2030,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2160,11 +2175,14 @@ def test_audience_segment_service_base_transport(): def test_audience_segment_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.audience_segment_service.transports.AudienceSegmentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.audience_segment_service.transports.AudienceSegmentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AudienceSegmentServiceTransport( @@ -2181,9 +2199,12 @@ def test_audience_segment_service_base_transport_with_credentials_file(): def test_audience_segment_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.audience_segment_service.transports.AudienceSegmentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.audience_segment_service.transports.AudienceSegmentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AudienceSegmentServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_bandwidth_group_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_bandwidth_group_service.py index 42fc177a7151..caf691907b3a 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_bandwidth_group_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_bandwidth_group_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BandwidthGroupServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): BandwidthGroupServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BandwidthGroupServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1738,8 +1743,9 @@ def test_get_bandwidth_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1804,18 +1810,20 @@ def test_get_bandwidth_group_rest_interceptors(null_interceptor): ) client = BandwidthGroupServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BandwidthGroupServiceRestInterceptor, "post_get_bandwidth_group" - ) as post, mock.patch.object( - transports.BandwidthGroupServiceRestInterceptor, - "post_get_bandwidth_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BandwidthGroupServiceRestInterceptor, "pre_get_bandwidth_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BandwidthGroupServiceRestInterceptor, "post_get_bandwidth_group" + ) as post, + mock.patch.object( + transports.BandwidthGroupServiceRestInterceptor, + "post_get_bandwidth_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BandwidthGroupServiceRestInterceptor, "pre_get_bandwidth_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1873,8 +1881,9 @@ def test_list_bandwidth_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1941,18 +1950,21 @@ def test_list_bandwidth_groups_rest_interceptors(null_interceptor): ) client = BandwidthGroupServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BandwidthGroupServiceRestInterceptor, "post_list_bandwidth_groups" - ) as post, mock.patch.object( - transports.BandwidthGroupServiceRestInterceptor, - "post_list_bandwidth_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BandwidthGroupServiceRestInterceptor, "pre_list_bandwidth_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BandwidthGroupServiceRestInterceptor, + "post_list_bandwidth_groups", + ) as post, + mock.patch.object( + transports.BandwidthGroupServiceRestInterceptor, + "post_list_bandwidth_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BandwidthGroupServiceRestInterceptor, "pre_list_bandwidth_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2012,8 +2024,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2156,11 +2169,14 @@ def test_bandwidth_group_service_base_transport(): def test_bandwidth_group_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.bandwidth_group_service.transports.BandwidthGroupServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.bandwidth_group_service.transports.BandwidthGroupServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BandwidthGroupServiceTransport( @@ -2177,9 +2193,12 @@ def test_bandwidth_group_service_base_transport_with_credentials_file(): def test_bandwidth_group_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.bandwidth_group_service.transports.BandwidthGroupServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.bandwidth_group_service.transports.BandwidthGroupServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BandwidthGroupServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_language_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_language_service.py index 3805e73f7fa7..8fdedbd934c4 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_language_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_language_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BrowserLanguageServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): BrowserLanguageServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BrowserLanguageServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1742,8 +1747,9 @@ def test_get_browser_language_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1808,18 +1814,21 @@ def test_get_browser_language_rest_interceptors(null_interceptor): ) client = BrowserLanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BrowserLanguageServiceRestInterceptor, "post_get_browser_language" - ) as post, mock.patch.object( - transports.BrowserLanguageServiceRestInterceptor, - "post_get_browser_language_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BrowserLanguageServiceRestInterceptor, "pre_get_browser_language" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BrowserLanguageServiceRestInterceptor, + "post_get_browser_language", + ) as post, + mock.patch.object( + transports.BrowserLanguageServiceRestInterceptor, + "post_get_browser_language_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BrowserLanguageServiceRestInterceptor, "pre_get_browser_language" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1877,8 +1886,9 @@ def test_list_browser_languages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1945,18 +1955,22 @@ def test_list_browser_languages_rest_interceptors(null_interceptor): ) client = BrowserLanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BrowserLanguageServiceRestInterceptor, "post_list_browser_languages" - ) as post, mock.patch.object( - transports.BrowserLanguageServiceRestInterceptor, - "post_list_browser_languages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BrowserLanguageServiceRestInterceptor, "pre_list_browser_languages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BrowserLanguageServiceRestInterceptor, + "post_list_browser_languages", + ) as post, + mock.patch.object( + transports.BrowserLanguageServiceRestInterceptor, + "post_list_browser_languages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BrowserLanguageServiceRestInterceptor, + "pre_list_browser_languages", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2016,8 +2030,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2160,11 +2175,14 @@ def test_browser_language_service_base_transport(): def test_browser_language_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.browser_language_service.transports.BrowserLanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.browser_language_service.transports.BrowserLanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BrowserLanguageServiceTransport( @@ -2181,9 +2199,12 @@ def test_browser_language_service_base_transport_with_credentials_file(): def test_browser_language_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.browser_language_service.transports.BrowserLanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.browser_language_service.transports.BrowserLanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BrowserLanguageServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_service.py index 53105e2291b2..2f82f64ebfbd 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_browser_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BrowserServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( BrowserServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BrowserServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1671,8 +1676,9 @@ def test_get_browser_rest_bad_request(request_type=browser_service.GetBrowserReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1741,17 +1747,19 @@ def test_get_browser_rest_interceptors(null_interceptor): ) client = BrowserServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BrowserServiceRestInterceptor, "post_get_browser" - ) as post, mock.patch.object( - transports.BrowserServiceRestInterceptor, "post_get_browser_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BrowserServiceRestInterceptor, "pre_get_browser" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BrowserServiceRestInterceptor, "post_get_browser" + ) as post, + mock.patch.object( + transports.BrowserServiceRestInterceptor, "post_get_browser_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BrowserServiceRestInterceptor, "pre_get_browser" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1804,8 +1812,9 @@ def test_list_browsers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1870,17 +1879,19 @@ def test_list_browsers_rest_interceptors(null_interceptor): ) client = BrowserServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BrowserServiceRestInterceptor, "post_list_browsers" - ) as post, mock.patch.object( - transports.BrowserServiceRestInterceptor, "post_list_browsers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BrowserServiceRestInterceptor, "pre_list_browsers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BrowserServiceRestInterceptor, "post_list_browsers" + ) as post, + mock.patch.object( + transports.BrowserServiceRestInterceptor, "post_list_browsers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BrowserServiceRestInterceptor, "pre_list_browsers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1940,8 +1951,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2080,11 +2092,14 @@ def test_browser_service_base_transport(): def test_browser_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.browser_service.transports.BrowserServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.browser_service.transports.BrowserServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BrowserServiceTransport( @@ -2101,9 +2116,12 @@ def test_browser_service_base_transport_with_credentials_file(): def test_browser_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.browser_service.transports.BrowserServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.browser_service.transports.BrowserServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BrowserServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_key_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_key_service.py index b6e1138f5ed8..59b0712cd23f 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_key_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_key_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CmsMetadataKeyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): CmsMetadataKeyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CmsMetadataKeyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1741,8 +1746,9 @@ def test_get_cms_metadata_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1812,18 +1818,20 @@ def test_get_cms_metadata_key_rest_interceptors(null_interceptor): ) client = CmsMetadataKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmsMetadataKeyServiceRestInterceptor, "post_get_cms_metadata_key" - ) as post, mock.patch.object( - transports.CmsMetadataKeyServiceRestInterceptor, - "post_get_cms_metadata_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmsMetadataKeyServiceRestInterceptor, "pre_get_cms_metadata_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmsMetadataKeyServiceRestInterceptor, "post_get_cms_metadata_key" + ) as post, + mock.patch.object( + transports.CmsMetadataKeyServiceRestInterceptor, + "post_get_cms_metadata_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmsMetadataKeyServiceRestInterceptor, "pre_get_cms_metadata_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1881,8 +1889,9 @@ def test_list_cms_metadata_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1949,18 +1958,22 @@ def test_list_cms_metadata_keys_rest_interceptors(null_interceptor): ) client = CmsMetadataKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmsMetadataKeyServiceRestInterceptor, "post_list_cms_metadata_keys" - ) as post, mock.patch.object( - transports.CmsMetadataKeyServiceRestInterceptor, - "post_list_cms_metadata_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmsMetadataKeyServiceRestInterceptor, "pre_list_cms_metadata_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmsMetadataKeyServiceRestInterceptor, + "post_list_cms_metadata_keys", + ) as post, + mock.patch.object( + transports.CmsMetadataKeyServiceRestInterceptor, + "post_list_cms_metadata_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmsMetadataKeyServiceRestInterceptor, + "pre_list_cms_metadata_keys", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2020,8 +2033,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2164,11 +2178,14 @@ def test_cms_metadata_key_service_base_transport(): def test_cms_metadata_key_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.cms_metadata_key_service.transports.CmsMetadataKeyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.cms_metadata_key_service.transports.CmsMetadataKeyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmsMetadataKeyServiceTransport( @@ -2185,9 +2202,12 @@ def test_cms_metadata_key_service_base_transport_with_credentials_file(): def test_cms_metadata_key_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.cms_metadata_key_service.transports.CmsMetadataKeyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.cms_metadata_key_service.transports.CmsMetadataKeyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmsMetadataKeyServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_value_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_value_service.py index 64cc1def0766..445ed64f7e1b 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_value_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_cms_metadata_value_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CmsMetadataValueServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): CmsMetadataValueServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CmsMetadataValueServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1744,8 +1749,9 @@ def test_get_cms_metadata_value_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1817,18 +1823,22 @@ def test_get_cms_metadata_value_rest_interceptors(null_interceptor): ) client = CmsMetadataValueServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmsMetadataValueServiceRestInterceptor, "post_get_cms_metadata_value" - ) as post, mock.patch.object( - transports.CmsMetadataValueServiceRestInterceptor, - "post_get_cms_metadata_value_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmsMetadataValueServiceRestInterceptor, "pre_get_cms_metadata_value" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmsMetadataValueServiceRestInterceptor, + "post_get_cms_metadata_value", + ) as post, + mock.patch.object( + transports.CmsMetadataValueServiceRestInterceptor, + "post_get_cms_metadata_value_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmsMetadataValueServiceRestInterceptor, + "pre_get_cms_metadata_value", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1886,8 +1896,9 @@ def test_list_cms_metadata_values_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1954,20 +1965,22 @@ def test_list_cms_metadata_values_rest_interceptors(null_interceptor): ) client = CmsMetadataValueServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmsMetadataValueServiceRestInterceptor, - "post_list_cms_metadata_values", - ) as post, mock.patch.object( - transports.CmsMetadataValueServiceRestInterceptor, - "post_list_cms_metadata_values_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmsMetadataValueServiceRestInterceptor, - "pre_list_cms_metadata_values", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmsMetadataValueServiceRestInterceptor, + "post_list_cms_metadata_values", + ) as post, + mock.patch.object( + transports.CmsMetadataValueServiceRestInterceptor, + "post_list_cms_metadata_values_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmsMetadataValueServiceRestInterceptor, + "pre_list_cms_metadata_values", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2027,8 +2040,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2171,11 +2185,14 @@ def test_cms_metadata_value_service_base_transport(): def test_cms_metadata_value_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.cms_metadata_value_service.transports.CmsMetadataValueServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.cms_metadata_value_service.transports.CmsMetadataValueServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmsMetadataValueServiceTransport( @@ -2192,9 +2209,12 @@ def test_cms_metadata_value_service_base_transport_with_credentials_file(): def test_cms_metadata_value_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.cms_metadata_value_service.transports.CmsMetadataValueServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.cms_metadata_value_service.transports.CmsMetadataValueServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmsMetadataValueServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_company_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_company_service.py index 5b2676b93554..3e6356453549 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_company_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_company_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CompanyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): assert ( CompanyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CompanyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1677,8 +1682,9 @@ def test_get_company_rest_bad_request(request_type=company_service.GetCompanyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1770,17 +1776,19 @@ def test_get_company_rest_interceptors(null_interceptor): ) client = CompanyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CompanyServiceRestInterceptor, "post_get_company" - ) as post, mock.patch.object( - transports.CompanyServiceRestInterceptor, "post_get_company_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CompanyServiceRestInterceptor, "pre_get_company" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CompanyServiceRestInterceptor, "post_get_company" + ) as post, + mock.patch.object( + transports.CompanyServiceRestInterceptor, "post_get_company_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CompanyServiceRestInterceptor, "pre_get_company" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1833,8 +1841,9 @@ def test_list_companies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1899,17 +1908,20 @@ def test_list_companies_rest_interceptors(null_interceptor): ) client = CompanyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CompanyServiceRestInterceptor, "post_list_companies" - ) as post, mock.patch.object( - transports.CompanyServiceRestInterceptor, "post_list_companies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CompanyServiceRestInterceptor, "pre_list_companies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CompanyServiceRestInterceptor, "post_list_companies" + ) as post, + mock.patch.object( + transports.CompanyServiceRestInterceptor, + "post_list_companies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompanyServiceRestInterceptor, "pre_list_companies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1969,8 +1981,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2109,11 +2122,14 @@ def test_company_service_base_transport(): def test_company_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.company_service.transports.CompanyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.company_service.transports.CompanyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompanyServiceTransport( @@ -2130,9 +2146,12 @@ def test_company_service_base_transport_with_credentials_file(): def test_company_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.company_service.transports.CompanyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.company_service.transports.CompanyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompanyServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_contact_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_contact_service.py index 554d8b8b36de..1349ab883a97 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_contact_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_contact_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContactServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ContactServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContactServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2442,8 +2447,9 @@ def test_get_contact_rest_bad_request(request_type=contact_service.GetContactReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2528,17 +2534,19 @@ def test_get_contact_rest_interceptors(null_interceptor): ) client = ContactServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_get_contact" - ) as post, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_get_contact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactServiceRestInterceptor, "pre_get_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_get_contact" + ) as post, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_get_contact_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContactServiceRestInterceptor, "pre_get_contact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2591,8 +2599,9 @@ def test_list_contacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2657,17 +2666,19 @@ def test_list_contacts_rest_interceptors(null_interceptor): ) client = ContactServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_list_contacts" - ) as post, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_list_contacts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactServiceRestInterceptor, "pre_list_contacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_list_contacts" + ) as post, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_list_contacts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContactServiceRestInterceptor, "pre_list_contacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2725,8 +2736,9 @@ def test_create_contact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2891,17 +2903,20 @@ def test_create_contact_rest_interceptors(null_interceptor): ) client = ContactServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_create_contact" - ) as post, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_create_contact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactServiceRestInterceptor, "pre_create_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_create_contact" + ) as post, + mock.patch.object( + transports.ContactServiceRestInterceptor, + "post_create_contact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactServiceRestInterceptor, "pre_create_contact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2954,8 +2969,9 @@ def test_batch_create_contacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3015,18 +3031,20 @@ def test_batch_create_contacts_rest_interceptors(null_interceptor): ) client = ContactServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_batch_create_contacts" - ) as post, mock.patch.object( - transports.ContactServiceRestInterceptor, - "post_batch_create_contacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactServiceRestInterceptor, "pre_batch_create_contacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_batch_create_contacts" + ) as post, + mock.patch.object( + transports.ContactServiceRestInterceptor, + "post_batch_create_contacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactServiceRestInterceptor, "pre_batch_create_contacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3084,8 +3102,9 @@ def test_update_contact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3250,17 +3269,20 @@ def test_update_contact_rest_interceptors(null_interceptor): ) client = ContactServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_update_contact" - ) as post, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_update_contact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactServiceRestInterceptor, "pre_update_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_update_contact" + ) as post, + mock.patch.object( + transports.ContactServiceRestInterceptor, + "post_update_contact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactServiceRestInterceptor, "pre_update_contact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3313,8 +3335,9 @@ def test_batch_update_contacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3374,18 +3397,20 @@ def test_batch_update_contacts_rest_interceptors(null_interceptor): ) client = ContactServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactServiceRestInterceptor, "post_batch_update_contacts" - ) as post, mock.patch.object( - transports.ContactServiceRestInterceptor, - "post_batch_update_contacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactServiceRestInterceptor, "pre_batch_update_contacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactServiceRestInterceptor, "post_batch_update_contacts" + ) as post, + mock.patch.object( + transports.ContactServiceRestInterceptor, + "post_batch_update_contacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactServiceRestInterceptor, "pre_batch_update_contacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3445,8 +3470,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3673,11 +3699,14 @@ def test_contact_service_base_transport(): def test_contact_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.contact_service.transports.ContactServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.contact_service.transports.ContactServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContactServiceTransport( @@ -3694,9 +3723,12 @@ def test_contact_service_base_transport_with_credentials_file(): def test_contact_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.contact_service.transports.ContactServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.contact_service.transports.ContactServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContactServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_bundle_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_bundle_service.py index 79298d4ac2d7..d0f3de235387 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_bundle_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_bundle_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContentBundleServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): ContentBundleServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContentBundleServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1733,8 +1738,9 @@ def test_get_content_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1799,18 +1805,20 @@ def test_get_content_bundle_rest_interceptors(null_interceptor): ) client = ContentBundleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentBundleServiceRestInterceptor, "post_get_content_bundle" - ) as post, mock.patch.object( - transports.ContentBundleServiceRestInterceptor, - "post_get_content_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContentBundleServiceRestInterceptor, "pre_get_content_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentBundleServiceRestInterceptor, "post_get_content_bundle" + ) as post, + mock.patch.object( + transports.ContentBundleServiceRestInterceptor, + "post_get_content_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentBundleServiceRestInterceptor, "pre_get_content_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1868,8 +1876,9 @@ def test_list_content_bundles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1936,18 +1945,20 @@ def test_list_content_bundles_rest_interceptors(null_interceptor): ) client = ContentBundleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentBundleServiceRestInterceptor, "post_list_content_bundles" - ) as post, mock.patch.object( - transports.ContentBundleServiceRestInterceptor, - "post_list_content_bundles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContentBundleServiceRestInterceptor, "pre_list_content_bundles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentBundleServiceRestInterceptor, "post_list_content_bundles" + ) as post, + mock.patch.object( + transports.ContentBundleServiceRestInterceptor, + "post_list_content_bundles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentBundleServiceRestInterceptor, "pre_list_content_bundles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2007,8 +2018,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2151,11 +2163,14 @@ def test_content_bundle_service_base_transport(): def test_content_bundle_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.content_bundle_service.transports.ContentBundleServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.content_bundle_service.transports.ContentBundleServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentBundleServiceTransport( @@ -2172,9 +2187,12 @@ def test_content_bundle_service_base_transport_with_credentials_file(): def test_content_bundle_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.content_bundle_service.transports.ContentBundleServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.content_bundle_service.transports.ContentBundleServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentBundleServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_label_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_label_service.py index 65689140ca09..ff647c510401 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_label_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_label_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContentLabelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): ContentLabelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContentLabelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1723,8 +1728,9 @@ def test_get_content_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1789,18 +1795,20 @@ def test_get_content_label_rest_interceptors(null_interceptor): ) client = ContentLabelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentLabelServiceRestInterceptor, "post_get_content_label" - ) as post, mock.patch.object( - transports.ContentLabelServiceRestInterceptor, - "post_get_content_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContentLabelServiceRestInterceptor, "pre_get_content_label" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentLabelServiceRestInterceptor, "post_get_content_label" + ) as post, + mock.patch.object( + transports.ContentLabelServiceRestInterceptor, + "post_get_content_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentLabelServiceRestInterceptor, "pre_get_content_label" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1858,8 +1866,9 @@ def test_list_content_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1924,18 +1933,20 @@ def test_list_content_labels_rest_interceptors(null_interceptor): ) client = ContentLabelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentLabelServiceRestInterceptor, "post_list_content_labels" - ) as post, mock.patch.object( - transports.ContentLabelServiceRestInterceptor, - "post_list_content_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContentLabelServiceRestInterceptor, "pre_list_content_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentLabelServiceRestInterceptor, "post_list_content_labels" + ) as post, + mock.patch.object( + transports.ContentLabelServiceRestInterceptor, + "post_list_content_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentLabelServiceRestInterceptor, "pre_list_content_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1995,8 +2006,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2139,11 +2151,14 @@ def test_content_label_service_base_transport(): def test_content_label_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.content_label_service.transports.ContentLabelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.content_label_service.transports.ContentLabelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentLabelServiceTransport( @@ -2160,9 +2175,12 @@ def test_content_label_service_base_transport_with_credentials_file(): def test_content_label_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.content_label_service.transports.ContentLabelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.content_label_service.transports.ContentLabelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentLabelServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_service.py index 5ed2f33d4935..1e070cfda521 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_content_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( ContentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1671,8 +1676,9 @@ def test_get_content_rest_bad_request(request_type=content_service.GetContentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1737,17 +1743,19 @@ def test_get_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_get_content" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_get_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_get_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_get_content" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_get_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_get_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1798,8 +1806,9 @@ def test_list_content_rest_bad_request(request_type=content_service.ListContentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1864,17 +1873,19 @@ def test_list_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_list_content" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_list_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_list_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_list_content" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_list_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_list_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1934,8 +1945,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2074,11 +2086,14 @@ def test_content_service_base_transport(): def test_content_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentServiceTransport( @@ -2095,9 +2110,12 @@ def test_content_service_base_transport_with_credentials_file(): def test_content_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_creative_template_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_creative_template_service.py index c051652ff3df..4ff67cde4cd3 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_creative_template_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_creative_template_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CreativeTemplateServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): CreativeTemplateServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CreativeTemplateServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1744,8 +1749,9 @@ def test_get_creative_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1832,18 +1838,22 @@ def test_get_creative_template_rest_interceptors(null_interceptor): ) client = CreativeTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CreativeTemplateServiceRestInterceptor, "post_get_creative_template" - ) as post, mock.patch.object( - transports.CreativeTemplateServiceRestInterceptor, - "post_get_creative_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CreativeTemplateServiceRestInterceptor, "pre_get_creative_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CreativeTemplateServiceRestInterceptor, + "post_get_creative_template", + ) as post, + mock.patch.object( + transports.CreativeTemplateServiceRestInterceptor, + "post_get_creative_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CreativeTemplateServiceRestInterceptor, + "pre_get_creative_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1901,8 +1911,9 @@ def test_list_creative_templates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1969,19 +1980,22 @@ def test_list_creative_templates_rest_interceptors(null_interceptor): ) client = CreativeTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CreativeTemplateServiceRestInterceptor, - "post_list_creative_templates", - ) as post, mock.patch.object( - transports.CreativeTemplateServiceRestInterceptor, - "post_list_creative_templates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CreativeTemplateServiceRestInterceptor, "pre_list_creative_templates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CreativeTemplateServiceRestInterceptor, + "post_list_creative_templates", + ) as post, + mock.patch.object( + transports.CreativeTemplateServiceRestInterceptor, + "post_list_creative_templates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CreativeTemplateServiceRestInterceptor, + "pre_list_creative_templates", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2041,8 +2055,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2185,11 +2200,14 @@ def test_creative_template_service_base_transport(): def test_creative_template_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.creative_template_service.transports.CreativeTemplateServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.creative_template_service.transports.CreativeTemplateServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CreativeTemplateServiceTransport( @@ -2206,9 +2224,12 @@ def test_creative_template_service_base_transport_with_credentials_file(): def test_creative_template_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.creative_template_service.transports.CreativeTemplateServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.creative_template_service.transports.CreativeTemplateServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CreativeTemplateServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_field_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_field_service.py index 985ded08a1d8..9023e488efeb 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_field_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_field_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CustomFieldServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): CustomFieldServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CustomFieldServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2915,8 +2920,9 @@ def test_get_custom_field_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3005,18 +3011,20 @@ def test_get_custom_field_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "post_get_custom_field" - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_get_custom_field_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_get_custom_field" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "post_get_custom_field" + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_get_custom_field_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "pre_get_custom_field" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3071,8 +3079,9 @@ def test_list_custom_fields_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3137,18 +3146,20 @@ def test_list_custom_fields_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "post_list_custom_fields" - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_list_custom_fields_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_list_custom_fields" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "post_list_custom_fields" + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_list_custom_fields_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "pre_list_custom_fields" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3206,8 +3217,9 @@ def test_create_custom_field_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3378,18 +3390,20 @@ def test_create_custom_field_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "post_create_custom_field" - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_create_custom_field_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_create_custom_field" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "post_create_custom_field" + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_create_custom_field_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "pre_create_custom_field" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3444,8 +3458,9 @@ def test_batch_create_custom_fields_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3507,18 +3522,22 @@ def test_batch_create_custom_fields_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "post_batch_create_custom_fields" - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_batch_create_custom_fields_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_batch_create_custom_fields" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_create_custom_fields", + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_create_custom_fields_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "pre_batch_create_custom_fields", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3576,8 +3595,9 @@ def test_update_custom_field_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3748,18 +3768,20 @@ def test_update_custom_field_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "post_update_custom_field" - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_update_custom_field_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_update_custom_field" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "post_update_custom_field" + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_update_custom_field_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, "pre_update_custom_field" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3814,8 +3836,9 @@ def test_batch_update_custom_fields_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3877,18 +3900,22 @@ def test_batch_update_custom_fields_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "post_batch_update_custom_fields" - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_batch_update_custom_fields_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_batch_update_custom_fields" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_update_custom_fields", + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_update_custom_fields_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "pre_batch_update_custom_fields", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3946,8 +3973,9 @@ def test_batch_activate_custom_fields_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4009,19 +4037,22 @@ def test_batch_activate_custom_fields_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_batch_activate_custom_fields", - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_batch_activate_custom_fields_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, "pre_batch_activate_custom_fields" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_activate_custom_fields", + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_activate_custom_fields_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "pre_batch_activate_custom_fields", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4079,8 +4110,9 @@ def test_batch_deactivate_custom_fields_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4144,20 +4176,22 @@ def test_batch_deactivate_custom_fields_rest_interceptors(null_interceptor): ) client = CustomFieldServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_batch_deactivate_custom_fields", - ) as post, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "post_batch_deactivate_custom_fields_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomFieldServiceRestInterceptor, - "pre_batch_deactivate_custom_fields", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_deactivate_custom_fields", + ) as post, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "post_batch_deactivate_custom_fields_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomFieldServiceRestInterceptor, + "pre_batch_deactivate_custom_fields", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4217,8 +4251,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4497,11 +4532,14 @@ def test_custom_field_service_base_transport(): def test_custom_field_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.custom_field_service.transports.CustomFieldServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.custom_field_service.transports.CustomFieldServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CustomFieldServiceTransport( @@ -4518,9 +4556,12 @@ def test_custom_field_service_base_transport_with_credentials_file(): def test_custom_field_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.custom_field_service.transports.CustomFieldServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.custom_field_service.transports.CustomFieldServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CustomFieldServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_key_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_key_service.py index 74f534ec9340..d1fbfd6e7bda 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_key_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_key_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CustomTargetingKeyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): CustomTargetingKeyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CustomTargetingKeyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3025,8 +3030,9 @@ def test_get_custom_targeting_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3110,20 +3116,22 @@ def test_get_custom_targeting_key_rest_interceptors(null_interceptor): ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_get_custom_targeting_key", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_get_custom_targeting_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_get_custom_targeting_key", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_get_custom_targeting_key", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_get_custom_targeting_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_get_custom_targeting_key", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3181,8 +3189,9 @@ def test_list_custom_targeting_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3249,20 +3258,22 @@ def test_list_custom_targeting_keys_rest_interceptors(null_interceptor): ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_list_custom_targeting_keys", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_list_custom_targeting_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_list_custom_targeting_keys", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_list_custom_targeting_keys", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_list_custom_targeting_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_list_custom_targeting_keys", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3324,8 +3335,9 @@ def test_create_custom_targeting_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3491,20 +3503,22 @@ def test_create_custom_targeting_key_rest_interceptors(null_interceptor): ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_create_custom_targeting_key", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_create_custom_targeting_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_create_custom_targeting_key", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_create_custom_targeting_key", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_create_custom_targeting_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_create_custom_targeting_key", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3562,8 +3576,9 @@ def test_batch_create_custom_targeting_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3631,20 +3646,22 @@ def test_batch_create_custom_targeting_keys_rest_interceptors(null_interceptor): ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_create_custom_targeting_keys", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_create_custom_targeting_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_batch_create_custom_targeting_keys", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_create_custom_targeting_keys", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_create_custom_targeting_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_batch_create_custom_targeting_keys", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3710,8 +3727,9 @@ def test_update_custom_targeting_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3879,20 +3897,22 @@ def test_update_custom_targeting_key_rest_interceptors(null_interceptor): ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_update_custom_targeting_key", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_update_custom_targeting_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_update_custom_targeting_key", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_update_custom_targeting_key", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_update_custom_targeting_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_update_custom_targeting_key", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3950,8 +3970,9 @@ def test_batch_update_custom_targeting_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4019,20 +4040,22 @@ def test_batch_update_custom_targeting_keys_rest_interceptors(null_interceptor): ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_update_custom_targeting_keys", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_update_custom_targeting_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_batch_update_custom_targeting_keys", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_update_custom_targeting_keys", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_update_custom_targeting_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_batch_update_custom_targeting_keys", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4096,8 +4119,9 @@ def test_batch_activate_custom_targeting_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4165,20 +4189,22 @@ def test_batch_activate_custom_targeting_keys_rest_interceptors(null_interceptor ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_activate_custom_targeting_keys", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_activate_custom_targeting_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_batch_activate_custom_targeting_keys", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_activate_custom_targeting_keys", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_activate_custom_targeting_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_batch_activate_custom_targeting_keys", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4240,8 +4266,9 @@ def test_batch_deactivate_custom_targeting_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4310,20 +4337,22 @@ def test_batch_deactivate_custom_targeting_keys_rest_interceptors(null_intercept ) client = CustomTargetingKeyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_deactivate_custom_targeting_keys", - ) as post, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "post_batch_deactivate_custom_targeting_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingKeyServiceRestInterceptor, - "pre_batch_deactivate_custom_targeting_keys", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_deactivate_custom_targeting_keys", + ) as post, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "post_batch_deactivate_custom_targeting_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingKeyServiceRestInterceptor, + "pre_batch_deactivate_custom_targeting_keys", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4389,8 +4418,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4679,11 +4709,14 @@ def test_custom_targeting_key_service_base_transport(): def test_custom_targeting_key_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.custom_targeting_key_service.transports.CustomTargetingKeyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.custom_targeting_key_service.transports.CustomTargetingKeyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CustomTargetingKeyServiceTransport( @@ -4700,9 +4733,12 @@ def test_custom_targeting_key_service_base_transport_with_credentials_file(): def test_custom_targeting_key_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.custom_targeting_key_service.transports.CustomTargetingKeyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.custom_targeting_key_service.transports.CustomTargetingKeyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CustomTargetingKeyServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_value_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_value_service.py index c19310f0e198..8c4d0bad10c2 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_value_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_custom_targeting_value_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CustomTargetingValueServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): CustomTargetingValueServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CustomTargetingValueServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1790,8 +1795,9 @@ def test_get_custom_targeting_value_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1872,20 +1878,22 @@ def test_get_custom_targeting_value_rest_interceptors(null_interceptor): ) client = CustomTargetingValueServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingValueServiceRestInterceptor, - "post_get_custom_targeting_value", - ) as post, mock.patch.object( - transports.CustomTargetingValueServiceRestInterceptor, - "post_get_custom_targeting_value_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingValueServiceRestInterceptor, - "pre_get_custom_targeting_value", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingValueServiceRestInterceptor, + "post_get_custom_targeting_value", + ) as post, + mock.patch.object( + transports.CustomTargetingValueServiceRestInterceptor, + "post_get_custom_targeting_value_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingValueServiceRestInterceptor, + "pre_get_custom_targeting_value", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1943,8 +1951,9 @@ def test_list_custom_targeting_values_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2013,20 +2022,22 @@ def test_list_custom_targeting_values_rest_interceptors(null_interceptor): ) client = CustomTargetingValueServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CustomTargetingValueServiceRestInterceptor, - "post_list_custom_targeting_values", - ) as post, mock.patch.object( - transports.CustomTargetingValueServiceRestInterceptor, - "post_list_custom_targeting_values_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CustomTargetingValueServiceRestInterceptor, - "pre_list_custom_targeting_values", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CustomTargetingValueServiceRestInterceptor, + "post_list_custom_targeting_values", + ) as post, + mock.patch.object( + transports.CustomTargetingValueServiceRestInterceptor, + "post_list_custom_targeting_values_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CustomTargetingValueServiceRestInterceptor, + "pre_list_custom_targeting_values", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2090,8 +2101,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2234,11 +2246,14 @@ def test_custom_targeting_value_service_base_transport(): def test_custom_targeting_value_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.custom_targeting_value_service.transports.CustomTargetingValueServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.custom_targeting_value_service.transports.CustomTargetingValueServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CustomTargetingValueServiceTransport( @@ -2255,9 +2270,12 @@ def test_custom_targeting_value_service_base_transport_with_credentials_file(): def test_custom_targeting_value_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.custom_targeting_value_service.transports.CustomTargetingValueServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.custom_targeting_value_service.transports.CustomTargetingValueServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CustomTargetingValueServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_capability_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_capability_service.py index 4225aaaefe54..df1d1abcd2d8 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_capability_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_capability_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeviceCapabilityServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): DeviceCapabilityServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DeviceCapabilityServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1743,8 +1748,9 @@ def test_get_device_capability_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1809,18 +1815,22 @@ def test_get_device_capability_rest_interceptors(null_interceptor): ) client = DeviceCapabilityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeviceCapabilityServiceRestInterceptor, "post_get_device_capability" - ) as post, mock.patch.object( - transports.DeviceCapabilityServiceRestInterceptor, - "post_get_device_capability_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeviceCapabilityServiceRestInterceptor, "pre_get_device_capability" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeviceCapabilityServiceRestInterceptor, + "post_get_device_capability", + ) as post, + mock.patch.object( + transports.DeviceCapabilityServiceRestInterceptor, + "post_get_device_capability_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeviceCapabilityServiceRestInterceptor, + "pre_get_device_capability", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1878,8 +1888,9 @@ def test_list_device_capabilities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1946,20 +1957,22 @@ def test_list_device_capabilities_rest_interceptors(null_interceptor): ) client = DeviceCapabilityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeviceCapabilityServiceRestInterceptor, - "post_list_device_capabilities", - ) as post, mock.patch.object( - transports.DeviceCapabilityServiceRestInterceptor, - "post_list_device_capabilities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeviceCapabilityServiceRestInterceptor, - "pre_list_device_capabilities", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeviceCapabilityServiceRestInterceptor, + "post_list_device_capabilities", + ) as post, + mock.patch.object( + transports.DeviceCapabilityServiceRestInterceptor, + "post_list_device_capabilities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeviceCapabilityServiceRestInterceptor, + "pre_list_device_capabilities", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2019,8 +2032,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2163,11 +2177,14 @@ def test_device_capability_service_base_transport(): def test_device_capability_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.device_capability_service.transports.DeviceCapabilityServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.device_capability_service.transports.DeviceCapabilityServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeviceCapabilityServiceTransport( @@ -2184,9 +2201,12 @@ def test_device_capability_service_base_transport_with_credentials_file(): def test_device_capability_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.device_capability_service.transports.DeviceCapabilityServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.device_capability_service.transports.DeviceCapabilityServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeviceCapabilityServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_category_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_category_service.py index 6803da523acc..85e949013f91 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_category_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_category_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeviceCategoryServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): DeviceCategoryServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DeviceCategoryServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1738,8 +1743,9 @@ def test_get_device_category_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1804,18 +1810,20 @@ def test_get_device_category_rest_interceptors(null_interceptor): ) client = DeviceCategoryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeviceCategoryServiceRestInterceptor, "post_get_device_category" - ) as post, mock.patch.object( - transports.DeviceCategoryServiceRestInterceptor, - "post_get_device_category_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeviceCategoryServiceRestInterceptor, "pre_get_device_category" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeviceCategoryServiceRestInterceptor, "post_get_device_category" + ) as post, + mock.patch.object( + transports.DeviceCategoryServiceRestInterceptor, + "post_get_device_category_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeviceCategoryServiceRestInterceptor, "pre_get_device_category" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1873,8 +1881,9 @@ def test_list_device_categories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1941,18 +1950,22 @@ def test_list_device_categories_rest_interceptors(null_interceptor): ) client = DeviceCategoryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeviceCategoryServiceRestInterceptor, "post_list_device_categories" - ) as post, mock.patch.object( - transports.DeviceCategoryServiceRestInterceptor, - "post_list_device_categories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeviceCategoryServiceRestInterceptor, "pre_list_device_categories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeviceCategoryServiceRestInterceptor, + "post_list_device_categories", + ) as post, + mock.patch.object( + transports.DeviceCategoryServiceRestInterceptor, + "post_list_device_categories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeviceCategoryServiceRestInterceptor, + "pre_list_device_categories", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2012,8 +2025,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2156,11 +2170,14 @@ def test_device_category_service_base_transport(): def test_device_category_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.device_category_service.transports.DeviceCategoryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.device_category_service.transports.DeviceCategoryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeviceCategoryServiceTransport( @@ -2177,9 +2194,12 @@ def test_device_category_service_base_transport_with_credentials_file(): def test_device_category_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.device_category_service.transports.DeviceCategoryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.device_category_service.transports.DeviceCategoryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeviceCategoryServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_manufacturer_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_manufacturer_service.py index bf0336c64bb3..6f8d6c4a3309 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_manufacturer_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_device_manufacturer_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeviceManufacturerServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): DeviceManufacturerServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DeviceManufacturerServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1759,8 +1764,9 @@ def test_get_device_manufacturer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1825,20 +1831,22 @@ def test_get_device_manufacturer_rest_interceptors(null_interceptor): ) client = DeviceManufacturerServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeviceManufacturerServiceRestInterceptor, - "post_get_device_manufacturer", - ) as post, mock.patch.object( - transports.DeviceManufacturerServiceRestInterceptor, - "post_get_device_manufacturer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeviceManufacturerServiceRestInterceptor, - "pre_get_device_manufacturer", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeviceManufacturerServiceRestInterceptor, + "post_get_device_manufacturer", + ) as post, + mock.patch.object( + transports.DeviceManufacturerServiceRestInterceptor, + "post_get_device_manufacturer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeviceManufacturerServiceRestInterceptor, + "pre_get_device_manufacturer", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1896,8 +1904,9 @@ def test_list_device_manufacturers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1964,20 +1973,22 @@ def test_list_device_manufacturers_rest_interceptors(null_interceptor): ) client = DeviceManufacturerServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeviceManufacturerServiceRestInterceptor, - "post_list_device_manufacturers", - ) as post, mock.patch.object( - transports.DeviceManufacturerServiceRestInterceptor, - "post_list_device_manufacturers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeviceManufacturerServiceRestInterceptor, - "pre_list_device_manufacturers", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeviceManufacturerServiceRestInterceptor, + "post_list_device_manufacturers", + ) as post, + mock.patch.object( + transports.DeviceManufacturerServiceRestInterceptor, + "post_list_device_manufacturers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeviceManufacturerServiceRestInterceptor, + "pre_list_device_manufacturers", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2041,8 +2052,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2185,11 +2197,14 @@ def test_device_manufacturer_service_base_transport(): def test_device_manufacturer_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.device_manufacturer_service.transports.DeviceManufacturerServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.device_manufacturer_service.transports.DeviceManufacturerServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeviceManufacturerServiceTransport( @@ -2206,9 +2221,12 @@ def test_device_manufacturer_service_base_transport_with_credentials_file(): def test_device_manufacturer_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.device_manufacturer_service.transports.DeviceManufacturerServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.device_manufacturer_service.transports.DeviceManufacturerServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeviceManufacturerServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_entity_signals_mapping_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_entity_signals_mapping_service.py index 78beef296006..76d47593b4a2 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_entity_signals_mapping_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_entity_signals_mapping_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EntitySignalsMappingServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): EntitySignalsMappingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EntitySignalsMappingServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2634,8 +2639,9 @@ def test_get_entity_signals_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2705,20 +2711,22 @@ def test_get_entity_signals_mapping_rest_interceptors(null_interceptor): ) client = EntitySignalsMappingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_get_entity_signals_mapping", - ) as post, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_get_entity_signals_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "pre_get_entity_signals_mapping", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_get_entity_signals_mapping", + ) as post, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_get_entity_signals_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "pre_get_entity_signals_mapping", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2776,8 +2784,9 @@ def test_list_entity_signals_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2846,20 +2855,22 @@ def test_list_entity_signals_mappings_rest_interceptors(null_interceptor): ) client = EntitySignalsMappingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_list_entity_signals_mappings", - ) as post, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_list_entity_signals_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "pre_list_entity_signals_mappings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_list_entity_signals_mappings", + ) as post, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_list_entity_signals_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "pre_list_entity_signals_mappings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2921,8 +2932,9 @@ def test_create_entity_signals_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3073,20 +3085,22 @@ def test_create_entity_signals_mapping_rest_interceptors(null_interceptor): ) client = EntitySignalsMappingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_create_entity_signals_mapping", - ) as post, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_create_entity_signals_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "pre_create_entity_signals_mapping", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_create_entity_signals_mapping", + ) as post, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_create_entity_signals_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "pre_create_entity_signals_mapping", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3150,8 +3164,9 @@ def test_update_entity_signals_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3306,20 +3321,22 @@ def test_update_entity_signals_mapping_rest_interceptors(null_interceptor): ) client = EntitySignalsMappingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_update_entity_signals_mapping", - ) as post, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_update_entity_signals_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "pre_update_entity_signals_mapping", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_update_entity_signals_mapping", + ) as post, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_update_entity_signals_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "pre_update_entity_signals_mapping", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3379,8 +3396,9 @@ def test_batch_create_entity_signals_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3449,20 +3467,22 @@ def test_batch_create_entity_signals_mappings_rest_interceptors(null_interceptor ) client = EntitySignalsMappingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_batch_create_entity_signals_mappings", - ) as post, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_batch_create_entity_signals_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "pre_batch_create_entity_signals_mappings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_batch_create_entity_signals_mappings", + ) as post, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_batch_create_entity_signals_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "pre_batch_create_entity_signals_mappings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3526,8 +3546,9 @@ def test_batch_update_entity_signals_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3596,20 +3617,22 @@ def test_batch_update_entity_signals_mappings_rest_interceptors(null_interceptor ) client = EntitySignalsMappingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_batch_update_entity_signals_mappings", - ) as post, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "post_batch_update_entity_signals_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntitySignalsMappingServiceRestInterceptor, - "pre_batch_update_entity_signals_mappings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_batch_update_entity_signals_mappings", + ) as post, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "post_batch_update_entity_signals_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntitySignalsMappingServiceRestInterceptor, + "pre_batch_update_entity_signals_mappings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3675,8 +3698,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3915,11 +3939,14 @@ def test_entity_signals_mapping_service_base_transport(): def test_entity_signals_mapping_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.entity_signals_mapping_service.transports.EntitySignalsMappingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.entity_signals_mapping_service.transports.EntitySignalsMappingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntitySignalsMappingServiceTransport( @@ -3936,9 +3963,12 @@ def test_entity_signals_mapping_service_base_transport_with_credentials_file(): def test_entity_signals_mapping_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.entity_signals_mapping_service.transports.EntitySignalsMappingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.entity_signals_mapping_service.transports.EntitySignalsMappingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntitySignalsMappingServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_geo_target_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_geo_target_service.py index 3b1821706c81..608649136738 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_geo_target_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_geo_target_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeoTargetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): GeoTargetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GeoTargetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1695,8 +1700,9 @@ def test_get_geo_target_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1771,17 +1777,20 @@ def test_get_geo_target_rest_interceptors(null_interceptor): ) client = GeoTargetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeoTargetServiceRestInterceptor, "post_get_geo_target" - ) as post, mock.patch.object( - transports.GeoTargetServiceRestInterceptor, "post_get_geo_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeoTargetServiceRestInterceptor, "pre_get_geo_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeoTargetServiceRestInterceptor, "post_get_geo_target" + ) as post, + mock.patch.object( + transports.GeoTargetServiceRestInterceptor, + "post_get_geo_target_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeoTargetServiceRestInterceptor, "pre_get_geo_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1836,8 +1845,9 @@ def test_list_geo_targets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1902,18 +1912,20 @@ def test_list_geo_targets_rest_interceptors(null_interceptor): ) client = GeoTargetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeoTargetServiceRestInterceptor, "post_list_geo_targets" - ) as post, mock.patch.object( - transports.GeoTargetServiceRestInterceptor, - "post_list_geo_targets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeoTargetServiceRestInterceptor, "pre_list_geo_targets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeoTargetServiceRestInterceptor, "post_list_geo_targets" + ) as post, + mock.patch.object( + transports.GeoTargetServiceRestInterceptor, + "post_list_geo_targets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeoTargetServiceRestInterceptor, "pre_list_geo_targets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1973,8 +1985,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2113,11 +2126,14 @@ def test_geo_target_service_base_transport(): def test_geo_target_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.geo_target_service.transports.GeoTargetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.geo_target_service.transports.GeoTargetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeoTargetServiceTransport( @@ -2134,9 +2150,12 @@ def test_geo_target_service_base_transport_with_credentials_file(): def test_geo_target_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.geo_target_service.transports.GeoTargetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.geo_target_service.transports.GeoTargetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeoTargetServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_line_item_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_line_item_service.py index 1d8115792785..baee31507cd1 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_line_item_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_line_item_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LineItemServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): assert ( LineItemServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LineItemServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1695,8 +1700,9 @@ def test_get_line_item_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1768,17 +1774,20 @@ def test_get_line_item_rest_interceptors(null_interceptor): ) client = LineItemServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineItemServiceRestInterceptor, "post_get_line_item" - ) as post, mock.patch.object( - transports.LineItemServiceRestInterceptor, "post_get_line_item_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineItemServiceRestInterceptor, "pre_get_line_item" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineItemServiceRestInterceptor, "post_get_line_item" + ) as post, + mock.patch.object( + transports.LineItemServiceRestInterceptor, + "post_get_line_item_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LineItemServiceRestInterceptor, "pre_get_line_item" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1833,8 +1842,9 @@ def test_list_line_items_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1899,17 +1909,20 @@ def test_list_line_items_rest_interceptors(null_interceptor): ) client = LineItemServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineItemServiceRestInterceptor, "post_list_line_items" - ) as post, mock.patch.object( - transports.LineItemServiceRestInterceptor, "post_list_line_items_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineItemServiceRestInterceptor, "pre_list_line_items" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineItemServiceRestInterceptor, "post_list_line_items" + ) as post, + mock.patch.object( + transports.LineItemServiceRestInterceptor, + "post_list_line_items_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LineItemServiceRestInterceptor, "pre_list_line_items" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1969,8 +1982,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2109,11 +2123,14 @@ def test_line_item_service_base_transport(): def test_line_item_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.line_item_service.transports.LineItemServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.line_item_service.transports.LineItemServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LineItemServiceTransport( @@ -2130,9 +2147,12 @@ def test_line_item_service_base_transport_with_credentials_file(): def test_line_item_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.line_item_service.transports.LineItemServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.line_item_service.transports.LineItemServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LineItemServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_carrier_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_carrier_service.py index 75bcf1ec42d9..c144fa0976d8 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_carrier_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_carrier_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MobileCarrierServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): MobileCarrierServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MobileCarrierServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1733,8 +1738,9 @@ def test_get_mobile_carrier_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1801,18 +1807,20 @@ def test_get_mobile_carrier_rest_interceptors(null_interceptor): ) client = MobileCarrierServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MobileCarrierServiceRestInterceptor, "post_get_mobile_carrier" - ) as post, mock.patch.object( - transports.MobileCarrierServiceRestInterceptor, - "post_get_mobile_carrier_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MobileCarrierServiceRestInterceptor, "pre_get_mobile_carrier" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MobileCarrierServiceRestInterceptor, "post_get_mobile_carrier" + ) as post, + mock.patch.object( + transports.MobileCarrierServiceRestInterceptor, + "post_get_mobile_carrier_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MobileCarrierServiceRestInterceptor, "pre_get_mobile_carrier" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1870,8 +1878,9 @@ def test_list_mobile_carriers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1938,18 +1947,20 @@ def test_list_mobile_carriers_rest_interceptors(null_interceptor): ) client = MobileCarrierServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MobileCarrierServiceRestInterceptor, "post_list_mobile_carriers" - ) as post, mock.patch.object( - transports.MobileCarrierServiceRestInterceptor, - "post_list_mobile_carriers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MobileCarrierServiceRestInterceptor, "pre_list_mobile_carriers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MobileCarrierServiceRestInterceptor, "post_list_mobile_carriers" + ) as post, + mock.patch.object( + transports.MobileCarrierServiceRestInterceptor, + "post_list_mobile_carriers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MobileCarrierServiceRestInterceptor, "pre_list_mobile_carriers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2009,8 +2020,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2153,11 +2165,14 @@ def test_mobile_carrier_service_base_transport(): def test_mobile_carrier_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.mobile_carrier_service.transports.MobileCarrierServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.mobile_carrier_service.transports.MobileCarrierServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MobileCarrierServiceTransport( @@ -2174,9 +2189,12 @@ def test_mobile_carrier_service_base_transport_with_credentials_file(): def test_mobile_carrier_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.mobile_carrier_service.transports.MobileCarrierServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.mobile_carrier_service.transports.MobileCarrierServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MobileCarrierServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_service.py index d1cf55d78073..89ae6aacc2dc 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MobileDeviceServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): MobileDeviceServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MobileDeviceServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1723,8 +1728,9 @@ def test_get_mobile_device_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1791,18 +1797,20 @@ def test_get_mobile_device_rest_interceptors(null_interceptor): ) client = MobileDeviceServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MobileDeviceServiceRestInterceptor, "post_get_mobile_device" - ) as post, mock.patch.object( - transports.MobileDeviceServiceRestInterceptor, - "post_get_mobile_device_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MobileDeviceServiceRestInterceptor, "pre_get_mobile_device" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MobileDeviceServiceRestInterceptor, "post_get_mobile_device" + ) as post, + mock.patch.object( + transports.MobileDeviceServiceRestInterceptor, + "post_get_mobile_device_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MobileDeviceServiceRestInterceptor, "pre_get_mobile_device" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1860,8 +1868,9 @@ def test_list_mobile_devices_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1926,18 +1935,20 @@ def test_list_mobile_devices_rest_interceptors(null_interceptor): ) client = MobileDeviceServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MobileDeviceServiceRestInterceptor, "post_list_mobile_devices" - ) as post, mock.patch.object( - transports.MobileDeviceServiceRestInterceptor, - "post_list_mobile_devices_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MobileDeviceServiceRestInterceptor, "pre_list_mobile_devices" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MobileDeviceServiceRestInterceptor, "post_list_mobile_devices" + ) as post, + mock.patch.object( + transports.MobileDeviceServiceRestInterceptor, + "post_list_mobile_devices_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MobileDeviceServiceRestInterceptor, "pre_list_mobile_devices" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1997,8 +2008,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2141,11 +2153,14 @@ def test_mobile_device_service_base_transport(): def test_mobile_device_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.mobile_device_service.transports.MobileDeviceServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.mobile_device_service.transports.MobileDeviceServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MobileDeviceServiceTransport( @@ -2162,9 +2177,12 @@ def test_mobile_device_service_base_transport_with_credentials_file(): def test_mobile_device_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.mobile_device_service.transports.MobileDeviceServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.mobile_device_service.transports.MobileDeviceServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MobileDeviceServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_submodel_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_submodel_service.py index b25634011654..773dfc1062dd 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_submodel_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_mobile_device_submodel_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MobileDeviceSubmodelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): MobileDeviceSubmodelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MobileDeviceSubmodelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1789,8 +1794,9 @@ def test_get_mobile_device_submodel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1859,20 +1865,22 @@ def test_get_mobile_device_submodel_rest_interceptors(null_interceptor): ) client = MobileDeviceSubmodelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MobileDeviceSubmodelServiceRestInterceptor, - "post_get_mobile_device_submodel", - ) as post, mock.patch.object( - transports.MobileDeviceSubmodelServiceRestInterceptor, - "post_get_mobile_device_submodel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MobileDeviceSubmodelServiceRestInterceptor, - "pre_get_mobile_device_submodel", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MobileDeviceSubmodelServiceRestInterceptor, + "post_get_mobile_device_submodel", + ) as post, + mock.patch.object( + transports.MobileDeviceSubmodelServiceRestInterceptor, + "post_get_mobile_device_submodel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MobileDeviceSubmodelServiceRestInterceptor, + "pre_get_mobile_device_submodel", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1930,8 +1938,9 @@ def test_list_mobile_device_submodels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2000,20 +2009,22 @@ def test_list_mobile_device_submodels_rest_interceptors(null_interceptor): ) client = MobileDeviceSubmodelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MobileDeviceSubmodelServiceRestInterceptor, - "post_list_mobile_device_submodels", - ) as post, mock.patch.object( - transports.MobileDeviceSubmodelServiceRestInterceptor, - "post_list_mobile_device_submodels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MobileDeviceSubmodelServiceRestInterceptor, - "pre_list_mobile_device_submodels", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MobileDeviceSubmodelServiceRestInterceptor, + "post_list_mobile_device_submodels", + ) as post, + mock.patch.object( + transports.MobileDeviceSubmodelServiceRestInterceptor, + "post_list_mobile_device_submodels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MobileDeviceSubmodelServiceRestInterceptor, + "pre_list_mobile_device_submodels", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2077,8 +2088,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2221,11 +2233,14 @@ def test_mobile_device_submodel_service_base_transport(): def test_mobile_device_submodel_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.mobile_device_submodel_service.transports.MobileDeviceSubmodelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.mobile_device_submodel_service.transports.MobileDeviceSubmodelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MobileDeviceSubmodelServiceTransport( @@ -2242,9 +2257,12 @@ def test_mobile_device_submodel_service_base_transport_with_credentials_file(): def test_mobile_device_submodel_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.mobile_device_submodel_service.transports.MobileDeviceSubmodelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.mobile_device_submodel_service.transports.MobileDeviceSubmodelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MobileDeviceSubmodelServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_network_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_network_service.py index 949259c49110..7905bf846243 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_network_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_network_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( NetworkServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1510,8 +1515,9 @@ def test_get_network_rest_bad_request(request_type=network_service.GetNetworkReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1592,17 +1598,19 @@ def test_get_network_rest_interceptors(null_interceptor): ) client = NetworkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkServiceRestInterceptor, "post_get_network" - ) as post, mock.patch.object( - transports.NetworkServiceRestInterceptor, "post_get_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkServiceRestInterceptor, "pre_get_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkServiceRestInterceptor, "post_get_network" + ) as post, + mock.patch.object( + transports.NetworkServiceRestInterceptor, "post_get_network_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServiceRestInterceptor, "pre_get_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1655,8 +1663,9 @@ def test_list_networks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1721,17 +1730,19 @@ def test_list_networks_rest_interceptors(null_interceptor): ) client = NetworkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkServiceRestInterceptor, "post_list_networks" - ) as post, mock.patch.object( - transports.NetworkServiceRestInterceptor, "post_list_networks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkServiceRestInterceptor, "pre_list_networks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkServiceRestInterceptor, "post_list_networks" + ) as post, + mock.patch.object( + transports.NetworkServiceRestInterceptor, "post_list_networks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkServiceRestInterceptor, "pre_list_networks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1791,8 +1802,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -1931,11 +1943,14 @@ def test_network_service_base_transport(): def test_network_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.network_service.transports.NetworkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.network_service.transports.NetworkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkServiceTransport( @@ -1952,9 +1967,12 @@ def test_network_service_base_transport_with_credentials_file(): def test_network_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.network_service.transports.NetworkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.network_service.transports.NetworkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_service.py index ea5b4afdfd17..f1be1c1e3b74 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert OperatingSystemServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): OperatingSystemServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + OperatingSystemServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1742,8 +1747,9 @@ def test_get_operating_system_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1808,18 +1814,21 @@ def test_get_operating_system_rest_interceptors(null_interceptor): ) client = OperatingSystemServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OperatingSystemServiceRestInterceptor, "post_get_operating_system" - ) as post, mock.patch.object( - transports.OperatingSystemServiceRestInterceptor, - "post_get_operating_system_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OperatingSystemServiceRestInterceptor, "pre_get_operating_system" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OperatingSystemServiceRestInterceptor, + "post_get_operating_system", + ) as post, + mock.patch.object( + transports.OperatingSystemServiceRestInterceptor, + "post_get_operating_system_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OperatingSystemServiceRestInterceptor, "pre_get_operating_system" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1877,8 +1886,9 @@ def test_list_operating_systems_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1945,18 +1955,22 @@ def test_list_operating_systems_rest_interceptors(null_interceptor): ) client = OperatingSystemServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OperatingSystemServiceRestInterceptor, "post_list_operating_systems" - ) as post, mock.patch.object( - transports.OperatingSystemServiceRestInterceptor, - "post_list_operating_systems_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OperatingSystemServiceRestInterceptor, "pre_list_operating_systems" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OperatingSystemServiceRestInterceptor, + "post_list_operating_systems", + ) as post, + mock.patch.object( + transports.OperatingSystemServiceRestInterceptor, + "post_list_operating_systems_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OperatingSystemServiceRestInterceptor, + "pre_list_operating_systems", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2016,8 +2030,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2160,11 +2175,14 @@ def test_operating_system_service_base_transport(): def test_operating_system_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.operating_system_service.transports.OperatingSystemServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.operating_system_service.transports.OperatingSystemServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OperatingSystemServiceTransport( @@ -2181,9 +2199,12 @@ def test_operating_system_service_base_transport_with_credentials_file(): def test_operating_system_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.operating_system_service.transports.OperatingSystemServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.operating_system_service.transports.OperatingSystemServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OperatingSystemServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_version_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_version_service.py index c8e78da942c5..4e1cca87d846 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_version_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_operating_system_version_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert OperatingSystemVersionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): OperatingSystemVersionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + OperatingSystemVersionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1814,8 +1819,9 @@ def test_get_operating_system_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1888,20 +1894,22 @@ def test_get_operating_system_version_rest_interceptors(null_interceptor): ) client = OperatingSystemVersionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OperatingSystemVersionServiceRestInterceptor, - "post_get_operating_system_version", - ) as post, mock.patch.object( - transports.OperatingSystemVersionServiceRestInterceptor, - "post_get_operating_system_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OperatingSystemVersionServiceRestInterceptor, - "pre_get_operating_system_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OperatingSystemVersionServiceRestInterceptor, + "post_get_operating_system_version", + ) as post, + mock.patch.object( + transports.OperatingSystemVersionServiceRestInterceptor, + "post_get_operating_system_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OperatingSystemVersionServiceRestInterceptor, + "pre_get_operating_system_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1961,8 +1969,9 @@ def test_list_operating_system_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2033,20 +2042,22 @@ def test_list_operating_system_versions_rest_interceptors(null_interceptor): ) client = OperatingSystemVersionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OperatingSystemVersionServiceRestInterceptor, - "post_list_operating_system_versions", - ) as post, mock.patch.object( - transports.OperatingSystemVersionServiceRestInterceptor, - "post_list_operating_system_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OperatingSystemVersionServiceRestInterceptor, - "pre_list_operating_system_versions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OperatingSystemVersionServiceRestInterceptor, + "post_list_operating_system_versions", + ) as post, + mock.patch.object( + transports.OperatingSystemVersionServiceRestInterceptor, + "post_list_operating_system_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OperatingSystemVersionServiceRestInterceptor, + "pre_list_operating_system_versions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2110,8 +2121,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2258,11 +2270,14 @@ def test_operating_system_version_service_base_transport(): def test_operating_system_version_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.operating_system_version_service.transports.OperatingSystemVersionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.operating_system_version_service.transports.OperatingSystemVersionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OperatingSystemVersionServiceTransport( @@ -2279,9 +2294,12 @@ def test_operating_system_version_service_base_transport_with_credentials_file() def test_operating_system_version_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.operating_system_version_service.transports.OperatingSystemVersionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.operating_system_version_service.transports.OperatingSystemVersionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OperatingSystemVersionServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_order_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_order_service.py index b69ab4c204ad..1dded7ac3a09 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_order_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_order_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert OrderServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert OrderServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + OrderServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1655,8 +1660,9 @@ def test_get_order_rest_bad_request(request_type=order_service.GetOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1763,17 +1769,19 @@ def test_get_order_rest_interceptors(null_interceptor): ) client = OrderServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrderServiceRestInterceptor, "post_get_order" - ) as post, mock.patch.object( - transports.OrderServiceRestInterceptor, "post_get_order_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.OrderServiceRestInterceptor, "pre_get_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrderServiceRestInterceptor, "post_get_order" + ) as post, + mock.patch.object( + transports.OrderServiceRestInterceptor, "post_get_order_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.OrderServiceRestInterceptor, "pre_get_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1822,8 +1830,9 @@ def test_list_orders_rest_bad_request(request_type=order_service.ListOrdersReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1888,17 +1897,19 @@ def test_list_orders_rest_interceptors(null_interceptor): ) client = OrderServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrderServiceRestInterceptor, "post_list_orders" - ) as post, mock.patch.object( - transports.OrderServiceRestInterceptor, "post_list_orders_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.OrderServiceRestInterceptor, "pre_list_orders" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrderServiceRestInterceptor, "post_list_orders" + ) as post, + mock.patch.object( + transports.OrderServiceRestInterceptor, "post_list_orders_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.OrderServiceRestInterceptor, "pre_list_orders" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1955,8 +1966,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2095,11 +2107,14 @@ def test_order_service_base_transport(): def test_order_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.order_service.transports.OrderServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.order_service.transports.OrderServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OrderServiceTransport( @@ -2116,9 +2131,12 @@ def test_order_service_base_transport_with_credentials_file(): def test_order_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.order_service.transports.OrderServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.order_service.transports.OrderServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OrderServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_placement_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_placement_service.py index 9927c6d0113a..89442d4be8e1 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_placement_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_placement_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PlacementServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): PlacementServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PlacementServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3077,8 +3082,9 @@ def test_get_placement_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3153,17 +3159,20 @@ def test_get_placement_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_get_placement" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_get_placement_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_get_placement" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_get_placement" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_get_placement_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_get_placement" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3218,8 +3227,9 @@ def test_list_placements_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3284,17 +3294,20 @@ def test_list_placements_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_list_placements" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_list_placements_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_list_placements" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_list_placements" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_list_placements_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_list_placements" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3352,8 +3365,9 @@ def test_create_placement_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3505,18 +3519,20 @@ def test_create_placement_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_create_placement" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_create_placement_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_create_placement" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_create_placement" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_create_placement_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_create_placement" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3571,8 +3587,9 @@ def test_update_placement_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3724,18 +3741,20 @@ def test_update_placement_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_update_placement" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_update_placement_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_update_placement" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_update_placement" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_update_placement_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_update_placement" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3790,8 +3809,9 @@ def test_batch_create_placements_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3851,18 +3871,20 @@ def test_batch_create_placements_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_batch_create_placements" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_batch_create_placements_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_batch_create_placements" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_batch_create_placements" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_batch_create_placements_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_batch_create_placements" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3920,8 +3942,9 @@ def test_batch_update_placements_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3981,18 +4004,20 @@ def test_batch_update_placements_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_batch_update_placements" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_batch_update_placements_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_batch_update_placements" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_batch_update_placements" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_batch_update_placements_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_batch_update_placements" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4050,8 +4075,9 @@ def test_batch_activate_placements_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4113,18 +4139,20 @@ def test_batch_activate_placements_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_batch_activate_placements" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_batch_activate_placements_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_batch_activate_placements" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_batch_activate_placements" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_batch_activate_placements_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_batch_activate_placements" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4182,8 +4210,9 @@ def test_batch_deactivate_placements_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4245,18 +4274,22 @@ def test_batch_deactivate_placements_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_batch_deactivate_placements" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_batch_deactivate_placements_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_batch_deactivate_placements" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_batch_deactivate_placements", + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_batch_deactivate_placements_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "pre_batch_deactivate_placements", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4314,8 +4347,9 @@ def test_batch_archive_placements_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4375,18 +4409,20 @@ def test_batch_archive_placements_rest_interceptors(null_interceptor): ) client = PlacementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlacementServiceRestInterceptor, "post_batch_archive_placements" - ) as post, mock.patch.object( - transports.PlacementServiceRestInterceptor, - "post_batch_archive_placements_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlacementServiceRestInterceptor, "pre_batch_archive_placements" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "post_batch_archive_placements" + ) as post, + mock.patch.object( + transports.PlacementServiceRestInterceptor, + "post_batch_archive_placements_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlacementServiceRestInterceptor, "pre_batch_archive_placements" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4446,8 +4482,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4743,11 +4780,14 @@ def test_placement_service_base_transport(): def test_placement_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.placement_service.transports.PlacementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.placement_service.transports.PlacementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PlacementServiceTransport( @@ -4764,9 +4804,12 @@ def test_placement_service_base_transport_with_credentials_file(): def test_placement_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.placement_service.transports.PlacementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.placement_service.transports.PlacementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PlacementServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_deal_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_deal_service.py index c16bc4e25dba..1be7bb1f05ec 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_deal_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_deal_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PrivateAuctionDealServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): PrivateAuctionDealServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PrivateAuctionDealServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2170,8 +2175,9 @@ def test_get_private_auction_deal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2258,20 +2264,22 @@ def test_get_private_auction_deal_rest_interceptors(null_interceptor): ) client = PrivateAuctionDealServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_get_private_auction_deal", - ) as post, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_get_private_auction_deal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "pre_get_private_auction_deal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_get_private_auction_deal", + ) as post, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_get_private_auction_deal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "pre_get_private_auction_deal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2329,8 +2337,9 @@ def test_list_private_auction_deals_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2397,20 +2406,22 @@ def test_list_private_auction_deals_rest_interceptors(null_interceptor): ) client = PrivateAuctionDealServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_list_private_auction_deals", - ) as post, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_list_private_auction_deals_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "pre_list_private_auction_deals", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_list_private_auction_deals", + ) as post, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_list_private_auction_deals_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "pre_list_private_auction_deals", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2472,8 +2483,9 @@ def test_create_private_auction_deal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2864,20 +2876,22 @@ def test_create_private_auction_deal_rest_interceptors(null_interceptor): ) client = PrivateAuctionDealServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_create_private_auction_deal", - ) as post, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_create_private_auction_deal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "pre_create_private_auction_deal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_create_private_auction_deal", + ) as post, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_create_private_auction_deal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "pre_create_private_auction_deal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2937,8 +2951,9 @@ def test_update_private_auction_deal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3331,20 +3346,22 @@ def test_update_private_auction_deal_rest_interceptors(null_interceptor): ) client = PrivateAuctionDealServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_update_private_auction_deal", - ) as post, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "post_update_private_auction_deal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionDealServiceRestInterceptor, - "pre_update_private_auction_deal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_update_private_auction_deal", + ) as post, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "post_update_private_auction_deal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionDealServiceRestInterceptor, + "pre_update_private_auction_deal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3404,8 +3421,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3594,11 +3612,14 @@ def test_private_auction_deal_service_base_transport(): def test_private_auction_deal_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.private_auction_deal_service.transports.PrivateAuctionDealServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.private_auction_deal_service.transports.PrivateAuctionDealServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrivateAuctionDealServiceTransport( @@ -3615,9 +3636,12 @@ def test_private_auction_deal_service_base_transport_with_credentials_file(): def test_private_auction_deal_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.private_auction_deal_service.transports.PrivateAuctionDealServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.private_auction_deal_service.transports.PrivateAuctionDealServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrivateAuctionDealServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_service.py index 5e24177e1f65..13803f317c95 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_private_auction_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PrivateAuctionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): PrivateAuctionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PrivateAuctionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2126,8 +2131,9 @@ def test_get_private_auction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2200,18 +2206,20 @@ def test_get_private_auction_rest_interceptors(null_interceptor): ) client = PrivateAuctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "post_get_private_auction" - ) as post, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, - "post_get_private_auction_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "pre_get_private_auction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, "post_get_private_auction" + ) as post, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_get_private_auction_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, "pre_get_private_auction" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2269,8 +2277,9 @@ def test_list_private_auctions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2337,18 +2346,21 @@ def test_list_private_auctions_rest_interceptors(null_interceptor): ) client = PrivateAuctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "post_list_private_auctions" - ) as post, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, - "post_list_private_auctions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "pre_list_private_auctions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_list_private_auctions", + ) as post, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_list_private_auctions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, "pre_list_private_auctions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2406,8 +2418,9 @@ def test_create_private_auction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2562,18 +2575,22 @@ def test_create_private_auction_rest_interceptors(null_interceptor): ) client = PrivateAuctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "post_create_private_auction" - ) as post, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, - "post_create_private_auction_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "pre_create_private_auction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_create_private_auction", + ) as post, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_create_private_auction_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "pre_create_private_auction", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2633,8 +2650,9 @@ def test_update_private_auction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2791,18 +2809,22 @@ def test_update_private_auction_rest_interceptors(null_interceptor): ) client = PrivateAuctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "post_update_private_auction" - ) as post, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, - "post_update_private_auction_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrivateAuctionServiceRestInterceptor, "pre_update_private_auction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_update_private_auction", + ) as post, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "post_update_private_auction_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrivateAuctionServiceRestInterceptor, + "pre_update_private_auction", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2862,8 +2884,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3052,11 +3075,14 @@ def test_private_auction_service_base_transport(): def test_private_auction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.private_auction_service.transports.PrivateAuctionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.private_auction_service.transports.PrivateAuctionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrivateAuctionServiceTransport( @@ -3073,9 +3099,12 @@ def test_private_auction_service_base_transport_with_credentials_file(): def test_private_auction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.private_auction_service.transports.PrivateAuctionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.private_auction_service.transports.PrivateAuctionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrivateAuctionServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_programmatic_buyer_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_programmatic_buyer_service.py index 2eaafb495eef..4ea054e00f51 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_programmatic_buyer_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_programmatic_buyer_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProgrammaticBuyerServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): ProgrammaticBuyerServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ProgrammaticBuyerServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1750,8 +1755,9 @@ def test_get_programmatic_buyer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1828,19 +1834,22 @@ def test_get_programmatic_buyer_rest_interceptors(null_interceptor): ) client = ProgrammaticBuyerServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProgrammaticBuyerServiceRestInterceptor, - "post_get_programmatic_buyer", - ) as post, mock.patch.object( - transports.ProgrammaticBuyerServiceRestInterceptor, - "post_get_programmatic_buyer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProgrammaticBuyerServiceRestInterceptor, "pre_get_programmatic_buyer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProgrammaticBuyerServiceRestInterceptor, + "post_get_programmatic_buyer", + ) as post, + mock.patch.object( + transports.ProgrammaticBuyerServiceRestInterceptor, + "post_get_programmatic_buyer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProgrammaticBuyerServiceRestInterceptor, + "pre_get_programmatic_buyer", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1898,8 +1907,9 @@ def test_list_programmatic_buyers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1966,20 +1976,22 @@ def test_list_programmatic_buyers_rest_interceptors(null_interceptor): ) client = ProgrammaticBuyerServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProgrammaticBuyerServiceRestInterceptor, - "post_list_programmatic_buyers", - ) as post, mock.patch.object( - transports.ProgrammaticBuyerServiceRestInterceptor, - "post_list_programmatic_buyers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProgrammaticBuyerServiceRestInterceptor, - "pre_list_programmatic_buyers", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProgrammaticBuyerServiceRestInterceptor, + "post_list_programmatic_buyers", + ) as post, + mock.patch.object( + transports.ProgrammaticBuyerServiceRestInterceptor, + "post_list_programmatic_buyers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProgrammaticBuyerServiceRestInterceptor, + "pre_list_programmatic_buyers", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2041,8 +2053,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2185,11 +2198,14 @@ def test_programmatic_buyer_service_base_transport(): def test_programmatic_buyer_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.programmatic_buyer_service.transports.ProgrammaticBuyerServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.programmatic_buyer_service.transports.ProgrammaticBuyerServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProgrammaticBuyerServiceTransport( @@ -2206,9 +2222,12 @@ def test_programmatic_buyer_service_base_transport_with_credentials_file(): def test_programmatic_buyer_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.programmatic_buyer_service.transports.ProgrammaticBuyerServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.programmatic_buyer_service.transports.ProgrammaticBuyerServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProgrammaticBuyerServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_report_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_report_service.py index f729ebf12843..55e6cc90e06f 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_report_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_report_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReportServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): assert ( ReportServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReportServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2386,8 +2391,9 @@ def test_get_report_rest_bad_request(request_type=report_service.GetReportReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2458,17 +2464,19 @@ def test_get_report_rest_interceptors(null_interceptor): ) client = ReportServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_get_report" - ) as post, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_get_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReportServiceRestInterceptor, "pre_get_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_get_report" + ) as post, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_get_report_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReportServiceRestInterceptor, "pre_get_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2519,8 +2527,9 @@ def test_list_reports_rest_bad_request(request_type=report_service.ListReportsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2585,17 +2594,19 @@ def test_list_reports_rest_interceptors(null_interceptor): ) client = ReportServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_list_reports" - ) as post, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_list_reports_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReportServiceRestInterceptor, "pre_list_reports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_list_reports" + ) as post, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_list_reports_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReportServiceRestInterceptor, "pre_list_reports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2650,8 +2661,9 @@ def test_create_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2874,17 +2886,19 @@ def test_create_report_rest_interceptors(null_interceptor): ) client = ReportServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_create_report" - ) as post, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_create_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReportServiceRestInterceptor, "pre_create_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_create_report" + ) as post, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_create_report_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReportServiceRestInterceptor, "pre_create_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2937,8 +2951,9 @@ def test_update_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3161,17 +3176,19 @@ def test_update_report_rest_interceptors(null_interceptor): ) client = ReportServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_update_report" - ) as post, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_update_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReportServiceRestInterceptor, "pre_update_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_update_report" + ) as post, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_update_report_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReportServiceRestInterceptor, "pre_update_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3222,8 +3239,9 @@ def test_run_report_rest_bad_request(request_type=report_service.RunReportReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3280,19 +3298,20 @@ def test_run_report_rest_interceptors(null_interceptor): ) client = ReportServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ReportServiceRestInterceptor, "post_run_report" - ) as post, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_run_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReportServiceRestInterceptor, "pre_run_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_run_report" + ) as post, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_run_report_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReportServiceRestInterceptor, "pre_run_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3345,8 +3364,9 @@ def test_fetch_report_result_rows_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3411,18 +3431,20 @@ def test_fetch_report_result_rows_rest_interceptors(null_interceptor): ) client = ReportServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReportServiceRestInterceptor, "post_fetch_report_result_rows" - ) as post, mock.patch.object( - transports.ReportServiceRestInterceptor, - "post_fetch_report_result_rows_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReportServiceRestInterceptor, "pre_fetch_report_result_rows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReportServiceRestInterceptor, "post_fetch_report_result_rows" + ) as post, + mock.patch.object( + transports.ReportServiceRestInterceptor, + "post_fetch_report_result_rows_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReportServiceRestInterceptor, "pre_fetch_report_result_rows" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3482,8 +3504,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3730,11 +3753,14 @@ def test_report_service_base_transport(): def test_report_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.report_service.transports.ReportServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.report_service.transports.ReportServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReportServiceTransport( @@ -3751,9 +3777,12 @@ def test_report_service_base_transport_with_credentials_file(): def test_report_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.report_service.transports.ReportServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.report_service.transports.ReportServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReportServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_role_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_role_service.py index b597adcbf7a2..ec09c3ccdfde 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_role_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_role_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RoleServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -137,6 +138,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RoleServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RoleServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1644,8 +1648,9 @@ def test_get_role_rest_bad_request(request_type=role_service.GetRoleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1718,17 +1723,17 @@ def test_get_role_rest_interceptors(null_interceptor): ) client = RoleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoleServiceRestInterceptor, "post_get_role" - ) as post, mock.patch.object( - transports.RoleServiceRestInterceptor, "post_get_role_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoleServiceRestInterceptor, "pre_get_role" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoleServiceRestInterceptor, "post_get_role" + ) as post, + mock.patch.object( + transports.RoleServiceRestInterceptor, "post_get_role_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoleServiceRestInterceptor, "pre_get_role") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1777,8 +1782,9 @@ def test_list_roles_rest_bad_request(request_type=role_service.ListRolesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1843,17 +1849,19 @@ def test_list_roles_rest_interceptors(null_interceptor): ) client = RoleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoleServiceRestInterceptor, "post_list_roles" - ) as post, mock.patch.object( - transports.RoleServiceRestInterceptor, "post_list_roles_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoleServiceRestInterceptor, "pre_list_roles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoleServiceRestInterceptor, "post_list_roles" + ) as post, + mock.patch.object( + transports.RoleServiceRestInterceptor, "post_list_roles_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoleServiceRestInterceptor, "pre_list_roles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1908,8 +1916,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2048,11 +2057,14 @@ def test_role_service_base_transport(): def test_role_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.role_service.transports.RoleServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.role_service.transports.RoleServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoleServiceTransport( @@ -2069,9 +2081,12 @@ def test_role_service_base_transport_with_credentials_file(): def test_role_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.role_service.transports.RoleServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.role_service.transports.RoleServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoleServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_site_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_site_service.py index 2019ef756959..f0e12b7f5f41 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_site_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_site_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SiteServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SiteServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SiteServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -2804,8 +2808,9 @@ def test_get_site_rest_bad_request(request_type=site_service.GetSiteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2877,17 +2882,17 @@ def test_get_site_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_get_site" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_get_site_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_get_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_get_site" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_get_site_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SiteServiceRestInterceptor, "pre_get_site") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2936,8 +2941,9 @@ def test_list_sites_rest_bad_request(request_type=site_service.ListSitesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3002,17 +3008,19 @@ def test_list_sites_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_list_sites" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_list_sites_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_list_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_list_sites" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_list_sites_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_list_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3063,8 +3071,9 @@ def test_create_site_rest_bad_request(request_type=site_service.CreateSiteReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3211,17 +3220,19 @@ def test_create_site_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_create_site" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_create_site_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_create_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_create_site" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_create_site_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_create_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3272,8 +3283,9 @@ def test_batch_create_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3333,17 +3345,20 @@ def test_batch_create_sites_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_batch_create_sites" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_batch_create_sites_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_batch_create_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_batch_create_sites" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, + "post_batch_create_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_batch_create_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3399,8 +3414,9 @@ def test_update_site_rest_bad_request(request_type=site_service.UpdateSiteReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3547,17 +3563,19 @@ def test_update_site_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_update_site" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_update_site_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_update_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_update_site" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_update_site_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_update_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3608,8 +3626,9 @@ def test_batch_update_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3669,17 +3688,20 @@ def test_batch_update_sites_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_batch_update_sites" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_batch_update_sites_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_batch_update_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_batch_update_sites" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, + "post_batch_update_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_batch_update_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3737,8 +3759,9 @@ def test_batch_deactivate_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3798,18 +3821,20 @@ def test_batch_deactivate_sites_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_batch_deactivate_sites" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, - "post_batch_deactivate_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_batch_deactivate_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, "post_batch_deactivate_sites" + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, + "post_batch_deactivate_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_batch_deactivate_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3867,8 +3892,9 @@ def test_batch_submit_sites_for_approval_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3928,18 +3954,21 @@ def test_batch_submit_sites_for_approval_rest_interceptors(null_interceptor): ) client = SiteServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteServiceRestInterceptor, "post_batch_submit_sites_for_approval" - ) as post, mock.patch.object( - transports.SiteServiceRestInterceptor, - "post_batch_submit_sites_for_approval_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteServiceRestInterceptor, "pre_batch_submit_sites_for_approval" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteServiceRestInterceptor, + "post_batch_submit_sites_for_approval", + ) as post, + mock.patch.object( + transports.SiteServiceRestInterceptor, + "post_batch_submit_sites_for_approval_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteServiceRestInterceptor, "pre_batch_submit_sites_for_approval" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3999,8 +4028,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4273,11 +4303,14 @@ def test_site_service_base_transport(): def test_site_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.site_service.transports.SiteServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.site_service.transports.SiteServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteServiceTransport( @@ -4294,9 +4327,12 @@ def test_site_service_base_transport_with_credentials_file(): def test_site_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.site_service.transports.SiteServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.site_service.transports.SiteServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_taxonomy_category_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_taxonomy_category_service.py index 2956d8e900e7..38ac8d80d063 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_taxonomy_category_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_taxonomy_category_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TaxonomyCategoryServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): TaxonomyCategoryServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TaxonomyCategoryServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1744,8 +1749,9 @@ def test_get_taxonomy_category_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1825,18 +1831,22 @@ def test_get_taxonomy_category_rest_interceptors(null_interceptor): ) client = TaxonomyCategoryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TaxonomyCategoryServiceRestInterceptor, "post_get_taxonomy_category" - ) as post, mock.patch.object( - transports.TaxonomyCategoryServiceRestInterceptor, - "post_get_taxonomy_category_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TaxonomyCategoryServiceRestInterceptor, "pre_get_taxonomy_category" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TaxonomyCategoryServiceRestInterceptor, + "post_get_taxonomy_category", + ) as post, + mock.patch.object( + transports.TaxonomyCategoryServiceRestInterceptor, + "post_get_taxonomy_category_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TaxonomyCategoryServiceRestInterceptor, + "pre_get_taxonomy_category", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1894,8 +1904,9 @@ def test_list_taxonomy_categories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1962,20 +1973,22 @@ def test_list_taxonomy_categories_rest_interceptors(null_interceptor): ) client = TaxonomyCategoryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TaxonomyCategoryServiceRestInterceptor, - "post_list_taxonomy_categories", - ) as post, mock.patch.object( - transports.TaxonomyCategoryServiceRestInterceptor, - "post_list_taxonomy_categories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TaxonomyCategoryServiceRestInterceptor, - "pre_list_taxonomy_categories", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TaxonomyCategoryServiceRestInterceptor, + "post_list_taxonomy_categories", + ) as post, + mock.patch.object( + transports.TaxonomyCategoryServiceRestInterceptor, + "post_list_taxonomy_categories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TaxonomyCategoryServiceRestInterceptor, + "pre_list_taxonomy_categories", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2035,8 +2048,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2179,11 +2193,14 @@ def test_taxonomy_category_service_base_transport(): def test_taxonomy_category_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.taxonomy_category_service.transports.TaxonomyCategoryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.taxonomy_category_service.transports.TaxonomyCategoryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TaxonomyCategoryServiceTransport( @@ -2200,9 +2217,12 @@ def test_taxonomy_category_service_base_transport_with_credentials_file(): def test_taxonomy_category_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.taxonomy_category_service.transports.TaxonomyCategoryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.taxonomy_category_service.transports.TaxonomyCategoryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TaxonomyCategoryServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_team_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_team_service.py index 5886b5c1fdde..c8c5d8d8f558 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_team_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_team_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TeamServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TeamServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TeamServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -2797,8 +2801,9 @@ def test_get_team_rest_bad_request(request_type=team_service.GetTeamRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2873,17 +2878,17 @@ def test_get_team_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_get_team" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_get_team_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_get_team" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_get_team" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_get_team_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TeamServiceRestInterceptor, "pre_get_team") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2932,8 +2937,9 @@ def test_list_teams_rest_bad_request(request_type=team_service.ListTeamsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2998,17 +3004,19 @@ def test_list_teams_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_list_teams" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_list_teams_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_list_teams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_list_teams" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_list_teams_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_list_teams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3059,8 +3067,9 @@ def test_create_team_rest_bad_request(request_type=team_service.CreateTeamReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3211,17 +3220,19 @@ def test_create_team_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_create_team" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_create_team_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_create_team" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_create_team" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_create_team_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_create_team" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3272,8 +3283,9 @@ def test_batch_create_teams_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3333,17 +3345,20 @@ def test_batch_create_teams_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_create_teams" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_create_teams_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_batch_create_teams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_batch_create_teams" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, + "post_batch_create_teams_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_batch_create_teams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3399,8 +3414,9 @@ def test_update_team_rest_bad_request(request_type=team_service.UpdateTeamReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3551,17 +3567,19 @@ def test_update_team_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_update_team" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_update_team_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_update_team" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_update_team" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_update_team_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_update_team" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3612,8 +3630,9 @@ def test_batch_update_teams_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3673,17 +3692,20 @@ def test_batch_update_teams_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_update_teams" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_update_teams_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_batch_update_teams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_batch_update_teams" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, + "post_batch_update_teams_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_batch_update_teams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3741,8 +3763,9 @@ def test_batch_activate_teams_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3802,17 +3825,20 @@ def test_batch_activate_teams_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_activate_teams" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_activate_teams_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_batch_activate_teams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_batch_activate_teams" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, + "post_batch_activate_teams_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_batch_activate_teams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3870,8 +3896,9 @@ def test_batch_deactivate_teams_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3931,18 +3958,20 @@ def test_batch_deactivate_teams_rest_interceptors(null_interceptor): ) client = TeamServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TeamServiceRestInterceptor, "post_batch_deactivate_teams" - ) as post, mock.patch.object( - transports.TeamServiceRestInterceptor, - "post_batch_deactivate_teams_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TeamServiceRestInterceptor, "pre_batch_deactivate_teams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TeamServiceRestInterceptor, "post_batch_deactivate_teams" + ) as post, + mock.patch.object( + transports.TeamServiceRestInterceptor, + "post_batch_deactivate_teams_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TeamServiceRestInterceptor, "pre_batch_deactivate_teams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4002,8 +4031,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4276,11 +4306,14 @@ def test_team_service_base_transport(): def test_team_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.team_service.transports.TeamServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.team_service.transports.TeamServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TeamServiceTransport( @@ -4297,9 +4330,12 @@ def test_team_service_base_transport_with_credentials_file(): def test_team_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.team_service.transports.TeamServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.team_service.transports.TeamServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TeamServiceTransport() diff --git a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_user_service.py b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_user_service.py index 6be67f08aaa5..265b2a9e96dc 100644 --- a/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_user_service.py +++ b/packages/google-ads-admanager/tests/unit/gapic/admanager_v1/test_user_service.py @@ -115,6 +115,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -133,6 +134,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert UserServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + UserServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1384,8 +1388,9 @@ def test_get_user_rest_bad_request(request_type=user_service.GetUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1464,17 +1469,17 @@ def test_get_user_rest_interceptors(null_interceptor): ) client = UserServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserServiceRestInterceptor, "post_get_user" - ) as post, mock.patch.object( - transports.UserServiceRestInterceptor, "post_get_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UserServiceRestInterceptor, "pre_get_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserServiceRestInterceptor, "post_get_user" + ) as post, + mock.patch.object( + transports.UserServiceRestInterceptor, "post_get_user_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UserServiceRestInterceptor, "pre_get_user") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1527,8 +1532,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -1646,11 +1652,14 @@ def test_user_service_base_transport(): def test_user_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.admanager_v1.services.user_service.transports.UserServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.admanager_v1.services.user_service.transports.UserServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserServiceTransport( @@ -1667,9 +1676,12 @@ def test_user_service_base_transport_with_credentials_file(): def test_user_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.admanager_v1.services.user_service.transports.UserServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.admanager_v1.services.user_service.transports.UserServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserServiceTransport() diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/async_client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/async_client.py index d545d500ec0f..99777c983b4a 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/async_client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> IngestionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/client.py index 4fa517fa7a63..272feb989932 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/client.py @@ -111,7 +111,7 @@ class IngestionServiceClient(metaclass=IngestionServiceClientMeta): """Service for sending audience data to supported destinations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -414,7 +418,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -511,7 +515,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = IngestionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/README.rst b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/README.rst index f36ae8169b64..d136470ef939 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/README.rst +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IngestionServiceTransport` is the ABC for all transports. -- public child `IngestionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IngestionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIngestionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IngestionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IngestionServiceTransport`` is the ABC for all transports. + +- public child ``IngestionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IngestionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIngestionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IngestionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/base.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/base.py index f9643c305549..21830e61896b 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/base.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc.py index 00603b147821..223eca299243 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc_asyncio.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc_asyncio.py index 1712ec86a94b..8b891a02ce39 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc_asyncio.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/rest.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/rest.py index 16456968ba8f..e9e76b63b3e7 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/rest.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/ingestion_service/transports/rest.py @@ -383,6 +383,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IngestionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/async_client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/async_client.py index fa6df2e7bb47..918437ff9aa5 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/async_client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/async_client.py @@ -199,7 +199,7 @@ def transport(self) -> MarketingDataInsightsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/client.py index 868d5a94bf81..f1e7e4470417 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/client.py @@ -115,7 +115,7 @@ class MarketingDataInsightsServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -422,7 +426,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -521,7 +525,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( self._universe_domain = MarketingDataInsightsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/README.rst b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/README.rst index 9f54b9a0e3cd..0ffde72eda2d 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/README.rst +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MarketingDataInsightsServiceTransport` is the ABC for all transports. -- public child `MarketingDataInsightsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MarketingDataInsightsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMarketingDataInsightsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MarketingDataInsightsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MarketingDataInsightsServiceTransport`` is the ABC for all transports. + +- public child ``MarketingDataInsightsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MarketingDataInsightsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMarketingDataInsightsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MarketingDataInsightsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/base.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/base.py index af0ebeeb574e..22e9decb154c 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/base.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc.py index 6a8d9a32f98a..c3d5a3412932 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc_asyncio.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc_asyncio.py index 8b016b258d4c..50448705edeb 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc_asyncio.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/rest.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/rest.py index 41e86f43cf3a..20d3fd1e18c2 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/rest.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/marketing_data_insights_service/transports/rest.py @@ -209,6 +209,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MarketingDataInsightsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/async_client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/async_client.py index 4fb0eb99b82a..455252a43213 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/async_client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> PartnerLinkServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/client.py index eacc94204e5b..b4f7c88d7ec1 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/client.py @@ -109,7 +109,7 @@ class PartnerLinkServiceClient(metaclass=PartnerLinkServiceClientMeta): """Service for managing partner links.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -117,7 +117,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -127,6 +127,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -434,7 +438,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -531,7 +535,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -631,7 +635,7 @@ def __init__( self._universe_domain = PartnerLinkServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/README.rst b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/README.rst index 32e481759b03..0aa678c7684e 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/README.rst +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PartnerLinkServiceTransport` is the ABC for all transports. -- public child `PartnerLinkServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PartnerLinkServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePartnerLinkServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PartnerLinkServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PartnerLinkServiceTransport`` is the ABC for all transports. + +- public child ``PartnerLinkServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PartnerLinkServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePartnerLinkServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PartnerLinkServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/base.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/base.py index 0b10836cef44..2d677e85bc9c 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/base.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc.py index ede50cceb91a..23cd61ebd7c5 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc_asyncio.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc_asyncio.py index ece9c8f8d570..43980b7cca20 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc_asyncio.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/rest.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/rest.py index 32ad88b89478..18ca1dcfc249 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/rest.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/partner_link_service/transports/rest.py @@ -284,6 +284,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PartnerLinkServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/async_client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/async_client.py index dfc5064e4e22..b8f4e3a4c26b 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/async_client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> UserListDirectLicenseServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/client.py index aa6a0dfb69df..11d676fadedf 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/client.py @@ -131,7 +131,7 @@ class UserListDirectLicenseServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -460,7 +464,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -559,7 +563,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = UserListDirectLicenseServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/README.rst b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/README.rst index f55c2e5badf1..d07d1ab6fa13 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/README.rst +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserListDirectLicenseServiceTransport` is the ABC for all transports. -- public child `UserListDirectLicenseServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserListDirectLicenseServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserListDirectLicenseServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserListDirectLicenseServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserListDirectLicenseServiceTransport`` is the ABC for all transports. + +- public child ``UserListDirectLicenseServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserListDirectLicenseServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserListDirectLicenseServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserListDirectLicenseServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/base.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/base.py index bab8e9ebbd37..473ec191563b 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/base.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc.py index faeb9325f080..bb000e665dea 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc_asyncio.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc_asyncio.py index 35a948eb6e0a..fd3dbd43f58b 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc_asyncio.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -248,6 +248,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/rest.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/rest.py index e8f16213d5a1..b383ecf15b0f 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/rest.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_direct_license_service/transports/rest.py @@ -399,6 +399,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserListDirectLicenseServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/async_client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/async_client.py index 0ed8e0b26a98..b0137fd6e0b7 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/async_client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/async_client.py @@ -227,7 +227,7 @@ def transport(self) -> UserListGlobalLicenseServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/client.py index bea082dd7cf2..0274bbad6dcb 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/client.py @@ -131,7 +131,7 @@ class UserListGlobalLicenseServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -484,7 +488,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -583,7 +587,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -685,7 +689,7 @@ def __init__( self._universe_domain = UserListGlobalLicenseServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/README.rst b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/README.rst index 193546a9dcb1..5ae8b05d3e0e 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/README.rst +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserListGlobalLicenseServiceTransport` is the ABC for all transports. -- public child `UserListGlobalLicenseServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserListGlobalLicenseServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserListGlobalLicenseServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserListGlobalLicenseServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserListGlobalLicenseServiceTransport`` is the ABC for all transports. + +- public child ``UserListGlobalLicenseServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserListGlobalLicenseServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserListGlobalLicenseServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserListGlobalLicenseServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/base.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/base.py index 2ada029e6352..8a1729df4a8c 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/base.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc.py index cee230ee68a5..53618a49a4ac 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc_asyncio.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc_asyncio.py index 7c134240fa40..ce22a5624ed3 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc_asyncio.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -248,6 +248,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/rest.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/rest.py index e738ca4bc801..407781b36c69 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/rest.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_global_license_service/transports/rest.py @@ -462,6 +462,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserListGlobalLicenseServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/async_client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/async_client.py index 21e7813a18ae..743e9c85a978 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/async_client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> UserListServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/client.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/client.py index f077fd331afc..079695630d8e 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/client.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/client.py @@ -113,7 +113,7 @@ class UserListServiceClient(metaclass=UserListServiceClientMeta): """Service for managing UserList resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -438,7 +442,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -535,7 +539,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -633,7 +637,7 @@ def __init__( self._universe_domain = UserListServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/README.rst b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/README.rst index cf4cc6775deb..3de32f646f99 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/README.rst +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserListServiceTransport` is the ABC for all transports. -- public child `UserListServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserListServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserListServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserListServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserListServiceTransport`` is the ABC for all transports. + +- public child ``UserListServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserListServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserListServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserListServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/base.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/base.py index e871741c07c4..800d63a4e824 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/base.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc.py index 04e1383a2c26..8bcead4dd258 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc_asyncio.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc_asyncio.py index 03f17b04a818..65883cf2985c 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc_asyncio.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/rest.py b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/rest.py index 622118b0cc7a..e13cc7948625 100644 --- a/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/rest.py +++ b/packages/google-ads-datamanager/google/ads/datamanager_v1/services/user_list_service/transports/rest.py @@ -389,6 +389,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserListServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-datamanager/noxfile.py b/packages/google-ads-datamanager/noxfile.py index 3f5af66111aa..fcf5ab92e0d5 100644 --- a/packages/google-ads-datamanager/noxfile.py +++ b/packages/google-ads-datamanager/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-ads-datamanager/setup.py b/packages/google-ads-datamanager/setup.py index f9ac94b4eaad..62f688cbfbbc 100644 --- a/packages/google-ads-datamanager/setup.py +++ b/packages/google-ads-datamanager/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-ads-datamanager" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-ads-datamanager/testing/constraints-3.7.txt b/packages/google-ads-datamanager/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-ads-datamanager/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-ads-datamanager/testing/constraints-3.8.txt b/packages/google-ads-datamanager/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-ads-datamanager/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-ads-datamanager/testing/constraints-3.9.txt b/packages/google-ads-datamanager/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-ads-datamanager/testing/constraints-3.9.txt +++ b/packages/google-ads-datamanager/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_ingestion_service.py b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_ingestion_service.py index de9225606b74..f479323be415 100644 --- a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_ingestion_service.py +++ b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_ingestion_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IngestionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -156,6 +157,10 @@ def test__get_default_mtls_endpoint(): IngestionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + IngestionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1325,11 +1330,13 @@ def test_ingestion_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2953,8 +2960,9 @@ def test_ingest_audience_members_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3017,18 +3025,20 @@ def test_ingest_audience_members_rest_interceptors(null_interceptor): ) client = IngestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IngestionServiceRestInterceptor, "post_ingest_audience_members" - ) as post, mock.patch.object( - transports.IngestionServiceRestInterceptor, - "post_ingest_audience_members_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IngestionServiceRestInterceptor, "pre_ingest_audience_members" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "post_ingest_audience_members" + ) as post, + mock.patch.object( + transports.IngestionServiceRestInterceptor, + "post_ingest_audience_members_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "pre_ingest_audience_members" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3086,8 +3096,9 @@ def test_remove_audience_members_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3150,18 +3161,20 @@ def test_remove_audience_members_rest_interceptors(null_interceptor): ) client = IngestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IngestionServiceRestInterceptor, "post_remove_audience_members" - ) as post, mock.patch.object( - transports.IngestionServiceRestInterceptor, - "post_remove_audience_members_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IngestionServiceRestInterceptor, "pre_remove_audience_members" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "post_remove_audience_members" + ) as post, + mock.patch.object( + transports.IngestionServiceRestInterceptor, + "post_remove_audience_members_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "pre_remove_audience_members" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3219,8 +3232,9 @@ def test_ingest_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3283,17 +3297,20 @@ def test_ingest_events_rest_interceptors(null_interceptor): ) client = IngestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IngestionServiceRestInterceptor, "post_ingest_events" - ) as post, mock.patch.object( - transports.IngestionServiceRestInterceptor, "post_ingest_events_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IngestionServiceRestInterceptor, "pre_ingest_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "post_ingest_events" + ) as post, + mock.patch.object( + transports.IngestionServiceRestInterceptor, + "post_ingest_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "pre_ingest_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3351,8 +3368,9 @@ def test_retrieve_request_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3412,18 +3430,20 @@ def test_retrieve_request_status_rest_interceptors(null_interceptor): ) client = IngestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IngestionServiceRestInterceptor, "post_retrieve_request_status" - ) as post, mock.patch.object( - transports.IngestionServiceRestInterceptor, - "post_retrieve_request_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IngestionServiceRestInterceptor, "pre_retrieve_request_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "post_retrieve_request_status" + ) as post, + mock.patch.object( + transports.IngestionServiceRestInterceptor, + "post_retrieve_request_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IngestionServiceRestInterceptor, "pre_retrieve_request_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3619,11 +3639,14 @@ def test_ingestion_service_base_transport(): def test_ingestion_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.datamanager_v1.services.ingestion_service.transports.IngestionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.datamanager_v1.services.ingestion_service.transports.IngestionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IngestionServiceTransport( @@ -3640,9 +3663,12 @@ def test_ingestion_service_base_transport_with_credentials_file(): def test_ingestion_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.datamanager_v1.services.ingestion_service.transports.IngestionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.datamanager_v1.services.ingestion_service.transports.IngestionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IngestionServiceTransport() @@ -3714,11 +3740,12 @@ def test_ingestion_service_transport_auth_gdch_credentials(transport_class): def test_ingestion_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_marketing_data_insights_service.py b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_marketing_data_insights_service.py index 0e6898d79b3b..214d76b83cc6 100644 --- a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_marketing_data_insights_service.py +++ b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_marketing_data_insights_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MarketingDataInsightsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): MarketingDataInsightsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MarketingDataInsightsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1386,11 +1391,13 @@ def test_marketing_data_insights_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1986,8 +1993,9 @@ def test_retrieve_insights_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2047,18 +2055,22 @@ def test_retrieve_insights_rest_interceptors(null_interceptor): ) client = MarketingDataInsightsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingDataInsightsServiceRestInterceptor, "post_retrieve_insights" - ) as post, mock.patch.object( - transports.MarketingDataInsightsServiceRestInterceptor, - "post_retrieve_insights_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingDataInsightsServiceRestInterceptor, "pre_retrieve_insights" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingDataInsightsServiceRestInterceptor, + "post_retrieve_insights", + ) as post, + mock.patch.object( + transports.MarketingDataInsightsServiceRestInterceptor, + "post_retrieve_insights_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingDataInsightsServiceRestInterceptor, + "pre_retrieve_insights", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2185,11 +2197,14 @@ def test_marketing_data_insights_service_base_transport(): def test_marketing_data_insights_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.datamanager_v1.services.marketing_data_insights_service.transports.MarketingDataInsightsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.datamanager_v1.services.marketing_data_insights_service.transports.MarketingDataInsightsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MarketingDataInsightsServiceTransport( @@ -2206,9 +2221,12 @@ def test_marketing_data_insights_service_base_transport_with_credentials_file(): def test_marketing_data_insights_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.datamanager_v1.services.marketing_data_insights_service.transports.MarketingDataInsightsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.datamanager_v1.services.marketing_data_insights_service.transports.MarketingDataInsightsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MarketingDataInsightsServiceTransport() @@ -2287,11 +2305,12 @@ def test_marketing_data_insights_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_partner_link_service.py b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_partner_link_service.py index dd1909628213..17c31d5223c8 100644 --- a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_partner_link_service.py +++ b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_partner_link_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PartnerLinkServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): PartnerLinkServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PartnerLinkServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1322,11 +1327,13 @@ def test_partner_link_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3509,8 +3516,9 @@ def test_create_partner_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3654,18 +3662,20 @@ def test_create_partner_link_rest_interceptors(null_interceptor): ) client = PartnerLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, "post_create_partner_link" - ) as post, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, - "post_create_partner_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, "pre_create_partner_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, "post_create_partner_link" + ) as post, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, + "post_create_partner_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, "pre_create_partner_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3722,8 +3732,9 @@ def test_delete_partner_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3782,13 +3793,13 @@ def test_delete_partner_link_rest_interceptors(null_interceptor): ) client = PartnerLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, "pre_delete_partner_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, "pre_delete_partner_link" + ) as pre, + ): pre.assert_not_called() pb_message = partner_link_service.DeletePartnerLinkRequest.pb( partner_link_service.DeletePartnerLinkRequest() @@ -3833,8 +3844,9 @@ def test_search_partner_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3897,18 +3909,20 @@ def test_search_partner_links_rest_interceptors(null_interceptor): ) client = PartnerLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, "post_search_partner_links" - ) as post, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, - "post_search_partner_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PartnerLinkServiceRestInterceptor, "pre_search_partner_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, "post_search_partner_links" + ) as post, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, + "post_search_partner_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PartnerLinkServiceRestInterceptor, "pre_search_partner_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4083,11 +4097,14 @@ def test_partner_link_service_base_transport(): def test_partner_link_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.datamanager_v1.services.partner_link_service.transports.PartnerLinkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.datamanager_v1.services.partner_link_service.transports.PartnerLinkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PartnerLinkServiceTransport( @@ -4104,9 +4121,12 @@ def test_partner_link_service_base_transport_with_credentials_file(): def test_partner_link_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.datamanager_v1.services.partner_link_service.transports.PartnerLinkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.datamanager_v1.services.partner_link_service.transports.PartnerLinkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PartnerLinkServiceTransport() @@ -4178,11 +4198,12 @@ def test_partner_link_service_transport_auth_gdch_credentials(transport_class): def test_partner_link_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_direct_license_service.py b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_direct_license_service.py index 0dc61e5a6fa4..63118c279145 100644 --- a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_direct_license_service.py +++ b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_direct_license_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserListDirectLicenseServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): UserListDirectLicenseServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserListDirectLicenseServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1399,11 +1404,13 @@ def test_user_list_direct_license_service_client_create_channel_credentials_file ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4417,8 +4424,9 @@ def test_create_user_list_direct_license_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4602,20 +4610,22 @@ def test_create_user_list_direct_license_rest_interceptors(null_interceptor): ) client = UserListDirectLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_create_user_list_direct_license", - ) as post, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_create_user_list_direct_license_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "pre_create_user_list_direct_license", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_create_user_list_direct_license", + ) as post, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_create_user_list_direct_license_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "pre_create_user_list_direct_license", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4677,8 +4687,9 @@ def test_get_user_list_direct_license_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4761,20 +4772,22 @@ def test_get_user_list_direct_license_rest_interceptors(null_interceptor): ) client = UserListDirectLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_get_user_list_direct_license", - ) as post, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_get_user_list_direct_license_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "pre_get_user_list_direct_license", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_get_user_list_direct_license", + ) as post, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_get_user_list_direct_license_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "pre_get_user_list_direct_license", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4838,8 +4851,9 @@ def test_update_user_list_direct_license_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5027,20 +5041,22 @@ def test_update_user_list_direct_license_rest_interceptors(null_interceptor): ) client = UserListDirectLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_update_user_list_direct_license", - ) as post, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_update_user_list_direct_license_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "pre_update_user_list_direct_license", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_update_user_list_direct_license", + ) as post, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_update_user_list_direct_license_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "pre_update_user_list_direct_license", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5100,8 +5116,9 @@ def test_list_user_list_direct_licenses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5170,20 +5187,22 @@ def test_list_user_list_direct_licenses_rest_interceptors(null_interceptor): ) client = UserListDirectLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_list_user_list_direct_licenses", - ) as post, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "post_list_user_list_direct_licenses_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListDirectLicenseServiceRestInterceptor, - "pre_list_user_list_direct_licenses", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_list_user_list_direct_licenses", + ) as post, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "post_list_user_list_direct_licenses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListDirectLicenseServiceRestInterceptor, + "pre_list_user_list_direct_licenses", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5393,11 +5412,14 @@ def test_user_list_direct_license_service_base_transport(): def test_user_list_direct_license_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.datamanager_v1.services.user_list_direct_license_service.transports.UserListDirectLicenseServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.datamanager_v1.services.user_list_direct_license_service.transports.UserListDirectLicenseServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserListDirectLicenseServiceTransport( @@ -5414,9 +5436,12 @@ def test_user_list_direct_license_service_base_transport_with_credentials_file() def test_user_list_direct_license_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.datamanager_v1.services.user_list_direct_license_service.transports.UserListDirectLicenseServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.datamanager_v1.services.user_list_direct_license_service.transports.UserListDirectLicenseServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserListDirectLicenseServiceTransport() @@ -5495,11 +5520,12 @@ def test_user_list_direct_license_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_global_license_service.py b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_global_license_service.py index 18f4e1e2cccf..28e752d32c7f 100644 --- a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_global_license_service.py +++ b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_global_license_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserListGlobalLicenseServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): UserListGlobalLicenseServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserListGlobalLicenseServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1399,11 +1404,13 @@ def test_user_list_global_license_service_client_create_channel_credentials_file ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5306,8 +5313,9 @@ def test_create_user_list_global_license_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5485,20 +5493,22 @@ def test_create_user_list_global_license_rest_interceptors(null_interceptor): ) client = UserListGlobalLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_create_user_list_global_license", - ) as post, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_create_user_list_global_license_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "pre_create_user_list_global_license", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_create_user_list_global_license", + ) as post, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_create_user_list_global_license_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "pre_create_user_list_global_license", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5562,8 +5572,9 @@ def test_update_user_list_global_license_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5745,20 +5756,22 @@ def test_update_user_list_global_license_rest_interceptors(null_interceptor): ) client = UserListGlobalLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_update_user_list_global_license", - ) as post, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_update_user_list_global_license_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "pre_update_user_list_global_license", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_update_user_list_global_license", + ) as post, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_update_user_list_global_license_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "pre_update_user_list_global_license", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5820,8 +5833,9 @@ def test_get_user_list_global_license_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5900,20 +5914,22 @@ def test_get_user_list_global_license_rest_interceptors(null_interceptor): ) client = UserListGlobalLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_get_user_list_global_license", - ) as post, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_get_user_list_global_license_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "pre_get_user_list_global_license", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_get_user_list_global_license", + ) as post, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_get_user_list_global_license_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "pre_get_user_list_global_license", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5973,8 +5989,9 @@ def test_list_user_list_global_licenses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6043,20 +6060,22 @@ def test_list_user_list_global_licenses_rest_interceptors(null_interceptor): ) client = UserListGlobalLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_list_user_list_global_licenses", - ) as post, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_list_user_list_global_licenses_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "pre_list_user_list_global_licenses", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_list_user_list_global_licenses", + ) as post, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_list_user_list_global_licenses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "pre_list_user_list_global_licenses", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6122,8 +6141,9 @@ def test_list_user_list_global_license_customer_infos_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6192,20 +6212,22 @@ def test_list_user_list_global_license_customer_infos_rest_interceptors( ) client = UserListGlobalLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_list_user_list_global_license_customer_infos", - ) as post, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "post_list_user_list_global_license_customer_infos_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserListGlobalLicenseServiceRestInterceptor, - "pre_list_user_list_global_license_customer_infos", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_list_user_list_global_license_customer_infos", + ) as post, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "post_list_user_list_global_license_customer_infos_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListGlobalLicenseServiceRestInterceptor, + "pre_list_user_list_global_license_customer_infos", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6432,11 +6454,14 @@ def test_user_list_global_license_service_base_transport(): def test_user_list_global_license_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.datamanager_v1.services.user_list_global_license_service.transports.UserListGlobalLicenseServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.datamanager_v1.services.user_list_global_license_service.transports.UserListGlobalLicenseServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserListGlobalLicenseServiceTransport( @@ -6453,9 +6478,12 @@ def test_user_list_global_license_service_base_transport_with_credentials_file() def test_user_list_global_license_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.datamanager_v1.services.user_list_global_license_service.transports.UserListGlobalLicenseServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.datamanager_v1.services.user_list_global_license_service.transports.UserListGlobalLicenseServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserListGlobalLicenseServiceTransport() @@ -6534,11 +6562,12 @@ def test_user_list_global_license_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_service.py b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_service.py index 68d14427a2a7..7ba3d88ff3ea 100644 --- a/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_service.py +++ b/packages/google-ads-datamanager/tests/unit/gapic/datamanager_v1/test_user_list_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserListServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( UserListServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserListServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1307,11 +1312,13 @@ def test_user_list_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4671,8 +4678,9 @@ def test_get_user_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4753,17 +4761,20 @@ def test_get_user_list_rest_interceptors(null_interceptor): ) client = UserListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_get_user_list" - ) as post, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_get_user_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UserListServiceRestInterceptor, "pre_get_user_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListServiceRestInterceptor, "post_get_user_list" + ) as post, + mock.patch.object( + transports.UserListServiceRestInterceptor, + "post_get_user_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListServiceRestInterceptor, "pre_get_user_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4816,8 +4827,9 @@ def test_list_user_lists_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4880,17 +4892,20 @@ def test_list_user_lists_rest_interceptors(null_interceptor): ) client = UserListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_list_user_lists" - ) as post, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_list_user_lists_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UserListServiceRestInterceptor, "pre_list_user_lists" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListServiceRestInterceptor, "post_list_user_lists" + ) as post, + mock.patch.object( + transports.UserListServiceRestInterceptor, + "post_list_user_lists_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListServiceRestInterceptor, "pre_list_user_lists" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4948,8 +4963,9 @@ def test_create_user_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5140,17 +5156,20 @@ def test_create_user_list_rest_interceptors(null_interceptor): ) client = UserListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_create_user_list" - ) as post, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_create_user_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UserListServiceRestInterceptor, "pre_create_user_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListServiceRestInterceptor, "post_create_user_list" + ) as post, + mock.patch.object( + transports.UserListServiceRestInterceptor, + "post_create_user_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListServiceRestInterceptor, "pre_create_user_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5205,8 +5224,9 @@ def test_update_user_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5399,17 +5419,20 @@ def test_update_user_list_rest_interceptors(null_interceptor): ) client = UserListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_update_user_list" - ) as post, mock.patch.object( - transports.UserListServiceRestInterceptor, "post_update_user_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UserListServiceRestInterceptor, "pre_update_user_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListServiceRestInterceptor, "post_update_user_list" + ) as post, + mock.patch.object( + transports.UserListServiceRestInterceptor, + "post_update_user_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserListServiceRestInterceptor, "pre_update_user_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5462,8 +5485,9 @@ def test_delete_user_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5520,13 +5544,13 @@ def test_delete_user_list_rest_interceptors(null_interceptor): ) client = UserListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserListServiceRestInterceptor, "pre_delete_user_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserListServiceRestInterceptor, "pre_delete_user_list" + ) as pre, + ): pre.assert_not_called() pb_message = user_list_service.DeleteUserListRequest.pb( user_list_service.DeleteUserListRequest() @@ -5724,11 +5748,14 @@ def test_user_list_service_base_transport(): def test_user_list_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.datamanager_v1.services.user_list_service.transports.UserListServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.datamanager_v1.services.user_list_service.transports.UserListServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserListServiceTransport( @@ -5745,9 +5772,12 @@ def test_user_list_service_base_transport_with_credentials_file(): def test_user_list_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.datamanager_v1.services.user_list_service.transports.UserListServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.datamanager_v1.services.user_list_service.transports.UserListServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserListServiceTransport() @@ -5819,11 +5849,12 @@ def test_user_list_service_transport_auth_gdch_credentials(transport_class): def test_user_list_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/async_client.py b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/async_client.py index 83ad7c16b9f2..73b628b4e6dd 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/async_client.py +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/async_client.py @@ -224,7 +224,7 @@ def transport(self) -> MarketingplatformAdminServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/client.py b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/client.py index 41f284f10fab..c4c384396bc7 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/client.py +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/client.py @@ -120,7 +120,7 @@ class MarketingplatformAdminServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -492,7 +496,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -591,7 +595,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -695,7 +699,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/README.rst b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/README.rst index d39c38a6d6a4..eeb63a6c9e32 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/README.rst +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MarketingplatformAdminServiceTransport` is the ABC for all transports. -- public child `MarketingplatformAdminServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MarketingplatformAdminServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMarketingplatformAdminServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MarketingplatformAdminServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MarketingplatformAdminServiceTransport`` is the ABC for all transports. + +- public child ``MarketingplatformAdminServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MarketingplatformAdminServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMarketingplatformAdminServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MarketingplatformAdminServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/base.py b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/base.py index 4295be260e8c..9ac87ef20e90 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/base.py +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc.py b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc.py index 84563e709161..f04d8b7fecf4 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc.py +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc_asyncio.py b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc_asyncio.py index f498f35f75e3..7885c437fc40 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc_asyncio.py +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/rest.py b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/rest.py index 804df0facb5e..a834e8ec47fa 100644 --- a/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/rest.py +++ b/packages/google-ads-marketingplatform-admin/google/ads/marketingplatform_admin_v1alpha/services/marketingplatform_admin_service/transports/rest.py @@ -585,6 +585,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MarketingplatformAdminServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ads-marketingplatform-admin/noxfile.py b/packages/google-ads-marketingplatform-admin/noxfile.py index 10f63e476e59..39f77e5ce83e 100644 --- a/packages/google-ads-marketingplatform-admin/noxfile.py +++ b/packages/google-ads-marketingplatform-admin/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-ads-marketingplatform-admin/setup.py b/packages/google-ads-marketingplatform-admin/setup.py index d9fce4c6602b..2fc5051f708c 100644 --- a/packages/google-ads-marketingplatform-admin/setup.py +++ b/packages/google-ads-marketingplatform-admin/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-ads-marketingplatform-admin" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-ads-marketingplatform-admin/testing/constraints-3.7.txt b/packages/google-ads-marketingplatform-admin/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-ads-marketingplatform-admin/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-ads-marketingplatform-admin/testing/constraints-3.8.txt b/packages/google-ads-marketingplatform-admin/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-ads-marketingplatform-admin/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-ads-marketingplatform-admin/testing/constraints-3.9.txt b/packages/google-ads-marketingplatform-admin/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-ads-marketingplatform-admin/testing/constraints-3.9.txt +++ b/packages/google-ads-marketingplatform-admin/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-ads-marketingplatform-admin/tests/unit/gapic/marketingplatform_admin_v1alpha/test_marketingplatform_admin_service.py b/packages/google-ads-marketingplatform-admin/tests/unit/gapic/marketingplatform_admin_v1alpha/test_marketingplatform_admin_service.py index d1fd5b2a49f4..f9fd340f0b59 100644 --- a/packages/google-ads-marketingplatform-admin/tests/unit/gapic/marketingplatform_admin_v1alpha/test_marketingplatform_admin_service.py +++ b/packages/google-ads-marketingplatform-admin/tests/unit/gapic/marketingplatform_admin_v1alpha/test_marketingplatform_admin_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MarketingplatformAdminServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): MarketingplatformAdminServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MarketingplatformAdminServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1401,11 +1406,13 @@ def test_marketingplatform_admin_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6343,8 +6350,9 @@ def test_get_organization_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6409,18 +6417,22 @@ def test_get_organization_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, "post_get_organization" - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_get_organization_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, "pre_get_organization" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_get_organization", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_get_organization_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_get_organization", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6473,8 +6485,9 @@ def test_list_organizations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6539,20 +6552,22 @@ def test_list_organizations_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_list_organizations", - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_list_organizations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_list_organizations", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_list_organizations", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_list_organizations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_list_organizations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6610,8 +6625,9 @@ def test_find_sales_partner_managed_clients_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6677,20 +6693,22 @@ def test_find_sales_partner_managed_clients_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_find_sales_partner_managed_clients", - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_find_sales_partner_managed_clients_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_find_sales_partner_managed_clients", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_find_sales_partner_managed_clients", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_find_sales_partner_managed_clients_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_find_sales_partner_managed_clients", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6752,8 +6770,9 @@ def test_list_analytics_account_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6818,20 +6837,22 @@ def test_list_analytics_account_links_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_list_analytics_account_links", - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_list_analytics_account_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_list_analytics_account_links", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_list_analytics_account_links", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_list_analytics_account_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_list_analytics_account_links", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6891,8 +6912,9 @@ def test_create_analytics_account_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7041,20 +7063,22 @@ def test_create_analytics_account_link_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_create_analytics_account_link", - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_create_analytics_account_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_create_analytics_account_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_create_analytics_account_link", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_create_analytics_account_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_create_analytics_account_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7109,8 +7133,9 @@ def test_delete_analytics_account_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7167,14 +7192,14 @@ def test_delete_analytics_account_link_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_delete_analytics_account_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_delete_analytics_account_link", + ) as pre, + ): pre.assert_not_called() pb_message = marketingplatform_admin.DeleteAnalyticsAccountLinkRequest.pb( marketingplatform_admin.DeleteAnalyticsAccountLinkRequest() @@ -7221,8 +7246,9 @@ def test_set_property_service_level_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7286,20 +7312,22 @@ def test_set_property_service_level_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_set_property_service_level", - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_set_property_service_level_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_set_property_service_level", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_set_property_service_level", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_set_property_service_level_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_set_property_service_level", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7357,8 +7385,9 @@ def test_report_property_usage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7420,20 +7449,22 @@ def test_report_property_usage_rest_interceptors(null_interceptor): ) client = MarketingplatformAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_report_property_usage", - ) as post, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "post_report_property_usage_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MarketingplatformAdminServiceRestInterceptor, - "pre_report_property_usage", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_report_property_usage", + ) as post, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "post_report_property_usage_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MarketingplatformAdminServiceRestInterceptor, + "pre_report_property_usage", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7721,11 +7752,14 @@ def test_marketingplatform_admin_service_base_transport(): def test_marketingplatform_admin_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ads.marketingplatform_admin_v1alpha.services.marketingplatform_admin_service.transports.MarketingplatformAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ads.marketingplatform_admin_v1alpha.services.marketingplatform_admin_service.transports.MarketingplatformAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MarketingplatformAdminServiceTransport( @@ -7745,9 +7779,12 @@ def test_marketingplatform_admin_service_base_transport_with_credentials_file(): def test_marketingplatform_admin_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ads.marketingplatform_admin_v1alpha.services.marketingplatform_admin_service.transports.MarketingplatformAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ads.marketingplatform_admin_v1alpha.services.marketingplatform_admin_service.transports.MarketingplatformAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MarketingplatformAdminServiceTransport() @@ -7832,11 +7869,12 @@ def test_marketingplatform_admin_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/async_client.py index f3d7a15e5ff3..5cc5dc7677ba 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> GenerativeServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -993,7 +993,7 @@ async def sample_count_tokens(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1019,8 +1019,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1029,7 +1033,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1037,7 +1041,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1048,7 +1052,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1074,8 +1078,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1084,7 +1092,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1100,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1103,7 +1111,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1133,8 +1141,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1143,7 +1155,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1151,7 +1163,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1159,7 +1171,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1188,8 +1200,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1198,7 +1214,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1206,7 +1222,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/client.py index f8ee1d5f4a0d..fcee54d6674b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/client.py @@ -114,7 +114,7 @@ class GenerativeServiceClient(metaclass=GenerativeServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -629,7 +633,7 @@ def __init__( self._universe_domain = GenerativeServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1414,7 +1418,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1440,8 +1444,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1450,7 +1458,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1459,7 +1467,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1473,7 +1481,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1499,8 +1507,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1509,7 +1521,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1518,7 +1530,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1532,7 +1544,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1562,8 +1574,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1572,7 +1588,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1580,7 +1596,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1588,7 +1604,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1617,8 +1633,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1627,7 +1647,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1635,7 +1655,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/README.rst index b8180cab1e5c..44094958dda4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GenerativeServiceTransport` is the ABC for all transports. -- public child `GenerativeServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GenerativeServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGenerativeServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GenerativeServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GenerativeServiceTransport`` is the ABC for all transports. + +- public child ``GenerativeServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GenerativeServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGenerativeServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GenerativeServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/base.py index 610570f9e334..4fb12be7b23b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc.py index 867236a201ae..4186368a516b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc_asyncio.py index bbfc0cda4ffb..c271966e4b50 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/rest.py index b69bd7d87dce..ab5f988221ea 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/rest.py @@ -538,6 +538,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GenerativeServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/async_client.py index 4b44d409c33b..ac2451e50363 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> ModelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -555,7 +555,7 @@ async def sample_list_models(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -581,8 +581,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -591,7 +595,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -599,7 +603,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -610,7 +614,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -636,8 +640,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -646,7 +654,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -654,7 +662,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -665,7 +673,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -695,8 +703,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -705,7 +717,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -713,7 +725,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -721,7 +733,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -750,8 +762,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -760,7 +776,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -768,7 +784,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/client.py index b165582fcad2..12dfe3e29010 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/client.py @@ -113,7 +113,7 @@ class ModelServiceClient(metaclass=ModelServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -431,7 +435,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -624,7 +628,7 @@ def __init__( self._universe_domain = ModelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -986,7 +990,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1012,8 +1016,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1022,7 +1030,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1031,7 +1039,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1045,7 +1053,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1071,8 +1079,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1081,7 +1093,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1090,7 +1102,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1116,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1146,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1160,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1168,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1160,7 +1176,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1189,8 +1205,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1199,7 +1219,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1207,7 +1227,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/README.rst index 05dddc4c34ad..a3b272dc76a1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelServiceTransport` is the ABC for all transports. -- public child `ModelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelServiceTransport`` is the ABC for all transports. + +- public child ``ModelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/base.py index 70e99fb853b7..1455de0fc3a2 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc.py index 28389c947afa..f44770fcb957 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc_asyncio.py index 55e393855f47..a2da740a5d9b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/rest.py index c7084942d166..c134ea81f84e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/rest.py @@ -351,6 +351,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/async_client.py index 168980eb63f3..e07227b9f31c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> CacheServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -848,7 +848,7 @@ async def sample_delete_cached_content(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -874,8 +874,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -884,7 +888,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -892,7 +896,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -903,7 +907,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -929,8 +933,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -939,7 +947,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -947,7 +955,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/client.py index 1e5037dbb092..3923d7af906d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/client.py @@ -126,7 +126,7 @@ class CacheServiceClient(metaclass=CacheServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -556,7 +560,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -652,7 +656,7 @@ def __init__( self._universe_domain = CacheServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1282,7 +1286,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1312,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1326,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1327,7 +1335,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1341,7 +1349,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1367,8 +1375,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1377,7 +1389,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1386,7 +1398,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/README.rst index 8647ac1a9f9b..22d3dce2bb7a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CacheServiceTransport` is the ABC for all transports. -- public child `CacheServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CacheServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCacheServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CacheServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CacheServiceTransport`` is the ABC for all transports. + +- public child ``CacheServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CacheServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCacheServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CacheServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/base.py index f1cba36ad441..1ccca38ba21b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc.py index be19b0b09c22..eb50e2093e4e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc_asyncio.py index 4c44c9406267..fb09afb62d0a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/rest.py index 7b78e7cee041..34aa67658304 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/cache_service/transports/rest.py @@ -456,6 +456,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CacheServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/async_client.py index ea36ce94a7d6..78e4678d3dcd 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> DiscussServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +628,7 @@ async def sample_count_message_tokens(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -654,8 +654,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -664,7 +668,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -672,7 +676,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -683,7 +687,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -709,8 +713,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -719,7 +727,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -727,7 +735,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/client.py index 80ba135a273b..83b49863fa53 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/client.py @@ -114,7 +114,7 @@ class DiscussServiceClient(metaclass=DiscussServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = DiscussServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1058,7 +1062,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1084,8 +1088,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1094,7 +1102,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1103,7 +1111,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1117,7 +1125,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1143,8 +1151,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1153,7 +1165,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1162,7 +1174,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/README.rst index 864ca745c717..c69346c80445 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiscussServiceTransport` is the ABC for all transports. -- public child `DiscussServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiscussServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiscussServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiscussServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiscussServiceTransport`` is the ABC for all transports. + +- public child ``DiscussServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiscussServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiscussServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiscussServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/base.py index bcfbe14b8aef..ab879e373447 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc.py index 4e9f8671a9e7..e6f1a3e60604 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc_asyncio.py index 2ca51546d8c2..37facf6b30a2 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/rest.py index 8bc496d6e83d..ad87f92ef427 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/discuss_service/transports/rest.py @@ -317,6 +317,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiscussServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/async_client.py index 47136c5f79d8..9dcbac5f802f 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> FileServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -670,7 +670,7 @@ async def sample_delete_file(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -696,8 +696,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -706,7 +710,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -714,7 +718,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -725,7 +729,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -751,8 +755,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -761,7 +769,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -769,7 +777,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/client.py index 69248864b065..29860dc6dd1f 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/client.py @@ -113,7 +113,7 @@ class FileServiceClient(metaclass=FileServiceClientMeta): """An API for uploading and managing files.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -431,7 +435,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -624,7 +628,7 @@ def __init__( self._universe_domain = FileServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1099,7 +1103,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1125,8 +1129,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1135,7 +1143,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1144,7 +1152,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1158,7 +1166,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1184,8 +1192,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1194,7 +1206,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1203,7 +1215,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/README.rst index f61177d3c2c0..51d2036c2ebe 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FileServiceTransport` is the ABC for all transports. -- public child `FileServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FileServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFileServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FileServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FileServiceTransport`` is the ABC for all transports. + +- public child ``FileServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FileServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFileServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FileServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/base.py index fdcb2e36359b..96b306b86915 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc.py index 51aaaac0d30d..96ac94e73631 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc_asyncio.py index b960b757abe4..ee04096ca79e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/rest.py index ad180c33d302..3159ec660f75 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/file_service/transports/rest.py @@ -373,6 +373,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FileServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/async_client.py index 4880851a2ce1..5e2d231191af 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> GenerativeServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1271,7 +1271,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1297,8 +1297,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1307,7 +1311,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1315,7 +1319,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1326,7 +1330,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1352,8 +1356,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1362,7 +1370,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1370,7 +1378,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/client.py index 540ff8acbc8e..fb3769b28c77 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/client.py @@ -119,7 +119,7 @@ class GenerativeServiceClient(metaclass=GenerativeServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -452,7 +456,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -549,7 +553,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = GenerativeServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1698,7 +1702,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1724,8 +1728,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1734,7 +1742,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1743,7 +1751,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1757,7 +1765,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1783,8 +1791,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1793,7 +1805,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1802,7 +1814,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/README.rst index b8180cab1e5c..44094958dda4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GenerativeServiceTransport` is the ABC for all transports. -- public child `GenerativeServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GenerativeServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGenerativeServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GenerativeServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GenerativeServiceTransport`` is the ABC for all transports. + +- public child ``GenerativeServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GenerativeServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGenerativeServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GenerativeServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/base.py index 37178747ac27..51691f431b88 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc.py index 01844baf2a90..b4c3befa73a2 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc_asyncio.py index 4913a0d8e331..2e1379225064 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/rest.py index aca07307507b..3df24a19b6e1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/generative_service/transports/rest.py @@ -552,6 +552,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GenerativeServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/async_client.py index c92a21853623..a9b22c615ee1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> ModelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1165,7 +1165,7 @@ async def sample_delete_tuned_model(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1191,8 +1191,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1201,7 +1205,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1209,7 +1213,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1220,7 +1224,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1246,8 +1250,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1256,7 +1264,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1264,7 +1272,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/client.py index 3ac1b4aaf62e..b6dc3c283a2a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/client.py @@ -118,7 +118,7 @@ class ModelServiceClient(metaclass=ModelServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = ModelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1594,7 +1598,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1620,8 +1624,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1630,7 +1638,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1639,7 +1647,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1653,7 +1661,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1679,8 +1687,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1689,7 +1701,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1698,7 +1710,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/README.rst index 05dddc4c34ad..a3b272dc76a1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelServiceTransport` is the ABC for all transports. -- public child `ModelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelServiceTransport`` is the ABC for all transports. + +- public child ``ModelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/base.py index 4dd5cd28d329..370fc4caff91 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc.py index 0e7ae105d85a..e0b18aeadfbc 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc_asyncio.py index 200c5378ef64..cf8aa8e0c5d1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/rest.py index 211c0db60e06..d17ff44aeeda 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/model_service/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/async_client.py index 004b590d02cc..04ee4532812a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> PermissionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1048,7 +1048,7 @@ async def sample_transfer_ownership(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1074,8 +1074,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1084,7 +1088,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1096,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1103,7 +1107,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1129,8 +1133,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1139,7 +1147,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1147,7 +1155,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/client.py index 8599fa46e1b9..7167751f90eb 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/client.py @@ -115,7 +115,7 @@ class PermissionServiceClient(metaclass=PermissionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = PermissionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1472,7 +1476,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1498,8 +1502,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1508,7 +1516,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1517,7 +1525,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1531,7 +1539,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1557,8 +1565,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1567,7 +1579,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1576,7 +1588,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/README.rst index 240b1d751a3a..3e7a59fc995e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PermissionServiceTransport` is the ABC for all transports. -- public child `PermissionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PermissionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePermissionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PermissionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PermissionServiceTransport`` is the ABC for all transports. + +- public child ``PermissionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PermissionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePermissionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PermissionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/base.py index e32a04cbf2dc..c2e6c1bcc8f3 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc.py index 433187a53863..f54bba1a8d54 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc_asyncio.py index 63f6784464f5..c0f504b36284 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/rest.py index 567bf9b08c5c..af1c074d9891 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/permission_service/transports/rest.py @@ -508,6 +508,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PermissionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/async_client.py index 581ae4a7b901..9193f8a5af2b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> PredictionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -422,7 +422,7 @@ async def sample_predict(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -448,8 +448,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -458,7 +462,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -466,7 +470,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -477,7 +481,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -503,8 +507,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -513,7 +521,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -521,7 +529,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/client.py index 93e177122c25..4c3d6d00a383 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/client.py @@ -111,7 +111,7 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): """A service for online predictions and explanations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -429,7 +433,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -526,7 +530,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( self._universe_domain = PredictionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -858,7 +862,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -884,8 +888,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -894,7 +902,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -903,7 +911,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -917,7 +925,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -943,8 +951,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -953,7 +965,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -962,7 +974,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/README.rst index 504aaca0a144..409d7c7b9f70 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PredictionServiceTransport` is the ABC for all transports. -- public child `PredictionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PredictionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePredictionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PredictionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PredictionServiceTransport`` is the ABC for all transports. + +- public child ``PredictionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PredictionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePredictionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PredictionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/base.py index 84f4719fa1f8..9cc0233b6a1f 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc.py index 4f92c9e383b5..4067e73d7dba 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc_asyncio.py index 6cf47c7823e0..4a98a5429071 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/rest.py index e5b9b9b22e07..088da4548970 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/prediction_service/transports/rest.py @@ -254,6 +254,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PredictionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/async_client.py index a974a0e07227..789f98c952ad 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> RetrieverServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2426,7 +2426,7 @@ async def sample_list_chunks(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2452,8 +2452,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2462,7 +2466,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2470,7 +2474,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2481,7 +2485,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2507,8 +2511,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2517,7 +2525,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2525,7 +2533,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/client.py index b3d91ffaa4ee..4af6fbb9fe28 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/client.py @@ -115,7 +115,7 @@ class RetrieverServiceClient(metaclass=RetrieverServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -667,7 +671,7 @@ def __init__( self._universe_domain = RetrieverServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2844,7 +2848,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2870,8 +2874,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2880,7 +2888,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2889,7 +2897,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2903,7 +2911,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2929,8 +2937,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2939,7 +2951,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2948,7 +2960,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/README.rst index 5f241959ab33..8759cd612c25 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RetrieverServiceTransport` is the ABC for all transports. -- public child `RetrieverServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RetrieverServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRetrieverServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RetrieverServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RetrieverServiceTransport`` is the ABC for all transports. + +- public child ``RetrieverServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RetrieverServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRetrieverServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RetrieverServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/base.py index 7089cd715a22..128c43f4e359 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc.py index 1aad5afee930..a4d6c8660fc8 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc_asyncio.py index 222a1c624fc6..44f583c6446b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/rest.py index 00260c0ebcd4..4e6e7bb5d298 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/retriever_service/transports/rest.py @@ -1167,6 +1167,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RetrieverServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/async_client.py index 684f5e71382a..88fb1bba8d4d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> TextServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -899,7 +899,7 @@ async def sample_count_text_tokens(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -925,8 +925,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -935,7 +939,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -943,7 +947,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -954,7 +958,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -980,8 +984,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -990,7 +998,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -998,7 +1006,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/client.py index ccd9784700e8..8a389c7928a4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/client.py @@ -114,7 +114,7 @@ class TextServiceClient(metaclass=TextServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = TextServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1324,7 +1328,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1350,8 +1354,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1360,7 +1368,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1369,7 +1377,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1383,7 +1391,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1409,8 +1417,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1419,7 +1431,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1428,7 +1440,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/README.rst index b603a3ea7af6..2f6dc3b9c130 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TextServiceTransport` is the ABC for all transports. -- public child `TextServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TextServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTextServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TextServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TextServiceTransport`` is the ABC for all transports. + +- public child ``TextServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TextServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTextServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TextServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/base.py index 95697a1b96c0..37f17546d5ad 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc.py index ae8225915ed7..61a43ca3fa1c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc_asyncio.py index ba59257daf06..6899601220ad 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/rest.py index b4a9f2e561e0..16995e59ab48 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1alpha/services/text_service/transports/rest.py @@ -427,6 +427,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TextServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/async_client.py index 68972b87a6b8..2907d11fba2c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> CacheServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -848,7 +848,7 @@ async def sample_delete_cached_content(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -874,8 +874,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -884,7 +888,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -892,7 +896,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -903,7 +907,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -929,8 +933,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -939,7 +947,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -947,7 +955,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -958,7 +966,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -988,8 +996,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -998,7 +1010,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1006,7 +1018,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1014,7 +1026,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1043,8 +1055,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1053,7 +1069,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1061,7 +1077,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/client.py index 67ec765d0526..8a8cc77c683d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/client.py @@ -126,7 +126,7 @@ class CacheServiceClient(metaclass=CacheServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -556,7 +560,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -652,7 +656,7 @@ def __init__( self._universe_domain = CacheServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1282,7 +1286,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1312,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1326,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1327,7 +1335,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1341,7 +1349,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1367,8 +1375,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1377,7 +1389,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1386,7 +1398,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1400,7 +1412,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1430,8 +1442,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1440,7 +1456,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1448,7 +1464,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1456,7 +1472,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1485,8 +1501,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1495,7 +1515,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1503,7 +1523,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/README.rst index 8647ac1a9f9b..22d3dce2bb7a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CacheServiceTransport` is the ABC for all transports. -- public child `CacheServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CacheServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCacheServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CacheServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CacheServiceTransport`` is the ABC for all transports. + +- public child ``CacheServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CacheServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCacheServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CacheServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/base.py index 716efa9f0b59..830e27e392dd 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc.py index e57fdab3357f..6f079524ed6d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc_asyncio.py index fc504ee02930..fec1febc709f 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/rest.py index bc9bf95f02e6..dd3a66a1e41b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/cache_service/transports/rest.py @@ -502,6 +502,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CacheServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/async_client.py index e5312c72e11d..bc04a0eaa764 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> DiscussServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +628,7 @@ async def sample_count_message_tokens(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -654,8 +654,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -664,7 +668,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -672,7 +676,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -683,7 +687,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -709,8 +713,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -719,7 +727,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -727,7 +735,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -738,7 +746,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -768,8 +776,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -778,7 +790,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -786,7 +798,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -794,7 +806,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -823,8 +835,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -833,7 +849,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -841,7 +857,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/client.py index 0b68cb56cdec..1fc40c7b99fa 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/client.py @@ -114,7 +114,7 @@ class DiscussServiceClient(metaclass=DiscussServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = DiscussServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1058,7 +1062,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1084,8 +1088,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1094,7 +1102,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1103,7 +1111,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1117,7 +1125,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1143,8 +1151,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1153,7 +1165,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1162,7 +1174,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1176,7 +1188,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1206,8 +1218,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1216,7 +1232,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1224,7 +1240,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1232,7 +1248,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1261,8 +1277,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1271,7 +1291,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1279,7 +1299,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/README.rst index 864ca745c717..c69346c80445 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiscussServiceTransport` is the ABC for all transports. -- public child `DiscussServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiscussServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiscussServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiscussServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiscussServiceTransport`` is the ABC for all transports. + +- public child ``DiscussServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiscussServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiscussServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiscussServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/base.py index 1bb7a5000105..9fe304b88d5c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc.py index 8596345cd1d1..6ca3144bba31 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc_asyncio.py index b695c5238cb0..c059d5e96399 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/rest.py index bf6d5458d97d..7e3b71bf3944 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/discuss_service/transports/rest.py @@ -363,6 +363,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiscussServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/async_client.py index 3506cf925eca..5cf7c3b8f5bf 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> FileServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -778,7 +778,7 @@ async def sample_download_file(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -804,8 +804,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -814,7 +818,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -822,7 +826,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -833,7 +837,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -859,8 +863,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -869,7 +877,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -877,7 +885,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -888,7 +896,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -918,8 +926,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -928,7 +940,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -936,7 +948,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -944,7 +956,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -973,8 +985,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -983,7 +999,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -991,7 +1007,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/client.py index b60d8b89cacf..66790470fd71 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/client.py @@ -113,7 +113,7 @@ class FileServiceClient(metaclass=FileServiceClientMeta): """An API for uploading and managing files.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -431,7 +435,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -624,7 +628,7 @@ def __init__( self._universe_domain = FileServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1204,7 +1208,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1230,8 +1234,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1240,7 +1248,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1249,7 +1257,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1263,7 +1271,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1289,8 +1297,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1299,7 +1311,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1308,7 +1320,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1322,7 +1334,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1352,8 +1364,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1362,7 +1378,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1370,7 +1386,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1378,7 +1394,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1407,8 +1423,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1417,7 +1437,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1425,7 +1445,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/README.rst index f61177d3c2c0..51d2036c2ebe 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FileServiceTransport` is the ABC for all transports. -- public child `FileServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FileServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFileServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FileServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FileServiceTransport`` is the ABC for all transports. + +- public child ``FileServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FileServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFileServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FileServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/base.py index 5a640f4263d6..ce46cfa2a530 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc.py index 466314c53dd2..82b781c4591a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc_asyncio.py index ebb43446a383..18d64442d5dd 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/rest.py index eb834e9e42c2..bf5814cf11c5 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/file_service/transports/rest.py @@ -477,6 +477,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FileServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/async_client.py index 5907fb4de758..131d2ff4798b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> GenerativeServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1271,7 +1271,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1297,8 +1297,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1307,7 +1311,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1315,7 +1319,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1326,7 +1330,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1352,8 +1356,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1362,7 +1370,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1370,7 +1378,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1381,7 +1389,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1411,8 +1419,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1421,7 +1433,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1429,7 +1441,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1437,7 +1449,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1466,8 +1478,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1476,7 +1492,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1484,7 +1500,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/client.py index 42e70b35a2e3..13be9f6e1d51 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/client.py @@ -119,7 +119,7 @@ class GenerativeServiceClient(metaclass=GenerativeServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -452,7 +456,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -549,7 +553,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = GenerativeServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1698,7 +1702,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1724,8 +1728,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1734,7 +1742,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1743,7 +1751,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1757,7 +1765,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1783,8 +1791,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1793,7 +1805,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1802,7 +1814,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1816,7 +1828,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1846,8 +1858,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1856,7 +1872,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1864,7 +1880,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1872,7 +1888,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1901,8 +1917,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1911,7 +1931,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1919,7 +1939,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/README.rst index b8180cab1e5c..44094958dda4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GenerativeServiceTransport` is the ABC for all transports. -- public child `GenerativeServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GenerativeServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGenerativeServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GenerativeServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GenerativeServiceTransport`` is the ABC for all transports. + +- public child ``GenerativeServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GenerativeServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGenerativeServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GenerativeServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/base.py index fe97259b4ea1..6d23e02b7d53 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc.py index b2f27e3e6867..dc06aaad8593 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc_asyncio.py index 296cbd7a25b7..e0c5da5e555a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py index 495d090e0bd1..137dcd980377 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py @@ -598,6 +598,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GenerativeServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/async_client.py index e193eebe7490..327d776eafb5 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> ModelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1165,7 +1165,7 @@ async def sample_delete_tuned_model(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1191,8 +1191,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1201,7 +1205,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1209,7 +1213,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1220,7 +1224,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1246,8 +1250,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1256,7 +1264,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1264,7 +1272,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1275,7 +1283,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1305,8 +1313,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1315,7 +1327,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1323,7 +1335,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1331,7 +1343,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1360,8 +1372,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1370,7 +1386,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1378,7 +1394,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/client.py index 0214f443f01f..ea4dc2a41c53 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/client.py @@ -118,7 +118,7 @@ class ModelServiceClient(metaclass=ModelServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = ModelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1594,7 +1598,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1620,8 +1624,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1630,7 +1638,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1639,7 +1647,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1653,7 +1661,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1679,8 +1687,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1689,7 +1701,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1698,7 +1710,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1712,7 +1724,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1742,8 +1754,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1752,7 +1768,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1760,7 +1776,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1768,7 +1784,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1797,8 +1813,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1807,7 +1827,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1815,7 +1835,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/README.rst index 05dddc4c34ad..a3b272dc76a1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelServiceTransport` is the ABC for all transports. -- public child `ModelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelServiceTransport`` is the ABC for all transports. + +- public child ``ModelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/base.py index bd3a40263803..8451ec7078cd 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc.py index 4ec8f4e8d2a2..3c1f8f86694f 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc_asyncio.py index 3eba6c7a5a27..5ad582d09abc 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/rest.py index 7b6a568a88e3..2a7e3a42b005 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/model_service/transports/rest.py @@ -597,6 +597,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/async_client.py index 20ad604ff73e..3f8d93112171 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> PermissionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1048,7 +1048,7 @@ async def sample_transfer_ownership(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1074,8 +1074,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1084,7 +1088,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1096,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1103,7 +1107,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1129,8 +1133,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1139,7 +1147,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1147,7 +1155,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1158,7 +1166,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1188,8 +1196,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1198,7 +1210,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1206,7 +1218,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1214,7 +1226,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1243,8 +1255,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1253,7 +1269,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1261,7 +1277,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/client.py index 02c98a0fa3f4..e4ca35e12764 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/client.py @@ -115,7 +115,7 @@ class PermissionServiceClient(metaclass=PermissionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = PermissionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1472,7 +1476,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1498,8 +1502,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1508,7 +1516,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1517,7 +1525,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1531,7 +1539,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1557,8 +1565,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1567,7 +1579,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1576,7 +1588,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1590,7 +1602,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1620,8 +1632,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1630,7 +1646,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1638,7 +1654,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1646,7 +1662,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1675,8 +1691,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1685,7 +1705,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1693,7 +1713,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/README.rst index 240b1d751a3a..3e7a59fc995e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PermissionServiceTransport` is the ABC for all transports. -- public child `PermissionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PermissionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePermissionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PermissionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PermissionServiceTransport`` is the ABC for all transports. + +- public child ``PermissionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PermissionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePermissionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PermissionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/base.py index e61c1f04da79..224f61cd54e4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc.py index 2b1eab39784d..e065b1132967 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc_asyncio.py index e0704ff31d27..437a61627d28 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest.py index f3613b84d1e0..54452c2796e4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/permission_service/transports/rest.py @@ -554,6 +554,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PermissionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/async_client.py index 87e32776ce84..bf33912d6e9b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> PredictionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -567,7 +567,7 @@ async def sample_predict_long_running(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -593,8 +593,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -603,7 +607,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -611,7 +615,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -622,7 +626,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -648,8 +652,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -658,7 +666,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -666,7 +674,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -677,7 +685,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -707,8 +715,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -717,7 +729,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -725,7 +737,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -733,7 +745,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -762,8 +774,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -772,7 +788,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -780,7 +796,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/client.py index 6a82f24d5410..aac0455d64c0 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/client.py @@ -113,7 +113,7 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): """A service for online predictions and explanations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -431,7 +435,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = PredictionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1000,7 +1004,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1026,8 +1030,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1036,7 +1044,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1053,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1059,7 +1067,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1085,8 +1093,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1095,7 +1107,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1104,7 +1116,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1118,7 +1130,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1160,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1174,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1166,7 +1182,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1174,7 +1190,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1203,8 +1219,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1213,7 +1233,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1221,7 +1241,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/README.rst index 504aaca0a144..409d7c7b9f70 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PredictionServiceTransport` is the ABC for all transports. -- public child `PredictionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PredictionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePredictionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PredictionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PredictionServiceTransport`` is the ABC for all transports. + +- public child ``PredictionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PredictionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePredictionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PredictionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/base.py index c32c8839253c..d2951662b39c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc.py index 8cd823435934..00d2c6cac9f4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc_asyncio.py index 9e5ec35ee622..f635bb1318f6 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/rest.py index 194380b6a3ee..fdf6eddae842 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/prediction_service/transports/rest.py @@ -357,6 +357,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PredictionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/async_client.py index 4dd9bf793817..ab3187277703 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> RetrieverServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2426,7 +2426,7 @@ async def sample_list_chunks(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2452,8 +2452,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2462,7 +2466,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2470,7 +2474,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2481,7 +2485,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2507,8 +2511,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2517,7 +2525,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2525,7 +2533,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2536,7 +2544,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2566,8 +2574,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2576,7 +2588,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2584,7 +2596,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2592,7 +2604,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2621,8 +2633,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2631,7 +2647,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2639,7 +2655,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/client.py index 75997e6b6d77..e855b581b075 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/client.py @@ -115,7 +115,7 @@ class RetrieverServiceClient(metaclass=RetrieverServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -667,7 +671,7 @@ def __init__( self._universe_domain = RetrieverServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2844,7 +2848,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2870,8 +2874,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2880,7 +2888,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2889,7 +2897,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2903,7 +2911,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2929,8 +2937,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2939,7 +2951,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2948,7 +2960,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2962,7 +2974,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2992,8 +3004,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3002,7 +3018,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3010,7 +3026,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3018,7 +3034,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3047,8 +3063,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3057,7 +3077,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3065,7 +3085,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/README.rst index 5f241959ab33..8759cd612c25 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RetrieverServiceTransport` is the ABC for all transports. -- public child `RetrieverServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RetrieverServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRetrieverServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RetrieverServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RetrieverServiceTransport`` is the ABC for all transports. + +- public child ``RetrieverServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RetrieverServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRetrieverServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RetrieverServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/base.py index efdc1b5af711..d764e5fe7599 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc.py index 5cd2b62688c6..3a89ecbaea00 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc_asyncio.py index b415fc3b10c8..749a005d562e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/rest.py index 6ce456b39f06..0b616a110dd4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/retriever_service/transports/rest.py @@ -1213,6 +1213,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RetrieverServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/async_client.py index 295fab4c4e01..26573039aa7a 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> TextServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -899,7 +899,7 @@ async def sample_count_text_tokens(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -925,8 +925,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -935,7 +939,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -943,7 +947,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -954,7 +958,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -980,8 +984,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -990,7 +998,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -998,7 +1006,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1009,7 +1017,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,8 +1047,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1049,7 +1061,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1057,7 +1069,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1065,7 +1077,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1094,8 +1106,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1104,7 +1120,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1112,7 +1128,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/client.py index b48f642e2bbc..f7f1fcdae98d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/client.py @@ -114,7 +114,7 @@ class TextServiceClient(metaclass=TextServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = TextServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1324,7 +1328,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1350,8 +1354,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1360,7 +1368,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1369,7 +1377,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1383,7 +1391,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1409,8 +1417,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1419,7 +1431,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1428,7 +1440,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1442,7 +1454,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1472,8 +1484,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1482,7 +1498,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1490,7 +1506,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1498,7 +1514,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1527,8 +1543,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1537,7 +1557,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1545,7 +1565,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/README.rst index b603a3ea7af6..2f6dc3b9c130 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TextServiceTransport` is the ABC for all transports. -- public child `TextServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TextServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTextServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TextServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TextServiceTransport`` is the ABC for all transports. + +- public child ``TextServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TextServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTextServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TextServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/base.py index d08863e417d5..9a8fdfb08a02 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc.py index 8245b1aeb150..dd1c686a4ce0 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc_asyncio.py index 38c85cd02c91..797aa8e42696 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/rest.py index 9a81ebabd11e..0fd9c04de07c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/text_service/transports/rest.py @@ -473,6 +473,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TextServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/async_client.py index 1b338cb83f47..0bc4c51ecc3e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> DiscussServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/client.py index ab791843580d..92118df0d809 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/client.py @@ -112,7 +112,7 @@ class DiscussServiceClient(metaclass=DiscussServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -430,7 +434,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -527,7 +531,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( self._universe_domain = DiscussServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/README.rst index 864ca745c717..c69346c80445 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiscussServiceTransport` is the ABC for all transports. -- public child `DiscussServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiscussServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiscussServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiscussServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiscussServiceTransport`` is the ABC for all transports. + +- public child ``DiscussServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiscussServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiscussServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiscussServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/base.py index 530febbe252b..d2f5e66b59c4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc.py index 93cff3a6d79b..6f518bec2037 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc_asyncio.py index 41ab9fbdda60..17fc7542ca5c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/rest.py index e18f5054faac..63a1bc56f6f9 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/discuss_service/transports/rest.py @@ -266,6 +266,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiscussServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/async_client.py index f889fb6981a2..6ea5a012bc3c 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> ModelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/client.py index 4332aefa9df4..d5d6c2623354 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/client.py @@ -111,7 +111,7 @@ class ModelServiceClient(metaclass=ModelServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -429,7 +433,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -526,7 +530,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -622,7 +626,7 @@ def __init__( self._universe_domain = ModelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/README.rst index 05dddc4c34ad..a3b272dc76a1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelServiceTransport` is the ABC for all transports. -- public child `ModelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelServiceTransport`` is the ABC for all transports. + +- public child ``ModelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/base.py index 06344c5dcd6d..3a073439f13e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc.py index 325a39d32e3f..b4aaab46367b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc_asyncio.py index ac226a68b386..1345b7206221 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/rest.py index a0f437080112..4fb145abc1a9 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/model_service/transports/rest.py @@ -254,6 +254,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/async_client.py index d00cc46ef4b7..7de088872bdf 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> TextServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/client.py index 23a4ff286dd6..1b733657bb31 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/client.py @@ -112,7 +112,7 @@ class TextServiceClient(metaclass=TextServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -430,7 +434,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -527,7 +531,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( self._universe_domain = TextServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/README.rst index b603a3ea7af6..2f6dc3b9c130 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TextServiceTransport` is the ABC for all transports. -- public child `TextServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TextServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTextServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TextServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TextServiceTransport`` is the ABC for all transports. + +- public child ``TextServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TextServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTextServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TextServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/base.py index 16df0db788f7..52e55a770e15 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc.py index 611f5c9c60fd..8e18a401ad8b 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc_asyncio.py index 435c8ac5704e..0eb91dd7b1e5 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/rest.py index 9d70acf94493..fa664f5c23c3 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/services/text_service/transports/rest.py @@ -260,6 +260,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TextServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/async_client.py index bef9537b4697..af322a73fbf7 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> DiscussServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/client.py index aa509b517a37..d1337318b535 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/client.py @@ -114,7 +114,7 @@ class DiscussServiceClient(metaclass=DiscussServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = DiscussServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/README.rst index 864ca745c717..c69346c80445 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiscussServiceTransport` is the ABC for all transports. -- public child `DiscussServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiscussServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiscussServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiscussServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiscussServiceTransport`` is the ABC for all transports. + +- public child ``DiscussServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiscussServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiscussServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiscussServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/base.py index f14b332a99b9..76edcf49d2d2 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc.py index a8bdd4769596..b3b37664746d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc_asyncio.py index c76a94ddd24d..b1a426ed2fb7 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/rest.py index 9504bcdebc69..f639fefa6831 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/discuss_service/transports/rest.py @@ -267,6 +267,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiscussServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/async_client.py index 9b856bf0c682..99db63049e76 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> ModelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/client.py index ed773fce5ac1..b6c9e7c3a782 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/client.py @@ -118,7 +118,7 @@ class ModelServiceClient(metaclass=ModelServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = ModelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/README.rst index 05dddc4c34ad..a3b272dc76a1 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelServiceTransport` is the ABC for all transports. -- public child `ModelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelServiceTransport`` is the ABC for all transports. + +- public child ``ModelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/base.py index 6ef356a34621..20925cad1c20 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc.py index e49af013eaf4..84a974ab217e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc_asyncio.py index 11a32d9be3ea..2e0352fbd9bc 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/rest.py index 8b027efd2d79..804129c1d5cd 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/model_service/transports/rest.py @@ -501,6 +501,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/async_client.py index 0d68b338eab2..3faeac0b674d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> PermissionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/client.py index 6846669fd6a6..fb82a286952d 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/client.py @@ -115,7 +115,7 @@ class PermissionServiceClient(metaclass=PermissionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -452,7 +456,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -549,7 +553,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = PermissionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/README.rst index 240b1d751a3a..3e7a59fc995e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PermissionServiceTransport` is the ABC for all transports. -- public child `PermissionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PermissionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePermissionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PermissionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PermissionServiceTransport`` is the ABC for all transports. + +- public child ``PermissionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PermissionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePermissionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PermissionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/base.py index c8228fadc62d..e86ec258002e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc.py index f70285a5d771..449e2d60f352 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc_asyncio.py index 7ff85d5b5d9e..2e561d8e5fa9 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/rest.py index fd99536d04c5..f0979a9fb776 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/rest.py @@ -458,6 +458,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PermissionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/async_client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/async_client.py index 54be965458bb..d6b97ca1b718 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/async_client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> TextServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/client.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/client.py index d7e4ca371739..8693cec1ec37 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/client.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/client.py @@ -114,7 +114,7 @@ class TextServiceClient(metaclass=TextServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = TextServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/README.rst b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/README.rst index b603a3ea7af6..2f6dc3b9c130 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/README.rst +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TextServiceTransport` is the ABC for all transports. -- public child `TextServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TextServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTextServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TextServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TextServiceTransport`` is the ABC for all transports. + +- public child ``TextServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TextServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTextServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TextServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/base.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/base.py index 497818e64f18..273ab98d1be4 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/base.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc.py index 0fa951da40d7..1181dac56e1f 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc_asyncio.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc_asyncio.py index 0498a7d920c9..b93ba20abc9e 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc_asyncio.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/rest.py b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/rest.py index 1e27fefbb8e7..34717d717219 100644 --- a/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/rest.py +++ b/packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/text_service/transports/rest.py @@ -377,6 +377,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TextServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-ai-generativelanguage/noxfile.py b/packages/google-ai-generativelanguage/noxfile.py index 0e2515a56157..ac0a6550226f 100644 --- a/packages/google-ai-generativelanguage/noxfile.py +++ b/packages/google-ai-generativelanguage/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-ai-generativelanguage/setup.py b/packages/google-ai-generativelanguage/setup.py index 92a51c68ea45..a774228d04ae 100644 --- a/packages/google-ai-generativelanguage/setup.py +++ b/packages/google-ai-generativelanguage/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-ai-generativelanguage" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-ai-generativelanguage/testing/constraints-3.7.txt b/packages/google-ai-generativelanguage/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-ai-generativelanguage/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-ai-generativelanguage/testing/constraints-3.8.txt b/packages/google-ai-generativelanguage/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-ai-generativelanguage/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-ai-generativelanguage/testing/constraints-3.9.txt b/packages/google-ai-generativelanguage/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-ai-generativelanguage/testing/constraints-3.9.txt +++ b/packages/google-ai-generativelanguage/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_generative_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_generative_service.py index 508bb2eb25af..13a17d941f03 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_generative_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_generative_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GenerativeServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): GenerativeServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GenerativeServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1321,11 +1326,13 @@ def test_generative_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4374,8 +4381,9 @@ def test_generate_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4440,18 +4448,20 @@ def test_generate_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_generate_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_generate_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_generate_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_generate_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_generate_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_generate_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4509,8 +4519,9 @@ def test_stream_generate_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4579,18 +4590,20 @@ def test_stream_generate_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_stream_generate_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_stream_generate_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_stream_generate_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_stream_generate_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_stream_generate_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_stream_generate_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4648,8 +4661,9 @@ def test_embed_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4709,17 +4723,20 @@ def test_embed_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_embed_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_embed_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_embed_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_embed_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_embed_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_embed_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4777,8 +4794,9 @@ def test_batch_embed_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4838,18 +4856,20 @@ def test_batch_embed_contents_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_batch_embed_contents" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_batch_embed_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_batch_embed_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_batch_embed_contents" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_batch_embed_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_batch_embed_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4907,8 +4927,9 @@ def test_count_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4971,17 +4992,20 @@ def test_count_tokens_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_count_tokens" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_count_tokens_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_count_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_count_tokens" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_count_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_count_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5041,8 +5065,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5101,8 +5126,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "operations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5163,8 +5189,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5223,8 +5250,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "operations"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5444,11 +5472,14 @@ def test_generative_service_base_transport(): def test_generative_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GenerativeServiceTransport( @@ -5465,9 +5496,12 @@ def test_generative_service_base_transport_with_credentials_file(): def test_generative_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GenerativeServiceTransport() @@ -5539,11 +5573,12 @@ def test_generative_service_transport_auth_gdch_credentials(transport_class): def test_generative_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6112,6 +6147,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6251,6 +6318,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6396,6 +6495,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6541,6 +6674,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_model_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_model_service.py index 1de82c13cb07..6ecbf3f869f2 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_model_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1/test_model_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1258,11 +1263,13 @@ def test_model_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2687,8 +2694,9 @@ def test_get_model_rest_bad_request(request_type=model_service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2777,17 +2785,19 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2836,8 +2846,9 @@ def test_list_models_rest_bad_request(request_type=model_service.ListModelsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2900,17 +2911,19 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2967,8 +2980,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3027,8 +3041,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "operations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3089,8 +3104,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3149,8 +3165,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "operations"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3303,11 +3320,14 @@ def test_model_service_base_transport(): def test_model_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport( @@ -3324,9 +3344,12 @@ def test_model_service_base_transport_with_credentials_file(): def test_model_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport() @@ -3398,11 +3421,12 @@ def test_model_service_transport_auth_gdch_credentials(transport_class): def test_model_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3951,6 +3975,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4090,6 +4146,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4235,6 +4323,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4380,6 +4502,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_cache_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_cache_service.py index 2e66189615c3..2fa32e018230 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_cache_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_cache_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CacheServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CacheServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CacheServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1269,11 +1274,13 @@ def test_cache_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4255,8 +4262,9 @@ def test_list_cached_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4319,18 +4327,20 @@ def test_list_cached_contents_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_list_cached_contents" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, - "post_list_cached_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_list_cached_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_list_cached_contents" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_list_cached_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_list_cached_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4388,8 +4398,9 @@ def test_create_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4599,18 +4610,20 @@ def test_create_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_create_cached_content" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, - "post_create_cached_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_create_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_create_cached_content" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_create_cached_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_create_cached_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4665,8 +4678,9 @@ def test_get_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4733,17 +4747,20 @@ def test_get_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_get_cached_content" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_get_cached_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_get_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_get_cached_content" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_get_cached_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_get_cached_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4798,8 +4815,9 @@ def test_update_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5009,18 +5027,20 @@ def test_update_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_update_cached_content" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, - "post_update_cached_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_update_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_update_cached_content" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_update_cached_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_update_cached_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5075,8 +5095,9 @@ def test_delete_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5133,13 +5154,13 @@ def test_delete_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_delete_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_delete_cached_content" + ) as pre, + ): pre.assert_not_called() pb_message = cache_service.DeleteCachedContentRequest.pb( cache_service.DeleteCachedContentRequest() @@ -5186,8 +5207,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5246,8 +5268,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5471,11 +5494,14 @@ def test_cache_service_base_transport(): def test_cache_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CacheServiceTransport( @@ -5492,9 +5518,12 @@ def test_cache_service_base_transport_with_credentials_file(): def test_cache_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CacheServiceTransport() @@ -5566,11 +5595,12 @@ def test_cache_service_transport_auth_gdch_credentials(transport_class): def test_cache_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6154,6 +6184,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CacheServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CacheServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CacheServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6299,6 +6363,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CacheServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CacheServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CacheServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_discuss_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_discuss_service.py index 558edeb17103..56c41b83c435 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_discuss_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_discuss_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiscussServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( DiscussServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DiscussServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1280,11 +1285,13 @@ def test_discuss_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2645,8 +2652,9 @@ def test_generate_message_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2706,17 +2714,20 @@ def test_generate_message_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_generate_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_generate_message" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_generate_message_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_generate_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2774,8 +2785,9 @@ def test_count_message_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2838,18 +2850,20 @@ def test_count_message_tokens_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_count_message_tokens" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, - "post_count_message_tokens_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_count_message_tokens" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_count_message_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2909,8 +2923,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2969,8 +2984,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3123,11 +3139,14 @@ def test_discuss_service_base_transport(): def test_discuss_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport( @@ -3144,9 +3163,12 @@ def test_discuss_service_base_transport_with_credentials_file(): def test_discuss_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport() @@ -3218,11 +3240,12 @@ def test_discuss_service_transport_auth_gdch_credentials(transport_class): def test_discuss_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3788,6 +3811,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DiscussServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DiscussServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DiscussServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3933,6 +3990,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DiscussServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DiscussServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DiscussServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_file_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_file_service.py index 9fc5704aecb3..0247ae3f6510 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_file_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_file_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FileServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FileServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FileServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1248,11 +1252,13 @@ def test_file_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3269,8 +3275,9 @@ def test_create_file_rest_bad_request(request_type=file_service.CreateFileReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3330,17 +3337,19 @@ def test_create_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_create_file" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_create_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_create_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_create_file" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_create_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_create_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3391,8 +3400,9 @@ def test_list_files_rest_bad_request(request_type=file_service.ListFilesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3455,17 +3465,19 @@ def test_list_files_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_list_files" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_list_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_list_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_list_files" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_list_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_list_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3516,8 +3528,9 @@ def test_get_file_rest_bad_request(request_type=file_service.GetFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3592,17 +3605,17 @@ def test_get_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_get_file" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_get_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_get_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_get_file" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_get_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FileServiceRestInterceptor, "pre_get_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3651,8 +3664,9 @@ def test_delete_file_rest_bad_request(request_type=file_service.DeleteFileReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3709,13 +3723,13 @@ def test_delete_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_delete_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_delete_file" + ) as pre, + ): pre.assert_not_called() pb_message = file_service.DeleteFileRequest.pb(file_service.DeleteFileRequest()) transcode.return_value = { @@ -3760,8 +3774,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3820,8 +3835,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4014,11 +4030,14 @@ def test_file_service_base_transport(): def test_file_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FileServiceTransport( @@ -4035,9 +4054,12 @@ def test_file_service_base_transport_with_credentials_file(): def test_file_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FileServiceTransport() @@ -4109,11 +4131,12 @@ def test_file_service_transport_auth_gdch_credentials(transport_class): def test_file_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4674,6 +4697,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FileServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FileServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FileServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4819,6 +4876,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FileServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FileServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = FileServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_generative_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_generative_service.py index 4604310e9dd7..49bce364f519 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_generative_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_generative_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GenerativeServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): GenerativeServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GenerativeServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1325,11 +1330,13 @@ def test_generative_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5192,8 +5199,9 @@ def test_generate_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5256,18 +5264,20 @@ def test_generate_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_generate_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_generate_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_generate_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_generate_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_generate_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_generate_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5325,8 +5335,9 @@ def test_generate_answer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5389,18 +5400,20 @@ def test_generate_answer_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_generate_answer" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_generate_answer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_generate_answer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_generate_answer" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_generate_answer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_generate_answer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5458,8 +5471,9 @@ def test_stream_generate_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5526,18 +5540,20 @@ def test_stream_generate_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_stream_generate_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_stream_generate_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_stream_generate_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_stream_generate_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_stream_generate_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_stream_generate_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5595,8 +5611,9 @@ def test_embed_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5656,17 +5673,20 @@ def test_embed_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_embed_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_embed_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_embed_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_embed_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_embed_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_embed_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5724,8 +5744,9 @@ def test_batch_embed_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5785,18 +5806,20 @@ def test_batch_embed_contents_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_batch_embed_contents" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_batch_embed_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_batch_embed_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_batch_embed_contents" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_batch_embed_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_batch_embed_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5854,8 +5877,9 @@ def test_count_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5920,17 +5944,20 @@ def test_count_tokens_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_count_tokens" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_count_tokens_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_count_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_count_tokens" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_count_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_count_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6002,8 +6029,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6062,8 +6090,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6303,11 +6332,14 @@ def test_generative_service_base_transport(): def test_generative_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GenerativeServiceTransport( @@ -6324,9 +6356,12 @@ def test_generative_service_base_transport_with_credentials_file(): def test_generative_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GenerativeServiceTransport() @@ -6398,11 +6433,12 @@ def test_generative_service_transport_auth_gdch_credentials(transport_class): def test_generative_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7003,6 +7039,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7148,6 +7218,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_model_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_model_service.py index bc921b8ff0fd..96340b8e9a43 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_model_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_model_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1265,11 +1270,13 @@ def test_model_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5721,8 +5728,9 @@ def test_get_model_rest_bad_request(request_type=model_service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5809,17 +5817,19 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5868,8 +5878,9 @@ def test_list_models_rest_bad_request(request_type=model_service.ListModelsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5932,17 +5943,19 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5997,8 +6010,9 @@ def test_get_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6076,17 +6090,19 @@ def test_get_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_tuned_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6139,8 +6155,9 @@ def test_list_tuned_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6203,17 +6220,20 @@ def test_list_tuned_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_tuned_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_tuned_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_tuned_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_tuned_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_list_tuned_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_tuned_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6271,8 +6291,9 @@ def test_create_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6442,19 +6463,21 @@ def test_create_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ModelServiceRestInterceptor, "post_create_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_create_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_create_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_create_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_create_tuned_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_create_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6507,8 +6530,9 @@ def test_update_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6699,17 +6723,20 @@ def test_update_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_update_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_update_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_update_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_update_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_update_tuned_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_update_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6762,8 +6789,9 @@ def test_delete_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6820,13 +6848,13 @@ def test_delete_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_delete_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_delete_tuned_model" + ) as pre, + ): pre.assert_not_called() pb_message = model_service.DeleteTunedModelRequest.pb( model_service.DeleteTunedModelRequest() @@ -6873,8 +6901,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6933,8 +6962,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7220,11 +7250,14 @@ def test_model_service_base_transport(): def test_model_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport( @@ -7241,9 +7274,12 @@ def test_model_service_base_transport_with_credentials_file(): def test_model_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport() @@ -7315,11 +7351,12 @@ def test_model_service_transport_auth_gdch_credentials(transport_class): def test_model_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7943,6 +7980,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8088,6 +8159,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_permission_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_permission_service.py index 3aaec88a694f..12f3cdf64edf 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_permission_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_permission_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PermissionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): PermissionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PermissionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1321,11 +1326,13 @@ def test_permission_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5075,8 +5082,9 @@ def test_create_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5218,18 +5226,20 @@ def test_create_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_create_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_create_permission_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_create_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_create_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_create_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_create_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5282,8 +5292,9 @@ def test_get_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5352,17 +5363,20 @@ def test_get_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_get_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_get_permission_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_get_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_get_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_get_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_get_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5415,8 +5429,9 @@ def test_list_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5479,18 +5494,20 @@ def test_list_permissions_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_list_permissions" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_list_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_list_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_list_permissions" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_list_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_list_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5548,8 +5565,9 @@ def test_update_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5691,18 +5709,20 @@ def test_update_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_update_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_update_permission_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_update_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_update_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_update_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_update_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5755,8 +5775,9 @@ def test_delete_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5813,13 +5834,13 @@ def test_delete_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_delete_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_delete_permission" + ) as pre, + ): pre.assert_not_called() pb_message = permission_service.DeletePermissionRequest.pb( permission_service.DeletePermissionRequest() @@ -5864,8 +5885,9 @@ def test_transfer_ownership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5925,18 +5947,20 @@ def test_transfer_ownership_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_transfer_ownership" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_transfer_ownership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_transfer_ownership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_transfer_ownership" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_transfer_ownership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_transfer_ownership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5996,8 +6020,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6056,8 +6081,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6300,11 +6326,14 @@ def test_permission_service_base_transport(): def test_permission_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PermissionServiceTransport( @@ -6321,9 +6350,12 @@ def test_permission_service_base_transport_with_credentials_file(): def test_permission_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PermissionServiceTransport() @@ -6395,11 +6427,12 @@ def test_permission_service_transport_auth_gdch_credentials(transport_class): def test_permission_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6980,6 +7013,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PermissionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PermissionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PermissionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7125,6 +7192,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PermissionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PermissionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = PermissionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_prediction_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_prediction_service.py index 7fd1352a41e8..b0d42668133d 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_prediction_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_prediction_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PredictionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PredictionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PredictionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1319,11 +1324,13 @@ def test_prediction_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2037,8 +2044,9 @@ def test_predict_rest_bad_request(request_type=prediction_service.PredictRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2098,17 +2106,19 @@ def test_predict_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_predict" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_predict" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2165,8 +2175,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2225,8 +2236,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2356,11 +2368,14 @@ def test_prediction_service_base_transport(): def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( @@ -2377,9 +2392,12 @@ def test_prediction_service_base_transport_with_credentials_file(): def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport() @@ -2451,11 +2469,12 @@ def test_prediction_service_transport_auth_gdch_credentials(transport_class): def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3018,6 +3037,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3163,6 +3216,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_retriever_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_retriever_service.py index e3ab147ca6ce..7d065510ef57 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_retriever_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_retriever_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RetrieverServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RetrieverServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RetrieverServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1313,11 +1318,13 @@ def test_retriever_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12257,8 +12264,9 @@ def test_create_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12396,17 +12404,20 @@ def test_create_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_create_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_create_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_create_corpus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_create_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12457,8 +12468,9 @@ def test_get_corpus_rest_bad_request(request_type=retriever_service.GetCorpusReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12523,17 +12535,19 @@ def test_get_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_get_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_corpus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_get_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12586,8 +12600,9 @@ def test_update_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12725,17 +12740,20 @@ def test_update_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_update_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_update_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_update_corpus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_update_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12788,8 +12806,9 @@ def test_delete_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12846,13 +12865,13 @@ def test_delete_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_delete_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_delete_corpus" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.DeleteCorpusRequest.pb( retriever_service.DeleteCorpusRequest() @@ -12897,8 +12916,9 @@ def test_list_corpora_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12961,17 +12981,20 @@ def test_list_corpora_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_corpora" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_corpora_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_list_corpora" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_corpora" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_list_corpora_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_list_corpora" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13029,8 +13052,9 @@ def test_query_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13090,17 +13114,20 @@ def test_query_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_query_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_query_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_query_corpus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_query_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13158,8 +13185,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13305,17 +13333,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_create_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13368,8 +13399,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13434,17 +13466,20 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_get_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13497,8 +13532,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13644,17 +13680,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_update_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13707,8 +13746,9 @@ def test_delete_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13765,13 +13805,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.DeleteDocumentRequest.pb( retriever_service.DeleteDocumentRequest() @@ -13816,8 +13856,9 @@ def test_list_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13880,17 +13921,20 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_list_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13948,8 +13992,9 @@ def test_query_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14009,17 +14054,20 @@ def test_query_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_query_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_query_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_query_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_query_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14077,8 +14125,9 @@ def test_create_chunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14225,17 +14274,20 @@ def test_create_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_chunk" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_create_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_create_chunk" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_create_chunk_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_create_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14288,8 +14340,9 @@ def test_batch_create_chunks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14349,18 +14402,20 @@ def test_batch_create_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_batch_create_chunks" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, - "post_batch_create_chunks_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_batch_create_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_batch_create_chunks" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_batch_create_chunks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_batch_create_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14416,8 +14471,9 @@ def test_get_chunk_rest_bad_request(request_type=retriever_service.GetChunkReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14482,17 +14538,19 @@ def test_get_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_chunk" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_get_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_chunk" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_chunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_get_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14547,8 +14605,9 @@ def test_update_chunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14697,17 +14756,20 @@ def test_update_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_chunk" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_update_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_update_chunk" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_update_chunk_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_update_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14760,8 +14822,9 @@ def test_batch_update_chunks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14821,18 +14884,20 @@ def test_batch_update_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_batch_update_chunks" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, - "post_batch_update_chunks_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_batch_update_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_batch_update_chunks" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_batch_update_chunks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_batch_update_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14890,8 +14955,9 @@ def test_delete_chunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14948,13 +15014,13 @@ def test_delete_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_delete_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_delete_chunk" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.DeleteChunkRequest.pb( retriever_service.DeleteChunkRequest() @@ -14999,8 +15065,9 @@ def test_batch_delete_chunks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15057,13 +15124,13 @@ def test_batch_delete_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_batch_delete_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_batch_delete_chunks" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.BatchDeleteChunksRequest.pb( retriever_service.BatchDeleteChunksRequest() @@ -15106,8 +15173,9 @@ def test_list_chunks_rest_bad_request(request_type=retriever_service.ListChunksR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15170,17 +15238,19 @@ def test_list_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_chunks" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_chunks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_list_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_chunks" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_chunks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_list_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15240,8 +15310,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15300,8 +15371,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15836,11 +15908,14 @@ def test_retriever_service_base_transport(): def test_retriever_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RetrieverServiceTransport( @@ -15857,9 +15932,12 @@ def test_retriever_service_base_transport_with_credentials_file(): def test_retriever_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RetrieverServiceTransport() @@ -15931,11 +16009,12 @@ def test_retriever_service_transport_auth_gdch_credentials(transport_class): def test_retriever_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16604,6 +16683,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RetrieverServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RetrieverServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RetrieverServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16749,6 +16862,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RetrieverServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RetrieverServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RetrieverServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_text_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_text_service.py index c5a5fe635ef2..468e1fd41874 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_text_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1alpha/test_text_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TextServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -137,6 +138,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TextServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TextServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_text_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3715,8 +3721,9 @@ def test_generate_text_rest_bad_request(request_type=text_service.GenerateTextRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3776,17 +3783,19 @@ def test_generate_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_generate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_generate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3839,8 +3848,9 @@ def test_embed_text_rest_bad_request(request_type=text_service.EmbedTextRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3900,17 +3910,19 @@ def test_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3963,8 +3975,9 @@ def test_batch_embed_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4024,17 +4037,19 @@ def test_batch_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_batch_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_batch_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_batch_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_batch_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_batch_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_batch_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4092,8 +4107,9 @@ def test_count_text_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4156,17 +4172,20 @@ def test_count_text_tokens_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_count_text_tokens" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_count_text_tokens_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_count_text_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_count_text_tokens" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, + "post_count_text_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_count_text_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4226,8 +4245,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4286,8 +4306,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4482,11 +4503,14 @@ def test_text_service_base_transport(): def test_text_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1alpha.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport( @@ -4503,9 +4527,12 @@ def test_text_service_base_transport_with_credentials_file(): def test_text_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1alpha.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1alpha.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport() @@ -4577,11 +4604,12 @@ def test_text_service_transport_auth_gdch_credentials(transport_class): def test_text_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5142,6 +5170,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = TextServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = TextServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = TextServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5287,6 +5349,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = TextServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = TextServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = TextServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_cache_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_cache_service.py index daf006dad640..a23037937333 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_cache_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_cache_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CacheServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CacheServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CacheServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1271,11 +1276,13 @@ def test_cache_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4256,8 +4263,9 @@ def test_list_cached_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4320,18 +4328,20 @@ def test_list_cached_contents_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_list_cached_contents" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, - "post_list_cached_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_list_cached_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_list_cached_contents" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_list_cached_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_list_cached_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4389,8 +4399,9 @@ def test_create_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4665,18 +4676,20 @@ def test_create_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_create_cached_content" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, - "post_create_cached_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_create_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_create_cached_content" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_create_cached_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_create_cached_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4731,8 +4744,9 @@ def test_get_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4799,17 +4813,20 @@ def test_get_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_get_cached_content" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_get_cached_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_get_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_get_cached_content" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_get_cached_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_get_cached_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4864,8 +4881,9 @@ def test_update_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5140,18 +5158,20 @@ def test_update_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "post_update_cached_content" - ) as post, mock.patch.object( - transports.CacheServiceRestInterceptor, - "post_update_cached_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_update_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "post_update_cached_content" + ) as post, + mock.patch.object( + transports.CacheServiceRestInterceptor, + "post_update_cached_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_update_cached_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5206,8 +5226,9 @@ def test_delete_cached_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5264,13 +5285,13 @@ def test_delete_cached_content_rest_interceptors(null_interceptor): ) client = CacheServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CacheServiceRestInterceptor, "pre_delete_cached_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CacheServiceRestInterceptor, "pre_delete_cached_content" + ) as pre, + ): pre.assert_not_called() pb_message = cache_service.DeleteCachedContentRequest.pb( cache_service.DeleteCachedContentRequest() @@ -5315,8 +5336,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5375,8 +5397,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5437,8 +5460,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5497,8 +5521,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5724,11 +5749,14 @@ def test_cache_service_base_transport(): def test_cache_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CacheServiceTransport( @@ -5745,9 +5773,12 @@ def test_cache_service_base_transport_with_credentials_file(): def test_cache_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.cache_service.transports.CacheServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CacheServiceTransport() @@ -5819,11 +5850,12 @@ def test_cache_service_transport_auth_gdch_credentials(transport_class): def test_cache_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6401,6 +6433,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CacheServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CacheServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CacheServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6540,6 +6604,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CacheServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CacheServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CacheServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6685,6 +6781,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CacheServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CacheServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CacheServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6830,6 +6960,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CacheServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CacheServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CacheServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_discuss_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_discuss_service.py index 6626f8a34c1e..87529572417b 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_discuss_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_discuss_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiscussServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( DiscussServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DiscussServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1280,11 +1285,13 @@ def test_discuss_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2645,8 +2652,9 @@ def test_generate_message_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2706,17 +2714,20 @@ def test_generate_message_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_generate_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_generate_message" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_generate_message_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_generate_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2774,8 +2785,9 @@ def test_count_message_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2838,18 +2850,20 @@ def test_count_message_tokens_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_count_message_tokens" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, - "post_count_message_tokens_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_count_message_tokens" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_count_message_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2907,8 +2921,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2967,8 +2982,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3029,8 +3045,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3089,8 +3106,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3245,11 +3263,14 @@ def test_discuss_service_base_transport(): def test_discuss_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport( @@ -3266,9 +3287,12 @@ def test_discuss_service_base_transport_with_credentials_file(): def test_discuss_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport() @@ -3340,11 +3364,12 @@ def test_discuss_service_transport_auth_gdch_credentials(transport_class): def test_discuss_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3904,6 +3929,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DiscussServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DiscussServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DiscussServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4043,6 +4100,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DiscussServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DiscussServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DiscussServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4188,6 +4277,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DiscussServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DiscussServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DiscussServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4333,6 +4456,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DiscussServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DiscussServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DiscussServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_file_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_file_service.py index 2df9c4f18784..dec9fe179ba7 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_file_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_file_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FileServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FileServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FileServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1248,11 +1252,13 @@ def test_file_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3818,8 +3824,9 @@ def test_create_file_rest_bad_request(request_type=file_service.CreateFileReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3879,17 +3886,19 @@ def test_create_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_create_file" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_create_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_create_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_create_file" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_create_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_create_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3940,8 +3949,9 @@ def test_list_files_rest_bad_request(request_type=file_service.ListFilesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4004,17 +4014,19 @@ def test_list_files_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_list_files" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_list_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_list_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_list_files" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_list_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_list_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4065,8 +4077,9 @@ def test_get_file_rest_bad_request(request_type=file_service.GetFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4145,17 +4158,17 @@ def test_get_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_get_file" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_get_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_get_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_get_file" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_get_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FileServiceRestInterceptor, "pre_get_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4204,8 +4217,9 @@ def test_delete_file_rest_bad_request(request_type=file_service.DeleteFileReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4262,13 +4276,13 @@ def test_delete_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_delete_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_delete_file" + ) as pre, + ): pre.assert_not_called() pb_message = file_service.DeleteFileRequest.pb(file_service.DeleteFileRequest()) transcode.return_value = { @@ -4309,8 +4323,9 @@ def test_download_file_rest_bad_request(request_type=file_service.DownloadFileRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4370,17 +4385,19 @@ def test_download_file_rest_interceptors(null_interceptor): ) client = FileServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FileServiceRestInterceptor, "post_download_file" - ) as post, mock.patch.object( - transports.FileServiceRestInterceptor, "post_download_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FileServiceRestInterceptor, "pre_download_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_download_file" + ) as post, + mock.patch.object( + transports.FileServiceRestInterceptor, "post_download_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FileServiceRestInterceptor, "pre_download_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4435,8 +4452,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4495,8 +4513,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4557,8 +4576,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4617,8 +4637,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4834,11 +4855,14 @@ def test_file_service_base_transport(): def test_file_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FileServiceTransport( @@ -4855,9 +4879,12 @@ def test_file_service_base_transport_with_credentials_file(): def test_file_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.file_service.transports.FileServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FileServiceTransport() @@ -4929,11 +4956,12 @@ def test_file_service_transport_auth_gdch_credentials(transport_class): def test_file_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5491,6 +5519,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = FileServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = FileServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = FileServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5630,6 +5690,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FileServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FileServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FileServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5775,6 +5867,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FileServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FileServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FileServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5920,6 +6046,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FileServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FileServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = FileServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_generative_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_generative_service.py index f919963068ca..e0777e424036 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_generative_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_generative_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GenerativeServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): GenerativeServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GenerativeServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1329,11 +1334,13 @@ def test_generative_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5200,8 +5207,9 @@ def test_generate_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5266,18 +5274,20 @@ def test_generate_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_generate_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_generate_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_generate_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_generate_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_generate_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_generate_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5335,8 +5345,9 @@ def test_generate_answer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5399,18 +5410,20 @@ def test_generate_answer_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_generate_answer" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_generate_answer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_generate_answer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_generate_answer" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_generate_answer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_generate_answer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5468,8 +5481,9 @@ def test_stream_generate_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5538,18 +5552,20 @@ def test_stream_generate_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_stream_generate_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_stream_generate_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_stream_generate_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_stream_generate_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_stream_generate_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_stream_generate_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5607,8 +5623,9 @@ def test_embed_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5668,17 +5685,20 @@ def test_embed_content_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_embed_content" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_embed_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_embed_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_embed_content" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_embed_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_embed_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5736,8 +5756,9 @@ def test_batch_embed_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5797,18 +5818,20 @@ def test_batch_embed_contents_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_batch_embed_contents" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, - "post_batch_embed_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_batch_embed_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_batch_embed_contents" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_batch_embed_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_batch_embed_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5866,8 +5889,9 @@ def test_count_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5932,17 +5956,20 @@ def test_count_tokens_rest_interceptors(null_interceptor): ) client = GenerativeServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_count_tokens" - ) as post, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "post_count_tokens_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GenerativeServiceRestInterceptor, "pre_count_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "post_count_tokens" + ) as post, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, + "post_count_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GenerativeServiceRestInterceptor, "pre_count_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6012,8 +6039,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6072,8 +6100,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6134,8 +6163,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6194,8 +6224,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6437,11 +6468,14 @@ def test_generative_service_base_transport(): def test_generative_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GenerativeServiceTransport( @@ -6458,9 +6492,12 @@ def test_generative_service_base_transport_with_credentials_file(): def test_generative_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.generative_service.transports.GenerativeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GenerativeServiceTransport() @@ -6532,11 +6569,12 @@ def test_generative_service_transport_auth_gdch_credentials(transport_class): def test_generative_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7131,6 +7169,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7270,6 +7340,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7415,6 +7517,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7560,6 +7696,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GenerativeServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GenerativeServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = GenerativeServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_model_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_model_service.py index b3cca3066bce..bc9f6ab4b93d 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_model_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_model_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1265,11 +1270,13 @@ def test_model_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5726,8 +5733,9 @@ def test_get_model_rest_bad_request(request_type=model_service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5816,17 +5824,19 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5875,8 +5885,9 @@ def test_list_models_rest_bad_request(request_type=model_service.ListModelsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5939,17 +5950,19 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6004,8 +6017,9 @@ def test_get_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6083,17 +6097,19 @@ def test_get_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_tuned_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6146,8 +6162,9 @@ def test_list_tuned_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6210,17 +6227,20 @@ def test_list_tuned_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_tuned_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_tuned_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_tuned_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_tuned_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_list_tuned_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_tuned_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6278,8 +6298,9 @@ def test_create_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6440,19 +6461,21 @@ def test_create_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ModelServiceRestInterceptor, "post_create_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_create_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_create_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_create_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_create_tuned_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_create_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6505,8 +6528,9 @@ def test_update_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6688,17 +6712,20 @@ def test_update_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_update_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_update_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_update_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_update_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_update_tuned_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_update_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6751,8 +6778,9 @@ def test_delete_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6809,13 +6837,13 @@ def test_delete_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_delete_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_delete_tuned_model" + ) as pre, + ): pre.assert_not_called() pb_message = model_service.DeleteTunedModelRequest.pb( model_service.DeleteTunedModelRequest() @@ -6860,8 +6888,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6920,8 +6949,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6982,8 +7012,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7042,8 +7073,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7331,11 +7363,14 @@ def test_model_service_base_transport(): def test_model_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport( @@ -7352,9 +7387,12 @@ def test_model_service_base_transport_with_credentials_file(): def test_model_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport() @@ -7426,11 +7464,12 @@ def test_model_service_transport_auth_gdch_credentials(transport_class): def test_model_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8048,6 +8087,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8187,6 +8258,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8332,6 +8435,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8477,6 +8614,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ModelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_permission_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_permission_service.py index 8e23e1657be2..0d9ae5df1460 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_permission_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_permission_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PermissionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): PermissionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PermissionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1321,11 +1326,13 @@ def test_permission_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5075,8 +5082,9 @@ def test_create_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5218,18 +5226,20 @@ def test_create_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_create_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_create_permission_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_create_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_create_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_create_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_create_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5282,8 +5292,9 @@ def test_get_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5352,17 +5363,20 @@ def test_get_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_get_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_get_permission_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_get_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_get_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_get_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_get_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5415,8 +5429,9 @@ def test_list_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5479,18 +5494,20 @@ def test_list_permissions_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_list_permissions" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_list_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_list_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_list_permissions" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_list_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_list_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5548,8 +5565,9 @@ def test_update_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5691,18 +5709,20 @@ def test_update_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_update_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_update_permission_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_update_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_update_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_update_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_update_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5755,8 +5775,9 @@ def test_delete_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5813,13 +5834,13 @@ def test_delete_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_delete_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_delete_permission" + ) as pre, + ): pre.assert_not_called() pb_message = permission_service.DeletePermissionRequest.pb( permission_service.DeletePermissionRequest() @@ -5864,8 +5885,9 @@ def test_transfer_ownership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5925,18 +5947,20 @@ def test_transfer_ownership_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_transfer_ownership" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_transfer_ownership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_transfer_ownership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_transfer_ownership" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_transfer_ownership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_transfer_ownership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5994,8 +6018,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6054,8 +6079,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6116,8 +6142,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6176,8 +6203,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6422,11 +6450,14 @@ def test_permission_service_base_transport(): def test_permission_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PermissionServiceTransport( @@ -6443,9 +6474,12 @@ def test_permission_service_base_transport_with_credentials_file(): def test_permission_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PermissionServiceTransport() @@ -6517,11 +6551,12 @@ def test_permission_service_transport_auth_gdch_credentials(transport_class): def test_permission_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7096,6 +7131,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = PermissionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = PermissionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = PermissionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7235,6 +7302,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PermissionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PermissionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PermissionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7380,6 +7479,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PermissionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PermissionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PermissionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7525,6 +7658,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PermissionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PermissionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = PermissionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_prediction_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_prediction_service.py index 55c543b8f9e6..7504fd1c4cc5 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_prediction_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_prediction_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PredictionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): PredictionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PredictionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1323,11 +1328,13 @@ def test_prediction_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2638,8 +2645,9 @@ def test_predict_rest_bad_request(request_type=prediction_service.PredictRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2699,17 +2707,19 @@ def test_predict_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_predict" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_predict" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2764,8 +2774,9 @@ def test_predict_long_running_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2822,20 +2833,21 @@ def test_predict_long_running_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict_long_running" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, - "post_predict_long_running_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_predict_long_running" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict_long_running" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, + "post_predict_long_running_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_predict_long_running" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2888,8 +2900,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2948,8 +2961,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3010,8 +3024,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3070,8 +3085,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3248,11 +3264,14 @@ def test_prediction_service_base_transport(): def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( @@ -3269,9 +3288,12 @@ def test_prediction_service_base_transport_with_credentials_file(): def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport() @@ -3343,11 +3365,12 @@ def test_prediction_service_transport_auth_gdch_credentials(transport_class): def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3941,6 +3964,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4080,6 +4135,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4225,6 +4312,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4370,6 +4491,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_retriever_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_retriever_service.py index 890135828eb2..5ddf953cc2d8 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_retriever_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_retriever_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RetrieverServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RetrieverServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RetrieverServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1313,11 +1318,13 @@ def test_retriever_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12257,8 +12264,9 @@ def test_create_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12396,17 +12404,20 @@ def test_create_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_create_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_create_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_create_corpus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_create_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12457,8 +12468,9 @@ def test_get_corpus_rest_bad_request(request_type=retriever_service.GetCorpusReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12523,17 +12535,19 @@ def test_get_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_get_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_corpus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_get_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12586,8 +12600,9 @@ def test_update_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12725,17 +12740,20 @@ def test_update_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_update_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_update_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_update_corpus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_update_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12788,8 +12806,9 @@ def test_delete_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12846,13 +12865,13 @@ def test_delete_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_delete_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_delete_corpus" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.DeleteCorpusRequest.pb( retriever_service.DeleteCorpusRequest() @@ -12897,8 +12916,9 @@ def test_list_corpora_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12961,17 +12981,20 @@ def test_list_corpora_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_corpora" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_corpora_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_list_corpora" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_corpora" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_list_corpora_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_list_corpora" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13029,8 +13052,9 @@ def test_query_corpus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13090,17 +13114,20 @@ def test_query_corpus_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_corpus" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_corpus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_query_corpus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_query_corpus" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_query_corpus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_query_corpus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13158,8 +13185,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13305,17 +13333,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_create_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13368,8 +13399,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13434,17 +13466,20 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_get_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13497,8 +13532,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13644,17 +13680,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_update_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13707,8 +13746,9 @@ def test_delete_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13765,13 +13805,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.DeleteDocumentRequest.pb( retriever_service.DeleteDocumentRequest() @@ -13816,8 +13856,9 @@ def test_list_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13880,17 +13921,20 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_list_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13948,8 +13992,9 @@ def test_query_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14009,17 +14054,20 @@ def test_query_document_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_document" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_query_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_query_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_query_document" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_query_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_query_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14077,8 +14125,9 @@ def test_create_chunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14225,17 +14274,20 @@ def test_create_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_chunk" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_create_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_create_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_create_chunk" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_create_chunk_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_create_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14288,8 +14340,9 @@ def test_batch_create_chunks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14349,18 +14402,20 @@ def test_batch_create_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_batch_create_chunks" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, - "post_batch_create_chunks_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_batch_create_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_batch_create_chunks" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_batch_create_chunks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_batch_create_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14416,8 +14471,9 @@ def test_get_chunk_rest_bad_request(request_type=retriever_service.GetChunkReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14482,17 +14538,19 @@ def test_get_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_chunk" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_get_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_get_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_chunk" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_get_chunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_get_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14547,8 +14605,9 @@ def test_update_chunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14697,17 +14756,20 @@ def test_update_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_chunk" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_update_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_update_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_update_chunk" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_update_chunk_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_update_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14760,8 +14822,9 @@ def test_batch_update_chunks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14821,18 +14884,20 @@ def test_batch_update_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_batch_update_chunks" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, - "post_batch_update_chunks_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_batch_update_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_batch_update_chunks" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, + "post_batch_update_chunks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_batch_update_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14890,8 +14955,9 @@ def test_delete_chunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14948,13 +15014,13 @@ def test_delete_chunk_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_delete_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_delete_chunk" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.DeleteChunkRequest.pb( retriever_service.DeleteChunkRequest() @@ -14999,8 +15065,9 @@ def test_batch_delete_chunks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15057,13 +15124,13 @@ def test_batch_delete_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_batch_delete_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_batch_delete_chunks" + ) as pre, + ): pre.assert_not_called() pb_message = retriever_service.BatchDeleteChunksRequest.pb( retriever_service.BatchDeleteChunksRequest() @@ -15106,8 +15173,9 @@ def test_list_chunks_rest_bad_request(request_type=retriever_service.ListChunksR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15170,17 +15238,19 @@ def test_list_chunks_rest_interceptors(null_interceptor): ) client = RetrieverServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_chunks" - ) as post, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "post_list_chunks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RetrieverServiceRestInterceptor, "pre_list_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_chunks" + ) as post, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "post_list_chunks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RetrieverServiceRestInterceptor, "pre_list_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15238,8 +15308,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15298,8 +15369,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15360,8 +15432,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15420,8 +15493,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15958,11 +16032,14 @@ def test_retriever_service_base_transport(): def test_retriever_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RetrieverServiceTransport( @@ -15979,9 +16056,12 @@ def test_retriever_service_base_transport_with_credentials_file(): def test_retriever_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.retriever_service.transports.RetrieverServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RetrieverServiceTransport() @@ -16053,11 +16133,12 @@ def test_retriever_service_transport_auth_gdch_credentials(transport_class): def test_retriever_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16720,6 +16801,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = RetrieverServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = RetrieverServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = RetrieverServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16859,6 +16972,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RetrieverServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RetrieverServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RetrieverServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17004,6 +17149,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RetrieverServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RetrieverServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RetrieverServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17149,6 +17328,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RetrieverServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RetrieverServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RetrieverServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_text_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_text_service.py index 245cf4b5c6c3..6a3ab26fda68 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_text_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta/test_text_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TextServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -137,6 +138,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TextServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TextServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_text_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3715,8 +3721,9 @@ def test_generate_text_rest_bad_request(request_type=text_service.GenerateTextRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3776,17 +3783,19 @@ def test_generate_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_generate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_generate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3839,8 +3848,9 @@ def test_embed_text_rest_bad_request(request_type=text_service.EmbedTextRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3900,17 +3910,19 @@ def test_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3963,8 +3975,9 @@ def test_batch_embed_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4024,17 +4037,19 @@ def test_batch_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_batch_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_batch_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_batch_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_batch_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_batch_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_batch_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4092,8 +4107,9 @@ def test_count_text_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4156,17 +4172,20 @@ def test_count_text_tokens_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_count_text_tokens" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_count_text_tokens_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_count_text_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_count_text_tokens" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, + "post_count_text_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_count_text_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4224,8 +4243,9 @@ def test_cancel_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4284,8 +4304,9 @@ def test_delete_operation_rest_bad_request( request = json_format.ParseDict({"name": "batches/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4346,8 +4367,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4406,8 +4428,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "tunedModels/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4604,11 +4627,14 @@ def test_text_service_base_transport(): def test_text_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport( @@ -4625,9 +4651,12 @@ def test_text_service_base_transport_with_credentials_file(): def test_text_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport() @@ -4699,11 +4728,12 @@ def test_text_service_transport_auth_gdch_credentials(transport_class): def test_text_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5258,6 +5288,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = TextServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = TextServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = TextServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5397,6 +5459,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = TextServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = TextServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = TextServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5542,6 +5636,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = TextServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = TextServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = TextServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5687,6 +5815,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = TextServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = TextServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = TextServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_discuss_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_discuss_service.py index 2981ba16546b..a4f0806664a5 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_discuss_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_discuss_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiscussServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( DiscussServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DiscussServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1279,11 +1284,13 @@ def test_discuss_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2644,8 +2651,9 @@ def test_generate_message_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2705,17 +2713,20 @@ def test_generate_message_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_generate_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_generate_message" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_generate_message_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_generate_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2773,8 +2784,9 @@ def test_count_message_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2837,18 +2849,20 @@ def test_count_message_tokens_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_count_message_tokens" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, - "post_count_message_tokens_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_count_message_tokens" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_count_message_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2998,11 +3012,14 @@ def test_discuss_service_base_transport(): def test_discuss_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta2.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta2.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport( @@ -3019,9 +3036,12 @@ def test_discuss_service_base_transport_with_credentials_file(): def test_discuss_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta2.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta2.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport() @@ -3093,11 +3113,12 @@ def test_discuss_service_transport_auth_gdch_credentials(transport_class): def test_discuss_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_model_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_model_service.py index 35600caab363..c9c73c5908af 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_model_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_model_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -137,6 +138,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1257,11 +1262,13 @@ def test_model_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2678,8 +2685,9 @@ def test_get_model_rest_bad_request(request_type=model_service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2764,17 +2772,19 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2823,8 +2833,9 @@ def test_list_models_rest_bad_request(request_type=model_service.ListModelsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2887,17 +2898,19 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3042,11 +3055,14 @@ def test_model_service_base_transport(): def test_model_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta2.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta2.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport( @@ -3063,9 +3079,12 @@ def test_model_service_base_transport_with_credentials_file(): def test_model_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta2.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta2.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport() @@ -3137,11 +3156,12 @@ def test_model_service_transport_auth_gdch_credentials(transport_class): def test_model_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_text_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_text_service.py index 256adf04b223..8bf13d60bf6e 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_text_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta2/test_text_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TextServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TextServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TextServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_text_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2578,8 +2584,9 @@ def test_generate_text_rest_bad_request(request_type=text_service.GenerateTextRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2639,17 +2646,19 @@ def test_generate_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_generate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_generate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2702,8 +2711,9 @@ def test_embed_text_rest_bad_request(request_type=text_service.EmbedTextRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2763,17 +2773,19 @@ def test_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2916,11 +2928,14 @@ def test_text_service_base_transport(): def test_text_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta2.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta2.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport( @@ -2937,9 +2952,12 @@ def test_text_service_base_transport_with_credentials_file(): def test_text_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta2.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta2.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport() @@ -3011,11 +3029,12 @@ def test_text_service_transport_auth_gdch_credentials(transport_class): def test_text_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_discuss_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_discuss_service.py index c42f6a7ecc25..ef1d812dad5b 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_discuss_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_discuss_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiscussServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( DiscussServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DiscussServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1280,11 +1285,13 @@ def test_discuss_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2645,8 +2652,9 @@ def test_generate_message_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2706,17 +2714,20 @@ def test_generate_message_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_generate_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_generate_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_generate_message" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_generate_message_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_generate_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2774,8 +2785,9 @@ def test_count_message_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2838,18 +2850,20 @@ def test_count_message_tokens_rest_interceptors(null_interceptor): ) client = DiscussServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiscussServiceRestInterceptor, "post_count_message_tokens" - ) as post, mock.patch.object( - transports.DiscussServiceRestInterceptor, - "post_count_message_tokens_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "post_count_message_tokens" + ) as post, + mock.patch.object( + transports.DiscussServiceRestInterceptor, + "post_count_message_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DiscussServiceRestInterceptor, "pre_count_message_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2999,11 +3013,14 @@ def test_discuss_service_base_transport(): def test_discuss_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta3.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport( @@ -3020,9 +3037,12 @@ def test_discuss_service_base_transport_with_credentials_file(): def test_discuss_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta3.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.discuss_service.transports.DiscussServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiscussServiceTransport() @@ -3094,11 +3114,12 @@ def test_discuss_service_transport_auth_gdch_credentials(transport_class): def test_discuss_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_model_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_model_service.py index abf389a260a1..67a06f32cde4 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_model_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_model_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1265,11 +1270,13 @@ def test_model_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5712,8 +5719,9 @@ def test_get_model_rest_bad_request(request_type=model_service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5798,17 +5806,19 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5857,8 +5867,9 @@ def test_list_models_rest_bad_request(request_type=model_service.ListModelsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5921,17 +5932,19 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5986,8 +5999,9 @@ def test_get_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6063,17 +6077,19 @@ def test_get_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_get_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_get_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_get_tuned_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_get_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6126,8 +6142,9 @@ def test_list_tuned_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6190,17 +6207,20 @@ def test_list_tuned_models_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_tuned_models" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_list_tuned_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_list_tuned_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_list_tuned_models" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_list_tuned_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_list_tuned_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6258,8 +6278,9 @@ def test_create_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6418,19 +6439,21 @@ def test_create_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ModelServiceRestInterceptor, "post_create_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_create_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_create_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_create_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_create_tuned_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_create_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6483,8 +6506,9 @@ def test_update_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6662,17 +6686,20 @@ def test_update_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_update_tuned_model" - ) as post, mock.patch.object( - transports.ModelServiceRestInterceptor, "post_update_tuned_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_update_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "post_update_tuned_model" + ) as post, + mock.patch.object( + transports.ModelServiceRestInterceptor, + "post_update_tuned_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_update_tuned_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6725,8 +6752,9 @@ def test_delete_tuned_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6783,13 +6811,13 @@ def test_delete_tuned_model_rest_interceptors(null_interceptor): ) client = ModelServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelServiceRestInterceptor, "pre_delete_tuned_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelServiceRestInterceptor, "pre_delete_tuned_model" + ) as pre, + ): pre.assert_not_called() pb_message = model_service.DeleteTunedModelRequest.pb( model_service.DeleteTunedModelRequest() @@ -7059,11 +7087,14 @@ def test_model_service_base_transport(): def test_model_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta3.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport( @@ -7080,9 +7111,12 @@ def test_model_service_base_transport_with_credentials_file(): def test_model_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta3.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelServiceTransport() @@ -7154,11 +7188,12 @@ def test_model_service_transport_auth_gdch_credentials(transport_class): def test_model_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_permission_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_permission_service.py index 0aad249c14c0..82b2e91eaba2 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_permission_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_permission_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PermissionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): PermissionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PermissionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1321,11 +1326,13 @@ def test_permission_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5075,8 +5082,9 @@ def test_create_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5218,18 +5226,20 @@ def test_create_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_create_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_create_permission_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_create_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_create_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_create_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_create_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5282,8 +5292,9 @@ def test_get_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5352,17 +5363,20 @@ def test_get_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_get_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_get_permission_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_get_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_get_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_get_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_get_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5415,8 +5429,9 @@ def test_list_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5479,18 +5494,20 @@ def test_list_permissions_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_list_permissions" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_list_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_list_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_list_permissions" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_list_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_list_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5548,8 +5565,9 @@ def test_update_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5691,18 +5709,20 @@ def test_update_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_update_permission" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_update_permission_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_update_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_update_permission" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_update_permission_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_update_permission" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5755,8 +5775,9 @@ def test_delete_permission_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5813,13 +5834,13 @@ def test_delete_permission_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_delete_permission" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_delete_permission" + ) as pre, + ): pre.assert_not_called() pb_message = permission_service.DeletePermissionRequest.pb( permission_service.DeletePermissionRequest() @@ -5864,8 +5885,9 @@ def test_transfer_ownership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5925,18 +5947,20 @@ def test_transfer_ownership_rest_interceptors(null_interceptor): ) client = PermissionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PermissionServiceRestInterceptor, "post_transfer_ownership" - ) as post, mock.patch.object( - transports.PermissionServiceRestInterceptor, - "post_transfer_ownership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PermissionServiceRestInterceptor, "pre_transfer_ownership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "post_transfer_ownership" + ) as post, + mock.patch.object( + transports.PermissionServiceRestInterceptor, + "post_transfer_ownership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PermissionServiceRestInterceptor, "pre_transfer_ownership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6176,11 +6200,14 @@ def test_permission_service_base_transport(): def test_permission_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta3.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PermissionServiceTransport( @@ -6197,9 +6224,12 @@ def test_permission_service_base_transport_with_credentials_file(): def test_permission_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta3.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.permission_service.transports.PermissionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PermissionServiceTransport() @@ -6271,11 +6301,12 @@ def test_permission_service_transport_auth_gdch_credentials(transport_class): def test_permission_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_text_service.py b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_text_service.py index 88370ca1ef45..15bf7aeb4b25 100644 --- a/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_text_service.py +++ b/packages/google-ai-generativelanguage/tests/unit/gapic/generativelanguage_v1beta3/test_text_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TextServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -137,6 +138,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TextServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TextServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_text_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3739,8 +3745,9 @@ def test_generate_text_rest_bad_request(request_type=text_service.GenerateTextRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3800,17 +3807,19 @@ def test_generate_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_generate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_generate_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_generate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3863,8 +3872,9 @@ def test_embed_text_rest_bad_request(request_type=text_service.EmbedTextRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3924,17 +3934,19 @@ def test_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3987,8 +3999,9 @@ def test_batch_embed_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4048,17 +4061,19 @@ def test_batch_embed_text_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_batch_embed_text" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_batch_embed_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_batch_embed_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_batch_embed_text" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_batch_embed_text_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_batch_embed_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4116,8 +4131,9 @@ def test_count_text_tokens_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4180,17 +4196,20 @@ def test_count_text_tokens_rest_interceptors(null_interceptor): ) client = TextServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TextServiceRestInterceptor, "post_count_text_tokens" - ) as post, mock.patch.object( - transports.TextServiceRestInterceptor, "post_count_text_tokens_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TextServiceRestInterceptor, "pre_count_text_tokens" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TextServiceRestInterceptor, "post_count_text_tokens" + ) as post, + mock.patch.object( + transports.TextServiceRestInterceptor, + "post_count_text_tokens_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TextServiceRestInterceptor, "pre_count_text_tokens" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4382,11 +4401,14 @@ def test_text_service_base_transport(): def test_text_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.ai.generativelanguage_v1beta3.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport( @@ -4403,9 +4425,12 @@ def test_text_service_base_transport_with_credentials_file(): def test_text_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.ai.generativelanguage_v1beta3.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.ai.generativelanguage_v1beta3.services.text_service.transports.TextServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TextServiceTransport() @@ -4477,11 +4502,12 @@ def test_text_service_transport_auth_gdch_credentials(transport_class): def test_text_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py index a5da6d7fb55f..d54c7760ccb1 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py @@ -402,7 +402,7 @@ def transport(self) -> AnalyticsAdminServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py index 64b553827f1b..f9da1f4e1341 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py @@ -131,7 +131,7 @@ class AnalyticsAdminServiceClient(metaclass=AnalyticsAdminServiceClientMeta): """Service Interface for the Google Analytics Admin API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -1130,7 +1134,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -1229,7 +1233,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1329,7 +1333,7 @@ def __init__( self._universe_domain = AnalyticsAdminServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/README.rst b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/README.rst index b745c67d3897..5a4c40939f3c 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/README.rst +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AnalyticsAdminServiceTransport` is the ABC for all transports. -- public child `AnalyticsAdminServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AnalyticsAdminServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAnalyticsAdminServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AnalyticsAdminServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AnalyticsAdminServiceTransport`` is the ABC for all transports. + +- public child ``AnalyticsAdminServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AnalyticsAdminServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAnalyticsAdminServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AnalyticsAdminServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py index db8dc6f9f2b3..18f5d3be868b 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py @@ -102,6 +102,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -151,6 +155,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py index dd98c207c75a..f387123f4af6 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py @@ -71,7 +71,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -106,7 +106,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -201,6 +201,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py index 67f2a37f6030..ca63a0366a32 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py @@ -77,7 +77,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -112,7 +112,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -252,6 +252,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/rest.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/rest.py index 5a6d939205be..74089bdca563 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/rest.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/rest.py @@ -8063,6 +8063,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AnalyticsAdminServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/async_client.py b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/async_client.py index e9a506dca9ce..6b33c456d496 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/async_client.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/async_client.py @@ -262,7 +262,7 @@ def transport(self) -> AnalyticsAdminServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/client.py b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/client.py index 0c88d2660100..b2ce87267a87 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/client.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/client.py @@ -117,7 +117,7 @@ class AnalyticsAdminServiceClient(metaclass=AnalyticsAdminServiceClientMeta): """Service Interface for the Google Analytics Admin API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -668,7 +672,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -767,7 +771,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -867,7 +871,7 @@ def __init__( self._universe_domain = AnalyticsAdminServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/README.rst b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/README.rst index b745c67d3897..5a4c40939f3c 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/README.rst +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AnalyticsAdminServiceTransport` is the ABC for all transports. -- public child `AnalyticsAdminServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AnalyticsAdminServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAnalyticsAdminServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AnalyticsAdminServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AnalyticsAdminServiceTransport`` is the ABC for all transports. + +- public child ``AnalyticsAdminServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AnalyticsAdminServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAnalyticsAdminServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AnalyticsAdminServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/base.py b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/base.py index f3d290afbc0c..4a8f4f0acf0f 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/base.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc.py b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc.py index 9565903d80a9..5f80dacd39d2 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc_asyncio.py b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc_asyncio.py index f1492a1e5292..ee1f670bcc59 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc_asyncio.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/rest.py b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/rest.py index c38632009b51..02513363641b 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/rest.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1beta/services/analytics_admin_service/transports/rest.py @@ -2893,6 +2893,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AnalyticsAdminServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index d410e6e59bf4..486143d95e80 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-analytics-admin/setup.py b/packages/google-analytics-admin/setup.py index 819dcf755029..16db9cd21496 100644 --- a/packages/google-analytics-admin/setup.py +++ b/packages/google-analytics-admin/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-analytics-admin" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-analytics-admin/testing/constraints-3.7.txt b/packages/google-analytics-admin/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-analytics-admin/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-analytics-admin/testing/constraints-3.8.txt b/packages/google-analytics-admin/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-analytics-admin/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-analytics-admin/testing/constraints-3.9.txt b/packages/google-analytics-admin/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-analytics-admin/testing/constraints-3.9.txt +++ b/packages/google-analytics-admin/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py b/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py index 227f7c10481e..633bcc8c1c3b 100644 --- a/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py +++ b/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py @@ -141,6 +141,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AnalyticsAdminServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -163,6 +164,10 @@ def test__get_default_mtls_endpoint(): AnalyticsAdminServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AnalyticsAdminServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1364,11 +1369,13 @@ def test_analytics_admin_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -97626,8 +97633,9 @@ def test_get_account_rest_bad_request(request_type=analytics_admin.GetAccountReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -97698,18 +97706,20 @@ def test_get_account_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_account" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_account" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -97762,8 +97772,9 @@ def test_list_accounts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -97826,18 +97837,20 @@ def test_list_accounts_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_accounts" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_accounts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_accounts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_accounts" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_accounts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_accounts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -97895,8 +97908,9 @@ def test_delete_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -97953,13 +97967,13 @@ def test_delete_account_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_account" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteAccountRequest.pb( analytics_admin.DeleteAccountRequest() @@ -98004,8 +98018,9 @@ def test_update_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -98152,18 +98167,20 @@ def test_update_account_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_account" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_account" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -98216,8 +98233,9 @@ def test_provision_account_ticket_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -98280,18 +98298,22 @@ def test_provision_account_ticket_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_provision_account_ticket" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_provision_account_ticket_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_provision_account_ticket" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_provision_account_ticket", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_provision_account_ticket_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_provision_account_ticket", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -98349,8 +98371,9 @@ def test_list_account_summaries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -98413,18 +98436,22 @@ def test_list_account_summaries_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_account_summaries" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_account_summaries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_account_summaries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_account_summaries", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_account_summaries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_account_summaries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -98480,8 +98507,9 @@ def test_get_property_rest_bad_request(request_type=analytics_admin.GetPropertyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -98560,18 +98588,20 @@ def test_get_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -98624,8 +98654,9 @@ def test_list_properties_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -98688,18 +98719,20 @@ def test_list_properties_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_properties" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_properties_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_properties" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_properties" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_properties_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_properties" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -98757,8 +98790,9 @@ def test_create_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -98919,18 +98953,20 @@ def test_create_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -98983,8 +99019,9 @@ def test_delete_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -99063,18 +99100,20 @@ def test_delete_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_delete_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_delete_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_delete_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_delete_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -99127,8 +99166,9 @@ def test_update_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -99289,18 +99329,20 @@ def test_update_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -99353,8 +99395,9 @@ def test_create_firebase_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -99491,18 +99534,20 @@ def test_create_firebase_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_firebase_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_firebase_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_firebase_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_firebase_link" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_firebase_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_firebase_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -99555,8 +99600,9 @@ def test_delete_firebase_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -99613,13 +99659,13 @@ def test_delete_firebase_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_firebase_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_firebase_link" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteFirebaseLinkRequest.pb( analytics_admin.DeleteFirebaseLinkRequest() @@ -99664,8 +99710,9 @@ def test_list_firebase_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -99728,18 +99775,20 @@ def test_list_firebase_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_firebase_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_firebase_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_firebase_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_firebase_links" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_firebase_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_firebase_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -99797,8 +99846,9 @@ def test_get_global_site_tag_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -99863,18 +99913,20 @@ def test_get_global_site_tag_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_global_site_tag" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_global_site_tag_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_global_site_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_global_site_tag" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_global_site_tag_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_global_site_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -99927,8 +99979,9 @@ def test_create_google_ads_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100075,18 +100128,22 @@ def test_create_google_ads_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_google_ads_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_google_ads_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_google_ads_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_google_ads_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_google_ads_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_google_ads_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -100141,8 +100198,9 @@ def test_update_google_ads_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100291,18 +100349,22 @@ def test_update_google_ads_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_google_ads_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_google_ads_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_google_ads_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_google_ads_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_google_ads_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_google_ads_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -100355,8 +100417,9 @@ def test_delete_google_ads_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100413,13 +100476,14 @@ def test_delete_google_ads_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_google_ads_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_google_ads_link", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteGoogleAdsLinkRequest.pb( analytics_admin.DeleteGoogleAdsLinkRequest() @@ -100464,8 +100528,9 @@ def test_list_google_ads_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100528,18 +100593,21 @@ def test_list_google_ads_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_google_ads_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_google_ads_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_google_ads_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_google_ads_links", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_google_ads_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_google_ads_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -100597,8 +100665,9 @@ def test_get_data_sharing_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100671,19 +100740,22 @@ def test_get_data_sharing_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_sharing_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_sharing_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_data_sharing_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_sharing_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_sharing_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_data_sharing_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -100740,8 +100812,9 @@ def test_get_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100810,20 +100883,22 @@ def test_get_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_measurement_protocol_secret", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_measurement_protocol_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_measurement_protocol_secret", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_measurement_protocol_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -100881,8 +100956,9 @@ def test_list_measurement_protocol_secrets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -100947,20 +101023,22 @@ def test_list_measurement_protocol_secrets_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_measurement_protocol_secrets", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_measurement_protocol_secrets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_measurement_protocol_secrets", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_measurement_protocol_secrets", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_measurement_protocol_secrets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_measurement_protocol_secrets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -101018,8 +101096,9 @@ def test_create_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -101164,20 +101243,22 @@ def test_create_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_measurement_protocol_secret", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_measurement_protocol_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_measurement_protocol_secret", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_measurement_protocol_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -101237,8 +101318,9 @@ def test_delete_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -101297,14 +101379,14 @@ def test_delete_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteMeasurementProtocolSecretRequest.pb( analytics_admin.DeleteMeasurementProtocolSecretRequest() @@ -101353,8 +101435,9 @@ def test_update_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -101503,20 +101586,22 @@ def test_update_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_measurement_protocol_secret", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_measurement_protocol_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_measurement_protocol_secret", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_measurement_protocol_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -101574,8 +101659,9 @@ def test_acknowledge_user_data_collection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -101637,20 +101723,22 @@ def test_acknowledge_user_data_collection_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_acknowledge_user_data_collection", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_acknowledge_user_data_collection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_acknowledge_user_data_collection", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_acknowledge_user_data_collection", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_acknowledge_user_data_collection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_acknowledge_user_data_collection", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -101710,8 +101798,9 @@ def test_get_sk_ad_network_conversion_value_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -101778,20 +101867,22 @@ def test_get_sk_ad_network_conversion_value_schema_rest_interceptors(null_interc ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_sk_ad_network_conversion_value_schema", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_sk_ad_network_conversion_value_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_sk_ad_network_conversion_value_schema", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_sk_ad_network_conversion_value_schema", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_sk_ad_network_conversion_value_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_sk_ad_network_conversion_value_schema", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -101849,8 +101940,9 @@ def test_create_sk_ad_network_conversion_value_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -102020,20 +102112,22 @@ def test_create_sk_ad_network_conversion_value_schema_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_sk_ad_network_conversion_value_schema", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_sk_ad_network_conversion_value_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_sk_ad_network_conversion_value_schema", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_sk_ad_network_conversion_value_schema", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_sk_ad_network_conversion_value_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_sk_ad_network_conversion_value_schema", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -102093,8 +102187,9 @@ def test_delete_sk_ad_network_conversion_value_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -102155,14 +102250,14 @@ def test_delete_sk_ad_network_conversion_value_schema_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_sk_ad_network_conversion_value_schema", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_sk_ad_network_conversion_value_schema", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteSKAdNetworkConversionValueSchemaRequest.pb( analytics_admin.DeleteSKAdNetworkConversionValueSchemaRequest() @@ -102211,8 +102306,9 @@ def test_update_sk_ad_network_conversion_value_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -102386,20 +102482,22 @@ def test_update_sk_ad_network_conversion_value_schema_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_sk_ad_network_conversion_value_schema", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_sk_ad_network_conversion_value_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_sk_ad_network_conversion_value_schema", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_sk_ad_network_conversion_value_schema", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_sk_ad_network_conversion_value_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_sk_ad_network_conversion_value_schema", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -102457,8 +102555,9 @@ def test_list_sk_ad_network_conversion_value_schemas_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -102525,20 +102624,22 @@ def test_list_sk_ad_network_conversion_value_schemas_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_sk_ad_network_conversion_value_schemas", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_sk_ad_network_conversion_value_schemas_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_sk_ad_network_conversion_value_schemas", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_sk_ad_network_conversion_value_schemas", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_sk_ad_network_conversion_value_schemas_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_sk_ad_network_conversion_value_schemas", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -102600,8 +102701,9 @@ def test_search_change_history_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -102666,20 +102768,22 @@ def test_search_change_history_events_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_search_change_history_events", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_search_change_history_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_search_change_history_events", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_search_change_history_events", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_search_change_history_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_search_change_history_events", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -102737,8 +102841,9 @@ def test_get_google_signals_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -102808,20 +102913,22 @@ def test_get_google_signals_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_google_signals_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_google_signals_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_google_signals_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_google_signals_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_google_signals_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_google_signals_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -102878,8 +102985,9 @@ def test_update_google_signals_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -103027,20 +103135,22 @@ def test_update_google_signals_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_google_signals_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_google_signals_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_google_signals_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_google_signals_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_google_signals_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_google_signals_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -103095,8 +103205,9 @@ def test_create_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -103251,18 +103362,22 @@ def test_create_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_conversion_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_conversion_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_conversion_event", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_conversion_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_conversion_event", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -103317,8 +103432,9 @@ def test_update_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -103475,18 +103591,22 @@ def test_update_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_conversion_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_conversion_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_conversion_event", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_conversion_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_conversion_event", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -103539,8 +103659,9 @@ def test_get_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -103614,18 +103735,20 @@ def test_get_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_conversion_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_conversion_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_conversion_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_conversion_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_conversion_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -103678,8 +103801,9 @@ def test_delete_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -103736,13 +103860,14 @@ def test_delete_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_conversion_event", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteConversionEventRequest.pb( analytics_admin.DeleteConversionEventRequest() @@ -103787,8 +103912,9 @@ def test_list_conversion_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -103851,18 +103977,22 @@ def test_list_conversion_events_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_conversion_events" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_conversion_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_conversion_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_conversion_events", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_conversion_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_conversion_events", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -103920,8 +104050,9 @@ def test_create_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104071,18 +104202,20 @@ def test_create_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_key_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_key_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_key_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_key_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_key_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -104135,8 +104268,9 @@ def test_update_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104286,18 +104420,20 @@ def test_update_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_key_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_key_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_key_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_key_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_key_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -104350,8 +104486,9 @@ def test_get_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104422,18 +104559,20 @@ def test_get_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_key_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_key_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_key_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_key_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_key_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -104486,8 +104625,9 @@ def test_delete_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104544,13 +104684,13 @@ def test_delete_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_key_event" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteKeyEventRequest.pb( analytics_admin.DeleteKeyEventRequest() @@ -104595,8 +104735,9 @@ def test_list_key_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104659,18 +104800,20 @@ def test_list_key_events_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_key_events" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_key_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_key_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_key_events" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_key_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_key_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -104728,8 +104871,9 @@ def test_get_display_video360_advertiser_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104796,20 +104940,22 @@ def test_get_display_video360_advertiser_link_rest_interceptors(null_interceptor ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_display_video360_advertiser_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_display_video360_advertiser_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_display_video360_advertiser_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_display_video360_advertiser_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_display_video360_advertiser_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_display_video360_advertiser_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -104867,8 +105013,9 @@ def test_list_display_video360_advertiser_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -104933,20 +105080,22 @@ def test_list_display_video360_advertiser_links_rest_interceptors(null_intercept ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_display_video360_advertiser_links", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_display_video360_advertiser_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_display_video360_advertiser_links", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_display_video360_advertiser_links", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_display_video360_advertiser_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_display_video360_advertiser_links", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -105006,8 +105155,9 @@ def test_create_display_video360_advertiser_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -105157,20 +105307,22 @@ def test_create_display_video360_advertiser_link_rest_interceptors(null_intercep ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_display_video360_advertiser_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_display_video360_advertiser_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_display_video360_advertiser_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_display_video360_advertiser_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_display_video360_advertiser_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_display_video360_advertiser_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -105228,8 +105380,9 @@ def test_delete_display_video360_advertiser_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -105286,14 +105439,14 @@ def test_delete_display_video360_advertiser_link_rest_interceptors(null_intercep ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_display_video360_advertiser_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_display_video360_advertiser_link", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteDisplayVideo360AdvertiserLinkRequest.pb( analytics_admin.DeleteDisplayVideo360AdvertiserLinkRequest() @@ -105342,8 +105495,9 @@ def test_update_display_video360_advertiser_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -105497,20 +105651,22 @@ def test_update_display_video360_advertiser_link_rest_interceptors(null_intercep ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_display_video360_advertiser_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_display_video360_advertiser_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_display_video360_advertiser_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_display_video360_advertiser_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_display_video360_advertiser_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_display_video360_advertiser_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -105570,8 +105726,9 @@ def test_get_display_video360_advertiser_link_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -105644,20 +105801,22 @@ def test_get_display_video360_advertiser_link_proposal_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_display_video360_advertiser_link_proposal", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_display_video360_advertiser_link_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_display_video360_advertiser_link_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_display_video360_advertiser_link_proposal", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_display_video360_advertiser_link_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_display_video360_advertiser_link_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -105715,8 +105874,9 @@ def test_list_display_video360_advertiser_link_proposals_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -105789,20 +105949,22 @@ def test_list_display_video360_advertiser_link_proposals_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_display_video360_advertiser_link_proposals", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_display_video360_advertiser_link_proposals_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_display_video360_advertiser_link_proposals", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_display_video360_advertiser_link_proposals", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_display_video360_advertiser_link_proposals_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_display_video360_advertiser_link_proposals", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -105866,8 +106028,9 @@ def test_create_display_video360_advertiser_link_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -106038,20 +106201,22 @@ def test_create_display_video360_advertiser_link_proposal_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_display_video360_advertiser_link_proposal", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_display_video360_advertiser_link_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_display_video360_advertiser_link_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_display_video360_advertiser_link_proposal", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_display_video360_advertiser_link_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_display_video360_advertiser_link_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -106113,8 +106278,9 @@ def test_delete_display_video360_advertiser_link_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -106177,14 +106343,14 @@ def test_delete_display_video360_advertiser_link_proposal_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_display_video360_advertiser_link_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_display_video360_advertiser_link_proposal", + ) as pre, + ): pre.assert_not_called() pb_message = ( analytics_admin.DeleteDisplayVideo360AdvertiserLinkProposalRequest.pb( @@ -106233,8 +106399,9 @@ def test_approve_display_video360_advertiser_link_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -106308,20 +106475,22 @@ def test_approve_display_video360_advertiser_link_proposal_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_approve_display_video360_advertiser_link_proposal", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_approve_display_video360_advertiser_link_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_approve_display_video360_advertiser_link_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_approve_display_video360_advertiser_link_proposal", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_approve_display_video360_advertiser_link_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_approve_display_video360_advertiser_link_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -106385,8 +106554,9 @@ def test_cancel_display_video360_advertiser_link_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -106461,20 +106631,22 @@ def test_cancel_display_video360_advertiser_link_proposal_rest_interceptors( ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_cancel_display_video360_advertiser_link_proposal", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_cancel_display_video360_advertiser_link_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_cancel_display_video360_advertiser_link_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_cancel_display_video360_advertiser_link_proposal", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_cancel_display_video360_advertiser_link_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_cancel_display_video360_advertiser_link_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -106534,8 +106706,9 @@ def test_create_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -106685,18 +106858,22 @@ def test_create_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_custom_dimension" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_custom_dimension_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_custom_dimension", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_custom_dimension_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_custom_dimension", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -106751,8 +106928,9 @@ def test_update_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -106904,18 +107082,22 @@ def test_update_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_custom_dimension" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_custom_dimension_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_custom_dimension", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_custom_dimension_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_custom_dimension", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -106968,8 +107150,9 @@ def test_list_custom_dimensions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107032,18 +107215,22 @@ def test_list_custom_dimensions_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_custom_dimensions" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_custom_dimensions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_custom_dimensions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_custom_dimensions", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_custom_dimensions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_custom_dimensions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -107101,8 +107288,9 @@ def test_archive_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107159,13 +107347,14 @@ def test_archive_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_archive_custom_dimension", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.ArchiveCustomDimensionRequest.pb( analytics_admin.ArchiveCustomDimensionRequest() @@ -107210,8 +107399,9 @@ def test_get_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107284,18 +107474,20 @@ def test_get_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_dimension" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_custom_dimension_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_dimension" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_custom_dimension_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_dimension" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -107348,8 +107540,9 @@ def test_create_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107504,18 +107697,20 @@ def test_create_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_custom_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_custom_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_custom_metric" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_custom_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_custom_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -107570,8 +107765,9 @@ def test_update_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107728,18 +107924,20 @@ def test_update_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_custom_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_custom_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_custom_metric" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_custom_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_custom_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -107792,8 +107990,9 @@ def test_list_custom_metrics_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107856,18 +108055,20 @@ def test_list_custom_metrics_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_custom_metrics" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_custom_metrics_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_custom_metrics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_custom_metrics" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_custom_metrics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_custom_metrics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -107925,8 +108126,9 @@ def test_archive_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -107983,13 +108185,13 @@ def test_archive_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_custom_metric" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.ArchiveCustomMetricRequest.pb( analytics_admin.ArchiveCustomMetricRequest() @@ -108034,8 +108236,9 @@ def test_get_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -108114,18 +108317,20 @@ def test_get_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_custom_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_metric" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_custom_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -108178,8 +108383,9 @@ def test_get_data_retention_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -108254,20 +108460,22 @@ def test_get_data_retention_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_retention_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_retention_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_data_retention_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_retention_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_retention_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_data_retention_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -108324,8 +108532,9 @@ def test_update_data_retention_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -108479,20 +108688,22 @@ def test_update_data_retention_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_retention_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_retention_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_data_retention_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_retention_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_retention_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_data_retention_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -108547,8 +108758,9 @@ def test_create_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -108702,18 +108914,20 @@ def test_create_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_data_stream" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_data_stream_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_data_stream" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_data_stream_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_data_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -108766,8 +108980,9 @@ def test_delete_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -108824,13 +109039,13 @@ def test_delete_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_data_stream" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteDataStreamRequest.pb( analytics_admin.DeleteDataStreamRequest() @@ -108875,8 +109090,9 @@ def test_update_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -109030,18 +109246,20 @@ def test_update_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_data_stream" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_stream_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_data_stream" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_stream_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_data_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -109094,8 +109312,9 @@ def test_list_data_streams_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -109158,18 +109377,20 @@ def test_list_data_streams_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_data_streams" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_data_streams_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_data_streams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_data_streams" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_data_streams_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_data_streams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -109227,8 +109448,9 @@ def test_get_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -109295,18 +109517,20 @@ def test_get_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_data_stream" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_stream_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_data_stream" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_stream_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_data_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -109357,8 +109581,9 @@ def test_get_audience_rest_bad_request(request_type=analytics_admin.GetAudienceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -109434,18 +109659,20 @@ def test_get_audience_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_audience" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_audience_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_audience" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_audience" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_audience_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_audience" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -109498,8 +109725,9 @@ def test_list_audiences_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -109562,18 +109790,20 @@ def test_list_audiences_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_audiences" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_audiences_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_audiences" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_audiences" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_audiences_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_audiences" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -109631,8 +109861,9 @@ def test_create_audience_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -109836,18 +110067,20 @@ def test_create_audience_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_audience" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_audience_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_audience" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_audience" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_audience_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_audience" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -109900,8 +110133,9 @@ def test_update_audience_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -110105,18 +110339,20 @@ def test_update_audience_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_audience" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_audience_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_audience" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_audience" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_audience_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_audience" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -110169,8 +110405,9 @@ def test_archive_audience_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -110227,13 +110464,13 @@ def test_archive_audience_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_audience" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_audience" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.ArchiveAudienceRequest.pb( analytics_admin.ArchiveAudienceRequest() @@ -110278,8 +110515,9 @@ def test_get_search_ads360_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -110346,18 +110584,22 @@ def test_get_search_ads360_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_search_ads360_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_search_ads360_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_search_ads360_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_search_ads360_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_search_ads360_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_search_ads360_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -110410,8 +110652,9 @@ def test_list_search_ads360_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -110474,18 +110717,22 @@ def test_list_search_ads360_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_search_ads360_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_search_ads360_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_search_ads360_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_search_ads360_links", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_search_ads360_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_search_ads360_links", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -110543,8 +110790,9 @@ def test_create_search_ads360_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -110689,19 +110937,22 @@ def test_create_search_ads360_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_search_ads360_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_search_ads360_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_search_ads360_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_search_ads360_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_search_ads360_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_search_ads360_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -110754,8 +111005,9 @@ def test_delete_search_ads360_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -110812,13 +111064,14 @@ def test_delete_search_ads360_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_search_ads360_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_search_ads360_link", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteSearchAds360LinkRequest.pb( analytics_admin.DeleteSearchAds360LinkRequest() @@ -110865,8 +111118,9 @@ def test_update_search_ads360_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -111013,19 +111267,22 @@ def test_update_search_ads360_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_search_ads360_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_search_ads360_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_search_ads360_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_search_ads360_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_search_ads360_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_search_ads360_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -111078,8 +111335,9 @@ def test_get_attribution_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -111162,18 +111420,22 @@ def test_get_attribution_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_attribution_settings" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_attribution_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_attribution_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_attribution_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_attribution_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_attribution_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -111230,8 +111492,9 @@ def test_update_attribution_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -111394,20 +111657,22 @@ def test_update_attribution_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_attribution_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_attribution_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_attribution_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_attribution_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_attribution_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_attribution_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -111462,8 +111727,9 @@ def test_run_access_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -111526,18 +111792,20 @@ def test_run_access_report_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_run_access_report" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_run_access_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_run_access_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_run_access_report" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_run_access_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_run_access_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -111595,8 +111863,9 @@ def test_create_access_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -111736,18 +112005,21 @@ def test_create_access_binding_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_access_binding" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_access_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_access_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_access_binding", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_access_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_access_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -111800,8 +112072,9 @@ def test_get_access_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -111867,18 +112140,20 @@ def test_get_access_binding_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_access_binding" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_access_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_access_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_access_binding" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_access_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_access_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -111933,8 +112208,9 @@ def test_update_access_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112076,18 +112352,21 @@ def test_update_access_binding_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_access_binding" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_access_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_access_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_access_binding", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_access_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_access_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -112140,8 +112419,9 @@ def test_delete_access_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112198,13 +112478,13 @@ def test_delete_access_binding_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_access_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_access_binding" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteAccessBindingRequest.pb( analytics_admin.DeleteAccessBindingRequest() @@ -112249,8 +112529,9 @@ def test_list_access_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112313,18 +112594,20 @@ def test_list_access_bindings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_access_bindings" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_access_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_access_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_access_bindings" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_access_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_access_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -112382,8 +112665,9 @@ def test_batch_create_access_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112445,20 +112729,22 @@ def test_batch_create_access_bindings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_batch_create_access_bindings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_batch_create_access_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_batch_create_access_bindings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_batch_create_access_bindings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_batch_create_access_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_batch_create_access_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -112516,8 +112802,9 @@ def test_batch_get_access_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112577,19 +112864,22 @@ def test_batch_get_access_bindings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_batch_get_access_bindings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_batch_get_access_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_batch_get_access_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_batch_get_access_bindings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_batch_get_access_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_batch_get_access_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -112647,8 +112937,9 @@ def test_batch_update_access_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112710,20 +113001,22 @@ def test_batch_update_access_bindings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_batch_update_access_bindings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_batch_update_access_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_batch_update_access_bindings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_batch_update_access_bindings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_batch_update_access_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_batch_update_access_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -112781,8 +113074,9 @@ def test_batch_delete_access_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112839,14 +113133,14 @@ def test_batch_delete_access_bindings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_batch_delete_access_bindings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_batch_delete_access_bindings", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.BatchDeleteAccessBindingsRequest.pb( analytics_admin.BatchDeleteAccessBindingsRequest() @@ -112891,8 +113185,9 @@ def test_get_expanded_data_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -112963,18 +113258,21 @@ def test_get_expanded_data_set_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_expanded_data_set" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_expanded_data_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_expanded_data_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_expanded_data_set", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_expanded_data_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_expanded_data_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -113029,8 +113327,9 @@ def test_list_expanded_data_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -113093,18 +113392,22 @@ def test_list_expanded_data_sets_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_expanded_data_sets" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_expanded_data_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_expanded_data_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_expanded_data_sets", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_expanded_data_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_expanded_data_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -113162,8 +113465,9 @@ def test_create_expanded_data_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -113327,18 +113631,22 @@ def test_create_expanded_data_set_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_expanded_data_set" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_expanded_data_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_expanded_data_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_expanded_data_set", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_expanded_data_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_expanded_data_set", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -113398,8 +113706,9 @@ def test_update_expanded_data_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -113565,18 +113874,22 @@ def test_update_expanded_data_set_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_expanded_data_set" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_expanded_data_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_expanded_data_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_expanded_data_set", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_expanded_data_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_expanded_data_set", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -113634,8 +113947,9 @@ def test_delete_expanded_data_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -113692,13 +114006,14 @@ def test_delete_expanded_data_set_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_expanded_data_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_expanded_data_set", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteExpandedDataSetRequest.pb( analytics_admin.DeleteExpandedDataSetRequest() @@ -113743,8 +114058,9 @@ def test_get_channel_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -113815,18 +114131,20 @@ def test_get_channel_group_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_channel_group" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_channel_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_channel_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_channel_group" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_channel_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_channel_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -113879,8 +114197,9 @@ def test_list_channel_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -113943,18 +114262,20 @@ def test_list_channel_groups_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_channel_groups" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_channel_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_channel_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_channel_groups" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_channel_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_channel_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -114012,8 +114333,9 @@ def test_create_channel_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -114175,18 +114497,20 @@ def test_create_channel_group_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_channel_group" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_channel_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_channel_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_channel_group" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_channel_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_channel_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -114243,8 +114567,9 @@ def test_update_channel_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -114408,18 +114733,20 @@ def test_update_channel_group_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_channel_group" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_channel_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_channel_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_channel_group" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_channel_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_channel_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -114474,8 +114801,9 @@ def test_delete_channel_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -114532,13 +114860,13 @@ def test_delete_channel_group_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_channel_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_channel_group" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteChannelGroupRequest.pb( analytics_admin.DeleteChannelGroupRequest() @@ -114583,8 +114911,9 @@ def test_create_big_query_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -114742,18 +115071,21 @@ def test_create_big_query_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_big_query_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_big_query_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_big_query_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_big_query_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_big_query_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_big_query_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -114806,8 +115138,9 @@ def test_get_big_query_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -114886,18 +115219,20 @@ def test_get_big_query_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_big_query_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_big_query_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_big_query_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_big_query_link" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_big_query_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_big_query_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -114950,8 +115285,9 @@ def test_list_big_query_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -115014,18 +115350,20 @@ def test_list_big_query_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_big_query_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_big_query_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_big_query_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_big_query_links" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_big_query_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_big_query_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -115083,8 +115421,9 @@ def test_delete_big_query_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -115141,13 +115480,13 @@ def test_delete_big_query_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_big_query_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_big_query_link" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteBigQueryLinkRequest.pb( analytics_admin.DeleteBigQueryLinkRequest() @@ -115194,8 +115533,9 @@ def test_update_big_query_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -115355,18 +115695,21 @@ def test_update_big_query_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_big_query_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_big_query_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_big_query_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_big_query_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_big_query_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_big_query_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -115421,8 +115764,9 @@ def test_get_enhanced_measurement_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -115507,20 +115851,22 @@ def test_get_enhanced_measurement_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_enhanced_measurement_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_enhanced_measurement_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_enhanced_measurement_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_enhanced_measurement_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_enhanced_measurement_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_enhanced_measurement_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -115582,8 +115928,9 @@ def test_update_enhanced_measurement_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -115758,20 +116105,22 @@ def test_update_enhanced_measurement_settings_rest_interceptors(null_interceptor ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_enhanced_measurement_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_enhanced_measurement_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_enhanced_measurement_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_enhanced_measurement_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_enhanced_measurement_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_enhanced_measurement_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -115829,8 +116178,9 @@ def test_get_ad_sense_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -115895,18 +116245,20 @@ def test_get_ad_sense_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_ad_sense_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_ad_sense_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_ad_sense_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_ad_sense_link" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_ad_sense_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_ad_sense_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -115959,8 +116311,9 @@ def test_create_ad_sense_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -116096,18 +116449,20 @@ def test_create_ad_sense_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_ad_sense_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_ad_sense_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_ad_sense_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_ad_sense_link" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_ad_sense_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_ad_sense_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -116160,8 +116515,9 @@ def test_delete_ad_sense_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -116218,13 +116574,13 @@ def test_delete_ad_sense_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_ad_sense_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_ad_sense_link" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteAdSenseLinkRequest.pb( analytics_admin.DeleteAdSenseLinkRequest() @@ -116269,8 +116625,9 @@ def test_list_ad_sense_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -116333,18 +116690,20 @@ def test_list_ad_sense_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_ad_sense_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_ad_sense_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_ad_sense_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_ad_sense_links" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_ad_sense_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_ad_sense_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -116404,8 +116763,9 @@ def test_get_event_create_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -116474,18 +116834,21 @@ def test_get_event_create_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_event_create_rule" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_event_create_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_event_create_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_event_create_rule", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_event_create_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_event_create_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -116543,8 +116906,9 @@ def test_list_event_create_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -116607,18 +116971,22 @@ def test_list_event_create_rules_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_event_create_rules" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_event_create_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_event_create_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_event_create_rules", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_event_create_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_event_create_rules", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -116676,8 +117044,9 @@ def test_create_event_create_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -116829,18 +117198,22 @@ def test_create_event_create_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_event_create_rule" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_event_create_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_event_create_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_event_create_rule", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_event_create_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_event_create_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -116902,8 +117275,9 @@ def test_update_event_create_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -117059,18 +117433,22 @@ def test_update_event_create_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_event_create_rule" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_event_create_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_event_create_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_event_create_rule", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_event_create_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_event_create_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -117130,8 +117508,9 @@ def test_delete_event_create_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -117190,13 +117569,14 @@ def test_delete_event_create_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_event_create_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_event_create_rule", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteEventCreateRuleRequest.pb( analytics_admin.DeleteEventCreateRuleRequest() @@ -117243,8 +117623,9 @@ def test_get_event_edit_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -117313,18 +117694,20 @@ def test_get_event_edit_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_event_edit_rule" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_event_edit_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_event_edit_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_event_edit_rule" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_event_edit_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_event_edit_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -117382,8 +117765,9 @@ def test_list_event_edit_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -117446,18 +117830,21 @@ def test_list_event_edit_rules_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_event_edit_rules" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_event_edit_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_event_edit_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_event_edit_rules", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_event_edit_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_event_edit_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -117515,8 +117902,9 @@ def test_create_event_edit_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -117668,18 +118056,22 @@ def test_create_event_edit_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_event_edit_rule" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_event_edit_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_event_edit_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_event_edit_rule", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_event_edit_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_event_edit_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -117741,8 +118133,9 @@ def test_update_event_edit_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -117898,18 +118291,22 @@ def test_update_event_edit_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_event_edit_rule" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_event_edit_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_event_edit_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_event_edit_rule", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_event_edit_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_event_edit_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -117969,8 +118366,9 @@ def test_delete_event_edit_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118029,13 +118427,14 @@ def test_delete_event_edit_rule_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_event_edit_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_event_edit_rule", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteEventEditRuleRequest.pb( analytics_admin.DeleteEventEditRuleRequest() @@ -118080,8 +118479,9 @@ def test_reorder_event_edit_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118138,13 +118538,14 @@ def test_reorder_event_edit_rules_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_reorder_event_edit_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_reorder_event_edit_rules", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.ReorderEventEditRulesRequest.pb( analytics_admin.ReorderEventEditRulesRequest() @@ -118193,8 +118594,9 @@ def test_update_data_redaction_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118347,20 +118749,22 @@ def test_update_data_redaction_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_redaction_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_redaction_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_data_redaction_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_redaction_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_redaction_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_data_redaction_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -118417,8 +118821,9 @@ def test_get_data_redaction_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118489,20 +118894,22 @@ def test_get_data_redaction_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_redaction_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_redaction_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_data_redaction_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_redaction_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_redaction_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_data_redaction_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -118557,8 +118964,9 @@ def test_get_calculated_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118639,18 +119047,21 @@ def test_get_calculated_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_calculated_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_calculated_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_calculated_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_calculated_metric", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_calculated_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_calculated_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -118703,8 +119114,9 @@ def test_create_calculated_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118864,18 +119276,22 @@ def test_create_calculated_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_calculated_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_calculated_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_calculated_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_calculated_metric", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_calculated_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_calculated_metric", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -118928,8 +119344,9 @@ def test_list_calculated_metrics_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -118992,18 +119409,22 @@ def test_list_calculated_metrics_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_calculated_metrics" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_calculated_metrics_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_calculated_metrics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_calculated_metrics", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_calculated_metrics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_calculated_metrics", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -119063,8 +119484,9 @@ def test_update_calculated_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -119226,18 +119648,22 @@ def test_update_calculated_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_calculated_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_calculated_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_calculated_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_calculated_metric", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_calculated_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_calculated_metric", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -119290,8 +119716,9 @@ def test_delete_calculated_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -119348,13 +119775,14 @@ def test_delete_calculated_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_calculated_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_calculated_metric", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteCalculatedMetricRequest.pb( analytics_admin.DeleteCalculatedMetricRequest() @@ -119399,8 +119827,9 @@ def test_create_rollup_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -119460,18 +119889,22 @@ def test_create_rollup_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_rollup_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_rollup_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_rollup_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_rollup_property", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_rollup_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_rollup_property", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -119529,8 +119962,9 @@ def test_get_rollup_property_source_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -119595,20 +120029,22 @@ def test_get_rollup_property_source_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_rollup_property_source_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_rollup_property_source_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_rollup_property_source_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_rollup_property_source_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_rollup_property_source_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_rollup_property_source_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -119663,8 +120099,9 @@ def test_list_rollup_property_source_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -119729,20 +120166,22 @@ def test_list_rollup_property_source_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_rollup_property_source_links", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_rollup_property_source_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_rollup_property_source_links", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_rollup_property_source_links", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_rollup_property_source_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_rollup_property_source_links", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -119800,8 +120239,9 @@ def test_create_rollup_property_source_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -119943,20 +120383,22 @@ def test_create_rollup_property_source_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_rollup_property_source_link", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_rollup_property_source_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_rollup_property_source_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_rollup_property_source_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_rollup_property_source_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_rollup_property_source_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -120011,8 +120453,9 @@ def test_delete_rollup_property_source_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -120069,14 +120512,14 @@ def test_delete_rollup_property_source_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_rollup_property_source_link", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_rollup_property_source_link", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteRollupPropertySourceLinkRequest.pb( analytics_admin.DeleteRollupPropertySourceLinkRequest() @@ -120121,8 +120564,9 @@ def test_provision_subproperty_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -120182,18 +120626,21 @@ def test_provision_subproperty_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_provision_subproperty" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_provision_subproperty_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_provision_subproperty" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_provision_subproperty", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_provision_subproperty_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_provision_subproperty" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -120251,8 +120698,9 @@ def test_create_subproperty_event_filter_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -120412,20 +120860,22 @@ def test_create_subproperty_event_filter_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_subproperty_event_filter", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_subproperty_event_filter_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_subproperty_event_filter", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_subproperty_event_filter", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_subproperty_event_filter_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_subproperty_event_filter", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -120483,8 +120933,9 @@ def test_get_subproperty_event_filter_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -120549,20 +121000,22 @@ def test_get_subproperty_event_filter_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_subproperty_event_filter", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_subproperty_event_filter_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_subproperty_event_filter", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_subproperty_event_filter", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_subproperty_event_filter_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_subproperty_event_filter", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -120620,8 +121073,9 @@ def test_list_subproperty_event_filters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -120686,20 +121140,22 @@ def test_list_subproperty_event_filters_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_subproperty_event_filters", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_subproperty_event_filters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_subproperty_event_filters", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_subproperty_event_filters", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_subproperty_event_filters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_subproperty_event_filters", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -120761,8 +121217,9 @@ def test_update_subproperty_event_filter_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -120926,20 +121383,22 @@ def test_update_subproperty_event_filter_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_subproperty_event_filter", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_subproperty_event_filter_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_subproperty_event_filter", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_subproperty_event_filter", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_subproperty_event_filter_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_subproperty_event_filter", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -120997,8 +121456,9 @@ def test_delete_subproperty_event_filter_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -121055,14 +121515,14 @@ def test_delete_subproperty_event_filter_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_subproperty_event_filter", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_subproperty_event_filter", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteSubpropertyEventFilterRequest.pb( analytics_admin.DeleteSubpropertyEventFilterRequest() @@ -121107,8 +121567,9 @@ def test_create_reporting_data_annotation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -121261,20 +121722,22 @@ def test_create_reporting_data_annotation_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_reporting_data_annotation", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_reporting_data_annotation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_reporting_data_annotation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_reporting_data_annotation", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_reporting_data_annotation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_reporting_data_annotation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -121329,8 +121792,9 @@ def test_get_reporting_data_annotation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -121401,20 +121865,22 @@ def test_get_reporting_data_annotation_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_reporting_data_annotation", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_reporting_data_annotation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_reporting_data_annotation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_reporting_data_annotation", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_reporting_data_annotation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_reporting_data_annotation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -121469,8 +121935,9 @@ def test_list_reporting_data_annotations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -121535,20 +122002,22 @@ def test_list_reporting_data_annotations_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_reporting_data_annotations", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_reporting_data_annotations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_reporting_data_annotations", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_reporting_data_annotations", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_reporting_data_annotations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_reporting_data_annotations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -121610,8 +122079,9 @@ def test_update_reporting_data_annotation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -121768,20 +122238,22 @@ def test_update_reporting_data_annotation_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_reporting_data_annotation", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_reporting_data_annotation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_reporting_data_annotation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_reporting_data_annotation", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_reporting_data_annotation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_reporting_data_annotation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -121836,8 +122308,9 @@ def test_delete_reporting_data_annotation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -121894,14 +122367,14 @@ def test_delete_reporting_data_annotation_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_reporting_data_annotation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_reporting_data_annotation", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteReportingDataAnnotationRequest.pb( analytics_admin.DeleteReportingDataAnnotationRequest() @@ -121946,8 +122419,9 @@ def test_submit_user_deletion_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -122007,18 +122481,20 @@ def test_submit_user_deletion_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_submit_user_deletion" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_submit_user_deletion_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_submit_user_deletion" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_submit_user_deletion" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_submit_user_deletion_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_submit_user_deletion" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -122076,8 +122552,9 @@ def test_list_subproperty_sync_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -122142,20 +122619,22 @@ def test_list_subproperty_sync_configs_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_subproperty_sync_configs", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_subproperty_sync_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_subproperty_sync_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_subproperty_sync_configs", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_subproperty_sync_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_subproperty_sync_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -122217,8 +122696,9 @@ def test_update_subproperty_sync_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -122368,20 +122848,22 @@ def test_update_subproperty_sync_config_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_subproperty_sync_config", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_subproperty_sync_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_subproperty_sync_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_subproperty_sync_config", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_subproperty_sync_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_subproperty_sync_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -122436,8 +122918,9 @@ def test_get_subproperty_sync_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -122507,20 +122990,22 @@ def test_get_subproperty_sync_config_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_subproperty_sync_config", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_subproperty_sync_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_subproperty_sync_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_subproperty_sync_config", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_subproperty_sync_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_subproperty_sync_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -122575,8 +123060,9 @@ def test_get_reporting_identity_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -122644,20 +123130,22 @@ def test_get_reporting_identity_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_reporting_identity_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_reporting_identity_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_reporting_identity_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_reporting_identity_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_reporting_identity_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_reporting_identity_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -126280,11 +126768,14 @@ def test_analytics_admin_service_base_transport(): def test_analytics_admin_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsAdminServiceTransport( @@ -126306,9 +126797,12 @@ def test_analytics_admin_service_base_transport_with_credentials_file(): def test_analytics_admin_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsAdminServiceTransport() @@ -126392,11 +126886,12 @@ def test_analytics_admin_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-analytics-admin/tests/unit/gapic/admin_v1beta/test_analytics_admin_service.py b/packages/google-analytics-admin/tests/unit/gapic/admin_v1beta/test_analytics_admin_service.py index 811581a0632d..64d846cc584f 100644 --- a/packages/google-analytics-admin/tests/unit/gapic/admin_v1beta/test_analytics_admin_service.py +++ b/packages/google-analytics-admin/tests/unit/gapic/admin_v1beta/test_analytics_admin_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AnalyticsAdminServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): AnalyticsAdminServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AnalyticsAdminServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1349,11 +1354,13 @@ def test_analytics_admin_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -34803,8 +34810,9 @@ def test_get_account_rest_bad_request(request_type=analytics_admin.GetAccountReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34875,18 +34883,20 @@ def test_get_account_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_account" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_account" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34939,8 +34949,9 @@ def test_list_accounts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35003,18 +35014,20 @@ def test_list_accounts_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_accounts" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_accounts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_accounts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_accounts" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_accounts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_accounts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35072,8 +35085,9 @@ def test_delete_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35130,13 +35144,13 @@ def test_delete_account_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_account" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteAccountRequest.pb( analytics_admin.DeleteAccountRequest() @@ -35181,8 +35195,9 @@ def test_update_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35329,18 +35344,20 @@ def test_update_account_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_account" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_account" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35393,8 +35410,9 @@ def test_provision_account_ticket_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35457,18 +35475,22 @@ def test_provision_account_ticket_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_provision_account_ticket" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_provision_account_ticket_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_provision_account_ticket" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_provision_account_ticket", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_provision_account_ticket_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_provision_account_ticket", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35526,8 +35548,9 @@ def test_list_account_summaries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35590,18 +35613,22 @@ def test_list_account_summaries_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_account_summaries" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_account_summaries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_account_summaries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_account_summaries", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_account_summaries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_account_summaries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35657,8 +35684,9 @@ def test_get_property_rest_bad_request(request_type=analytics_admin.GetPropertyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35737,18 +35765,20 @@ def test_get_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35801,8 +35831,9 @@ def test_list_properties_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35865,18 +35896,20 @@ def test_list_properties_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_properties" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_properties_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_properties" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_properties" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_properties_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_properties" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35934,8 +35967,9 @@ def test_create_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36096,18 +36130,20 @@ def test_create_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36160,8 +36196,9 @@ def test_delete_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36240,18 +36277,20 @@ def test_delete_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_delete_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_delete_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_delete_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_delete_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36304,8 +36343,9 @@ def test_update_property_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36466,18 +36506,20 @@ def test_update_property_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_property" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_property_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_property" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_property" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_property_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_property" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36530,8 +36572,9 @@ def test_create_firebase_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36668,18 +36711,20 @@ def test_create_firebase_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_firebase_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_firebase_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_firebase_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_firebase_link" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_firebase_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_firebase_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36732,8 +36777,9 @@ def test_delete_firebase_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36790,13 +36836,13 @@ def test_delete_firebase_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_firebase_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_firebase_link" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteFirebaseLinkRequest.pb( analytics_admin.DeleteFirebaseLinkRequest() @@ -36841,8 +36887,9 @@ def test_list_firebase_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36905,18 +36952,20 @@ def test_list_firebase_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_firebase_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_firebase_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_firebase_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_firebase_links" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_firebase_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_firebase_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36974,8 +37023,9 @@ def test_create_google_ads_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37122,18 +37172,22 @@ def test_create_google_ads_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_google_ads_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_google_ads_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_google_ads_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_google_ads_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_google_ads_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_google_ads_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37188,8 +37242,9 @@ def test_update_google_ads_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37338,18 +37393,22 @@ def test_update_google_ads_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_google_ads_link" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_google_ads_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_google_ads_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_google_ads_link", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_google_ads_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_google_ads_link", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37402,8 +37461,9 @@ def test_delete_google_ads_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37460,13 +37520,14 @@ def test_delete_google_ads_link_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_google_ads_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_google_ads_link", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteGoogleAdsLinkRequest.pb( analytics_admin.DeleteGoogleAdsLinkRequest() @@ -37511,8 +37572,9 @@ def test_list_google_ads_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37575,18 +37637,21 @@ def test_list_google_ads_links_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_google_ads_links" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_google_ads_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_google_ads_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_google_ads_links", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_google_ads_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_google_ads_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37644,8 +37709,9 @@ def test_get_data_sharing_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37718,19 +37784,22 @@ def test_get_data_sharing_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_sharing_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_sharing_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_data_sharing_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_sharing_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_sharing_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_data_sharing_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37787,8 +37856,9 @@ def test_get_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37857,20 +37927,22 @@ def test_get_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_measurement_protocol_secret", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_measurement_protocol_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_measurement_protocol_secret", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_measurement_protocol_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37928,8 +38000,9 @@ def test_list_measurement_protocol_secrets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37994,20 +38067,22 @@ def test_list_measurement_protocol_secrets_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_measurement_protocol_secrets", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_measurement_protocol_secrets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_list_measurement_protocol_secrets", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_measurement_protocol_secrets", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_measurement_protocol_secrets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_measurement_protocol_secrets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38065,8 +38140,9 @@ def test_create_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38211,20 +38287,22 @@ def test_create_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_measurement_protocol_secret", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_measurement_protocol_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_create_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_measurement_protocol_secret", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_measurement_protocol_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38284,8 +38362,9 @@ def test_delete_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38344,14 +38423,14 @@ def test_delete_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_delete_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteMeasurementProtocolSecretRequest.pb( analytics_admin.DeleteMeasurementProtocolSecretRequest() @@ -38400,8 +38479,9 @@ def test_update_measurement_protocol_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38550,20 +38630,22 @@ def test_update_measurement_protocol_secret_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_measurement_protocol_secret", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_measurement_protocol_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_measurement_protocol_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_measurement_protocol_secret", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_measurement_protocol_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_measurement_protocol_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38621,8 +38703,9 @@ def test_acknowledge_user_data_collection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38684,20 +38767,22 @@ def test_acknowledge_user_data_collection_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_acknowledge_user_data_collection", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_acknowledge_user_data_collection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_acknowledge_user_data_collection", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_acknowledge_user_data_collection", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_acknowledge_user_data_collection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_acknowledge_user_data_collection", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38755,8 +38840,9 @@ def test_search_change_history_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38821,20 +38907,22 @@ def test_search_change_history_events_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_search_change_history_events", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_search_change_history_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_search_change_history_events", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_search_change_history_events", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_search_change_history_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_search_change_history_events", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38892,8 +38980,9 @@ def test_create_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39048,18 +39137,22 @@ def test_create_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_conversion_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_conversion_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_conversion_event", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_conversion_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_conversion_event", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39114,8 +39207,9 @@ def test_update_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39272,18 +39366,22 @@ def test_update_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_conversion_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_conversion_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_conversion_event", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_conversion_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_conversion_event", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39336,8 +39434,9 @@ def test_get_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39411,18 +39510,20 @@ def test_get_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_conversion_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_conversion_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_conversion_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_conversion_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_conversion_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39475,8 +39576,9 @@ def test_delete_conversion_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39533,13 +39635,14 @@ def test_delete_conversion_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_conversion_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_delete_conversion_event", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteConversionEventRequest.pb( analytics_admin.DeleteConversionEventRequest() @@ -39584,8 +39687,9 @@ def test_list_conversion_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39648,18 +39752,22 @@ def test_list_conversion_events_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_conversion_events" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_conversion_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_conversion_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_conversion_events", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_conversion_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_conversion_events", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39717,8 +39825,9 @@ def test_create_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39868,18 +39977,20 @@ def test_create_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_key_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_key_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_key_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_key_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_key_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39932,8 +40043,9 @@ def test_update_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40083,18 +40195,20 @@ def test_update_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_key_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_key_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_key_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_key_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_key_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40147,8 +40261,9 @@ def test_get_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40219,18 +40334,20 @@ def test_get_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_key_event" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_key_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_key_event" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_key_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_key_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40283,8 +40400,9 @@ def test_delete_key_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40341,13 +40459,13 @@ def test_delete_key_event_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_key_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_key_event" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteKeyEventRequest.pb( analytics_admin.DeleteKeyEventRequest() @@ -40392,8 +40510,9 @@ def test_list_key_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40456,18 +40575,20 @@ def test_list_key_events_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_key_events" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_key_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_key_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_key_events" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_key_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_key_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40525,8 +40646,9 @@ def test_create_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40676,18 +40798,22 @@ def test_create_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_custom_dimension" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_custom_dimension_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_custom_dimension", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_custom_dimension_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_create_custom_dimension", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40742,8 +40868,9 @@ def test_update_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40895,18 +41022,22 @@ def test_update_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_custom_dimension" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_custom_dimension_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_custom_dimension", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_custom_dimension_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_custom_dimension", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40959,8 +41090,9 @@ def test_list_custom_dimensions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41023,18 +41155,22 @@ def test_list_custom_dimensions_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_custom_dimensions" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_custom_dimensions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_custom_dimensions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_custom_dimensions", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_custom_dimensions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_list_custom_dimensions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41092,8 +41228,9 @@ def test_archive_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41150,13 +41287,14 @@ def test_archive_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_archive_custom_dimension", + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.ArchiveCustomDimensionRequest.pb( analytics_admin.ArchiveCustomDimensionRequest() @@ -41201,8 +41339,9 @@ def test_get_custom_dimension_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41275,18 +41414,20 @@ def test_get_custom_dimension_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_dimension" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_custom_dimension_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_dimension" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_dimension" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_custom_dimension_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_dimension" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41339,8 +41480,9 @@ def test_create_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41495,18 +41637,20 @@ def test_create_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_custom_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_custom_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_custom_metric" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_custom_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_custom_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41561,8 +41705,9 @@ def test_update_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41719,18 +41864,20 @@ def test_update_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_custom_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_custom_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_custom_metric" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_custom_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_custom_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41783,8 +41930,9 @@ def test_list_custom_metrics_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41847,18 +41995,20 @@ def test_list_custom_metrics_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_custom_metrics" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_custom_metrics_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_custom_metrics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_custom_metrics" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_custom_metrics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_custom_metrics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41916,8 +42066,9 @@ def test_archive_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41974,13 +42125,13 @@ def test_archive_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_archive_custom_metric" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.ArchiveCustomMetricRequest.pb( analytics_admin.ArchiveCustomMetricRequest() @@ -42025,8 +42176,9 @@ def test_get_custom_metric_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42105,18 +42257,20 @@ def test_get_custom_metric_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_metric" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_custom_metric_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_metric" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_custom_metric" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_custom_metric_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_custom_metric" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42169,8 +42323,9 @@ def test_get_data_retention_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42245,20 +42400,22 @@ def test_get_data_retention_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_retention_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_retention_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_get_data_retention_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_retention_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_retention_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_get_data_retention_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42315,8 +42472,9 @@ def test_update_data_retention_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42470,20 +42628,22 @@ def test_update_data_retention_settings_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_retention_settings", - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_retention_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "pre_update_data_retention_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_retention_settings", + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_retention_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "pre_update_data_retention_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42538,8 +42698,9 @@ def test_create_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42693,18 +42854,20 @@ def test_create_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_create_data_stream" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_create_data_stream_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_create_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_create_data_stream" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_create_data_stream_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_create_data_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42757,8 +42920,9 @@ def test_delete_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42815,13 +42979,13 @@ def test_delete_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_delete_data_stream" + ) as pre, + ): pre.assert_not_called() pb_message = analytics_admin.DeleteDataStreamRequest.pb( analytics_admin.DeleteDataStreamRequest() @@ -42866,8 +43030,9 @@ def test_update_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43021,18 +43186,20 @@ def test_update_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_update_data_stream" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_update_data_stream_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_update_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_update_data_stream" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_update_data_stream_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_update_data_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43085,8 +43252,9 @@ def test_list_data_streams_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43149,18 +43317,20 @@ def test_list_data_streams_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_list_data_streams" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_list_data_streams_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_list_data_streams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_list_data_streams" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_list_data_streams_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_list_data_streams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43218,8 +43388,9 @@ def test_get_data_stream_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43286,18 +43457,20 @@ def test_get_data_stream_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_get_data_stream" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_get_data_stream_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_get_data_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_get_data_stream" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_get_data_stream_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_get_data_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43350,8 +43523,9 @@ def test_run_access_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43414,18 +43588,20 @@ def test_run_access_report_rest_interceptors(null_interceptor): ) client = AnalyticsAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "post_run_access_report" - ) as post, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, - "post_run_access_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnalyticsAdminServiceRestInterceptor, "pre_run_access_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "post_run_access_report" + ) as post, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, + "post_run_access_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnalyticsAdminServiceRestInterceptor, "pre_run_access_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44743,11 +44919,14 @@ def test_analytics_admin_service_base_transport(): def test_analytics_admin_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.analytics.admin_v1beta.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.analytics.admin_v1beta.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsAdminServiceTransport( @@ -44767,9 +44946,12 @@ def test_analytics_admin_service_base_transport_with_credentials_file(): def test_analytics_admin_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.analytics.admin_v1beta.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.analytics.admin_v1beta.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsAdminServiceTransport() @@ -44849,11 +45031,12 @@ def test_analytics_admin_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py index bf99a162538c..ea738ae51608 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> AlphaAnalyticsDataTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py index fc1547067e34..e5a6370766a7 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py @@ -114,7 +114,7 @@ class AlphaAnalyticsDataClient(metaclass=AlphaAnalyticsDataClientMeta): """Google Analytics reporting data service.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -490,7 +494,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -587,7 +591,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -687,7 +691,7 @@ def __init__( self._universe_domain = AlphaAnalyticsDataClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/README.rst b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/README.rst index aada6b24865f..83b2386a3382 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/README.rst +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlphaAnalyticsDataTransport` is the ABC for all transports. -- public child `AlphaAnalyticsDataGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlphaAnalyticsDataGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlphaAnalyticsDataRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlphaAnalyticsDataRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlphaAnalyticsDataTransport`` is the ABC for all transports. + +- public child ``AlphaAnalyticsDataGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlphaAnalyticsDataGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlphaAnalyticsDataRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlphaAnalyticsDataRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py index 626fe9259e3b..1af5bcd61c19 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py index a963d1392308..fea629dfd74f 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py index 7fbb069e2861..fa488e1556d1 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py index 7fde7d0fc110..3c95d9779d7f 100644 --- a/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py +++ b/packages/google-analytics-data/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py @@ -975,6 +975,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlphaAnalyticsDataRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py index 35ab0e689b6a..7ff337ac1488 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> BetaAnalyticsDataTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/client.py b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/client.py index dd34cf31bc7a..f41245af858e 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/client.py +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/client.py @@ -114,7 +114,7 @@ class BetaAnalyticsDataClient(metaclass=BetaAnalyticsDataClientMeta): """Google Analytics reporting data service.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -452,7 +456,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -549,7 +553,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = BetaAnalyticsDataClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/README.rst b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/README.rst index e409a11acb1b..e508eb496c38 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/README.rst +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BetaAnalyticsDataTransport` is the ABC for all transports. -- public child `BetaAnalyticsDataGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BetaAnalyticsDataGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBetaAnalyticsDataRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BetaAnalyticsDataRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BetaAnalyticsDataTransport`` is the ABC for all transports. + +- public child ``BetaAnalyticsDataGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BetaAnalyticsDataGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBetaAnalyticsDataRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BetaAnalyticsDataRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py index 3b2504df2013..0ee93fbfd4b5 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py index 27570e9887c9..e1c09b4b0f56 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py index 24a81044e26f..f09412032ace 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py index 73ff4adcb76c..b714a4f1f601 100644 --- a/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py +++ b/packages/google-analytics-data/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py @@ -796,6 +796,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BetaAnalyticsDataRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-analytics-data/noxfile.py b/packages/google-analytics-data/noxfile.py index ebccfa924472..822b856d247d 100644 --- a/packages/google-analytics-data/noxfile.py +++ b/packages/google-analytics-data/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-analytics-data/setup.py b/packages/google-analytics-data/setup.py index c7cb7550a558..4159dd64f36b 100644 --- a/packages/google-analytics-data/setup.py +++ b/packages/google-analytics-data/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-analytics-data" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-analytics-data/testing/constraints-3.7.txt b/packages/google-analytics-data/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-analytics-data/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-analytics-data/testing/constraints-3.8.txt b/packages/google-analytics-data/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-analytics-data/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-analytics-data/testing/constraints-3.9.txt b/packages/google-analytics-data/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-analytics-data/testing/constraints-3.9.txt +++ b/packages/google-analytics-data/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-analytics-data/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py b/packages/google-analytics-data/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py index 795e573ec6ed..c55650dc959d 100644 --- a/packages/google-analytics-data/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py +++ b/packages/google-analytics-data/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlphaAnalyticsDataClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): AlphaAnalyticsDataClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AlphaAnalyticsDataClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1329,11 +1334,13 @@ def test_alpha_analytics_data_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10334,8 +10341,9 @@ def test_run_funnel_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10398,18 +10406,20 @@ def test_run_funnel_report_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_run_funnel_report" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_run_funnel_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_run_funnel_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_run_funnel_report" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_run_funnel_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_run_funnel_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10467,8 +10477,9 @@ def test_create_audience_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10611,20 +10622,21 @@ def test_create_audience_list_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_create_audience_list" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_create_audience_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_create_audience_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_create_audience_list" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_create_audience_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_create_audience_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10677,8 +10689,9 @@ def test_query_audience_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10741,18 +10754,20 @@ def test_query_audience_list_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_query_audience_list" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_query_audience_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_query_audience_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_query_audience_list" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_query_audience_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_query_audience_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10810,8 +10825,9 @@ def test_sheet_export_audience_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10880,18 +10896,22 @@ def test_sheet_export_audience_list_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_sheet_export_audience_list" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_sheet_export_audience_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_sheet_export_audience_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_sheet_export_audience_list", + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_sheet_export_audience_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "pre_sheet_export_audience_list", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10949,8 +10969,9 @@ def test_get_audience_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11029,18 +11050,20 @@ def test_get_audience_list_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_get_audience_list" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_get_audience_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_get_audience_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_get_audience_list" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_get_audience_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_get_audience_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11095,8 +11118,9 @@ def test_list_audience_lists_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11159,18 +11183,20 @@ def test_list_audience_lists_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_list_audience_lists" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_list_audience_lists_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_list_audience_lists" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_list_audience_lists" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_list_audience_lists_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_list_audience_lists" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11228,8 +11254,9 @@ def test_create_recurring_audience_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11383,20 +11410,22 @@ def test_create_recurring_audience_list_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_create_recurring_audience_list", - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_create_recurring_audience_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "pre_create_recurring_audience_list", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_create_recurring_audience_list", + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_create_recurring_audience_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "pre_create_recurring_audience_list", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11454,8 +11483,9 @@ def test_get_recurring_audience_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11526,18 +11556,22 @@ def test_get_recurring_audience_list_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_get_recurring_audience_list" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_get_recurring_audience_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_get_recurring_audience_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_get_recurring_audience_list", + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_get_recurring_audience_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "pre_get_recurring_audience_list", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11595,8 +11629,9 @@ def test_list_recurring_audience_lists_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11661,20 +11696,22 @@ def test_list_recurring_audience_lists_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_list_recurring_audience_lists", - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_list_recurring_audience_lists_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "pre_list_recurring_audience_lists", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_list_recurring_audience_lists", + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_list_recurring_audience_lists_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "pre_list_recurring_audience_lists", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11732,8 +11769,9 @@ def test_get_property_quotas_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11796,19 +11834,22 @@ def test_get_property_quotas_snapshot_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_get_property_quotas_snapshot", - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_get_property_quotas_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_get_property_quotas_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_get_property_quotas_snapshot", + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_get_property_quotas_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "pre_get_property_quotas_snapshot", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11866,8 +11907,9 @@ def test_create_report_task_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12092,20 +12134,21 @@ def test_create_report_task_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_create_report_task" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_create_report_task_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_create_report_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_create_report_task" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_create_report_task_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_create_report_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12158,8 +12201,9 @@ def test_query_report_task_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12222,18 +12266,20 @@ def test_query_report_task_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_query_report_task" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_query_report_task_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_query_report_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_query_report_task" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_query_report_task_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_query_report_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12291,8 +12337,9 @@ def test_get_report_task_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12355,18 +12402,20 @@ def test_get_report_task_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_get_report_task" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_get_report_task_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_get_report_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_get_report_task" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_get_report_task_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_get_report_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12421,8 +12470,9 @@ def test_list_report_tasks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12485,18 +12535,20 @@ def test_list_report_tasks_rest_interceptors(null_interceptor): ) client = AlphaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_list_report_tasks" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, - "post_list_report_tasks_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_list_report_tasks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_list_report_tasks" + ) as post, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, + "post_list_report_tasks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_list_report_tasks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12944,11 +12996,14 @@ def test_alpha_analytics_data_base_transport(): def test_alpha_analytics_data_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.analytics.data_v1alpha.services.alpha_analytics_data.transports.AlphaAnalyticsDataTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.analytics.data_v1alpha.services.alpha_analytics_data.transports.AlphaAnalyticsDataTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlphaAnalyticsDataTransport( @@ -12971,9 +13026,12 @@ def test_alpha_analytics_data_base_transport_with_credentials_file(): def test_alpha_analytics_data_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.analytics.data_v1alpha.services.alpha_analytics_data.transports.AlphaAnalyticsDataTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.analytics.data_v1alpha.services.alpha_analytics_data.transports.AlphaAnalyticsDataTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlphaAnalyticsDataTransport() @@ -13057,11 +13115,12 @@ def test_alpha_analytics_data_transport_auth_gdch_credentials(transport_class): def test_alpha_analytics_data_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-analytics-data/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py b/packages/google-analytics-data/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py index 6b5548885ea2..437fb7b2725c 100644 --- a/packages/google-analytics-data/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/packages/google-analytics-data/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BetaAnalyticsDataClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): BetaAnalyticsDataClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BetaAnalyticsDataClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1324,11 +1329,13 @@ def test_beta_analytics_data_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6736,8 +6743,9 @@ def test_run_report_rest_bad_request(request_type=analytics_data_api.RunReportRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6802,17 +6810,19 @@ def test_run_report_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_run_report" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_run_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_run_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_run_report" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_run_report_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_run_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6870,8 +6880,9 @@ def test_run_pivot_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6934,18 +6945,20 @@ def test_run_pivot_report_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_run_pivot_report" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_run_pivot_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_run_pivot_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_run_pivot_report" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_run_pivot_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_run_pivot_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7003,8 +7016,9 @@ def test_batch_run_reports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7067,18 +7081,20 @@ def test_batch_run_reports_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_batch_run_reports" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_batch_run_reports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_batch_run_reports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_batch_run_reports" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_batch_run_reports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_batch_run_reports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7136,8 +7152,9 @@ def test_batch_run_pivot_reports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7200,18 +7217,20 @@ def test_batch_run_pivot_reports_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_batch_run_pivot_reports" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_batch_run_pivot_reports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_batch_run_pivot_reports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_batch_run_pivot_reports" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_batch_run_pivot_reports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_batch_run_pivot_reports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7269,8 +7288,9 @@ def test_get_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7333,17 +7353,20 @@ def test_get_metadata_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_get_metadata" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_get_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_get_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_get_metadata" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_get_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_get_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7398,8 +7421,9 @@ def test_run_realtime_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7464,18 +7488,20 @@ def test_run_realtime_report_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_run_realtime_report" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_run_realtime_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_run_realtime_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_run_realtime_report" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_run_realtime_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_run_realtime_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7533,8 +7559,9 @@ def test_check_compatibility_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7594,18 +7621,20 @@ def test_check_compatibility_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_check_compatibility" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_check_compatibility_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_check_compatibility" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_check_compatibility" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_check_compatibility_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_check_compatibility" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7663,8 +7692,9 @@ def test_create_audience_export_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7802,20 +7832,21 @@ def test_create_audience_export_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_create_audience_export" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_create_audience_export_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_create_audience_export" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_create_audience_export" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_create_audience_export_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_create_audience_export" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7868,8 +7899,9 @@ def test_query_audience_export_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7932,18 +7964,20 @@ def test_query_audience_export_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_query_audience_export" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_query_audience_export_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_query_audience_export" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_query_audience_export" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_query_audience_export_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_query_audience_export" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8001,8 +8035,9 @@ def test_get_audience_export_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8079,18 +8114,20 @@ def test_get_audience_export_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_get_audience_export" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_get_audience_export_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_get_audience_export" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_get_audience_export" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_get_audience_export_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_get_audience_export" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8145,8 +8182,9 @@ def test_list_audience_exports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8209,18 +8247,20 @@ def test_list_audience_exports_rest_interceptors(null_interceptor): ) client = BetaAnalyticsDataClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "post_list_audience_exports" - ) as post, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, - "post_list_audience_exports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BetaAnalyticsDataRestInterceptor, "pre_list_audience_exports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "post_list_audience_exports" + ) as post, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, + "post_list_audience_exports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BetaAnalyticsDataRestInterceptor, "pre_list_audience_exports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8595,11 +8635,14 @@ def test_beta_analytics_data_base_transport(): def test_beta_analytics_data_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.analytics.data_v1beta.services.beta_analytics_data.transports.BetaAnalyticsDataTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.analytics.data_v1beta.services.beta_analytics_data.transports.BetaAnalyticsDataTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BetaAnalyticsDataTransport( @@ -8619,9 +8662,12 @@ def test_beta_analytics_data_base_transport_with_credentials_file(): def test_beta_analytics_data_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.analytics.data_v1beta.services.beta_analytics_data.transports.BetaAnalyticsDataTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.analytics.data_v1beta.services.beta_analytics_data.transports.BetaAnalyticsDataTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BetaAnalyticsDataTransport() @@ -8699,11 +8745,12 @@ def test_beta_analytics_data_transport_auth_gdch_credentials(transport_class): def test_beta_analytics_data_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-apps-card/noxfile.py b/packages/google-apps-card/noxfile.py index 6da94f2e6ce3..4e6076ac3c3d 100644 --- a/packages/google-apps-card/noxfile.py +++ b/packages/google-apps-card/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-apps-card/setup.py b/packages/google-apps-card/setup.py index 4ef0736f7cdd..ee9423c0e61d 100644 --- a/packages/google-apps-card/setup.py +++ b/packages/google-apps-card/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-apps-card" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-apps-card/testing/constraints-3.7.txt b/packages/google-apps-card/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-apps-card/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-apps-card/testing/constraints-3.8.txt b/packages/google-apps-card/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-apps-card/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-apps-card/testing/constraints-3.9.txt b/packages/google-apps-card/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-apps-card/testing/constraints-3.9.txt +++ b/packages/google-apps-card/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py index b21c18cdcbe3..1f16c255dca5 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/async_client.py @@ -248,7 +248,7 @@ def transport(self) -> ChatServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py index 1bfbd8ea6255..3bc454149959 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/client.py @@ -142,7 +142,7 @@ class ChatServiceClient(metaclass=ChatServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -150,7 +150,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -160,6 +160,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -670,7 +674,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -767,7 +771,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -863,7 +867,7 @@ def __init__( self._universe_domain = ChatServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/README.rst b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/README.rst index 9cfe3f57a43b..914e9255066e 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/README.rst +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ChatServiceTransport` is the ABC for all transports. -- public child `ChatServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ChatServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseChatServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ChatServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ChatServiceTransport`` is the ABC for all transports. + +- public child ``ChatServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ChatServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseChatServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ChatServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py index 8cfaa0e3b91e..124a8e57741f 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/base.py @@ -131,6 +131,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -180,6 +184,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py index 5b74e5c5050b..f3d9eecdf896 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc.py @@ -74,7 +74,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -109,7 +109,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -205,6 +205,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py index 920864338584..1dde1db5c5f3 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/grpc_asyncio.py @@ -80,7 +80,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -115,7 +115,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -256,6 +256,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py index 12860478aa6d..a0b5a6ea4756 100644 --- a/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py +++ b/packages/google-apps-chat/google/apps/chat_v1/services/chat_service/transports/rest.py @@ -1951,6 +1951,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ChatServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-chat/noxfile.py b/packages/google-apps-chat/noxfile.py index edb1105e2f4d..532b6338d36a 100644 --- a/packages/google-apps-chat/noxfile.py +++ b/packages/google-apps-chat/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-apps-chat/setup.py b/packages/google-apps-chat/setup.py index e6bbc09ab33e..49b4a8590fe1 100644 --- a/packages/google-apps-chat/setup.py +++ b/packages/google-apps-chat/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "google-apps-card >= 0.3.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-apps-chat/testing/constraints-3.7.txt b/packages/google-apps-chat/testing/constraints-3.7.txt deleted file mode 100644 index cc0575c8da85..000000000000 --- a/packages/google-apps-chat/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -google-apps-card==0.3.0 diff --git a/packages/google-apps-chat/testing/constraints-3.8.txt b/packages/google-apps-chat/testing/constraints-3.8.txt deleted file mode 100644 index 1d982dd067f0..000000000000 --- a/packages/google-apps-chat/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-apps-card diff --git a/packages/google-apps-chat/testing/constraints-3.9.txt b/packages/google-apps-chat/testing/constraints-3.9.txt index 1d982dd067f0..f9a53dddcddf 100644 --- a/packages/google-apps-chat/testing/constraints-3.9.txt +++ b/packages/google-apps-chat/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-apps-card +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +google-apps-card==0.3.0 diff --git a/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py b/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py index 95c5c80c37ee..7fc63f420f9b 100644 --- a/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py +++ b/packages/google-apps-chat/tests/unit/gapic/chat_v1/test_chat_service.py @@ -155,6 +155,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ChatServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -173,6 +174,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ChatServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ChatServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1279,11 +1283,13 @@ def test_chat_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -22094,8 +22100,9 @@ def test_create_message_rest_bad_request(request_type=gc_message.CreateMessageRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22718,17 +22725,19 @@ def test_create_message_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_message" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_create_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_message" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_message_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_create_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22779,8 +22788,9 @@ def test_list_messages_rest_bad_request(request_type=message.ListMessagesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22843,17 +22853,19 @@ def test_list_messages_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_messages" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_messages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_list_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_messages" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_messages_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_list_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22906,8 +22918,9 @@ def test_list_memberships_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22970,17 +22983,19 @@ def test_list_memberships_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_memberships" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_memberships_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_list_memberships" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_memberships" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_memberships_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_list_memberships" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23033,8 +23048,9 @@ def test_get_membership_rest_bad_request(request_type=membership.GetMembershipRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23101,17 +23117,19 @@ def test_get_membership_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_membership" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_membership" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_membership_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23162,8 +23180,9 @@ def test_get_message_rest_bad_request(request_type=message.GetMessageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23238,17 +23257,19 @@ def test_get_message_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_message" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_message" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_message_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23297,8 +23318,9 @@ def test_update_message_rest_bad_request(request_type=gc_message.UpdateMessageRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23921,17 +23943,19 @@ def test_update_message_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_message" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_update_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_update_message" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_update_message_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_update_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23982,8 +24006,9 @@ def test_delete_message_rest_bad_request(request_type=message.DeleteMessageReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24040,13 +24065,13 @@ def test_delete_message_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_delete_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_delete_message" + ) as pre, + ): pre.assert_not_called() pb_message = message.DeleteMessageRequest.pb(message.DeleteMessageRequest()) transcode.return_value = { @@ -24087,8 +24112,9 @@ def test_get_attachment_rest_bad_request(request_type=attachment.GetAttachmentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24161,17 +24187,19 @@ def test_get_attachment_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_attachment" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_attachment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_attachment" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_attachment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24224,8 +24252,9 @@ def test_upload_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24285,17 +24314,20 @@ def test_upload_attachment_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_upload_attachment" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_upload_attachment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_upload_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_upload_attachment" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_upload_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_upload_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24351,8 +24383,9 @@ def test_list_spaces_rest_bad_request(request_type=space.ListSpacesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24415,17 +24448,19 @@ def test_list_spaces_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_spaces" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_spaces_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_list_spaces" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_spaces" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_spaces_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_list_spaces" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24474,8 +24509,9 @@ def test_search_spaces_rest_bad_request(request_type=space.SearchSpacesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24540,17 +24576,19 @@ def test_search_spaces_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_search_spaces" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_search_spaces_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_search_spaces" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_search_spaces" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_search_spaces_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_search_spaces" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24599,8 +24637,9 @@ def test_get_space_rest_bad_request(request_type=space.GetSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24691,17 +24730,19 @@ def test_get_space_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_space" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24750,8 +24791,9 @@ def test_create_space_rest_bad_request(request_type=gc_space.CreateSpaceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24951,17 +24993,19 @@ def test_create_space_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_space" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_create_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_space" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_create_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25010,8 +25054,9 @@ def test_set_up_space_rest_bad_request(request_type=space_setup.SetUpSpaceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25102,17 +25147,19 @@ def test_set_up_space_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_set_up_space" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_set_up_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_set_up_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_set_up_space" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_set_up_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_set_up_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25161,8 +25208,9 @@ def test_update_space_rest_bad_request(request_type=gc_space.UpdateSpaceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25362,17 +25410,19 @@ def test_update_space_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_space" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_update_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_update_space" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_update_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_update_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25421,8 +25471,9 @@ def test_delete_space_rest_bad_request(request_type=space.DeleteSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25479,13 +25530,13 @@ def test_delete_space_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_delete_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_delete_space" + ) as pre, + ): pre.assert_not_called() pb_message = space.DeleteSpaceRequest.pb(space.DeleteSpaceRequest()) transcode.return_value = { @@ -25528,8 +25579,9 @@ def test_complete_import_space_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25589,18 +25641,20 @@ def test_complete_import_space_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_complete_import_space" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, - "post_complete_import_space_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_complete_import_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_complete_import_space" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_complete_import_space_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_complete_import_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25655,8 +25709,9 @@ def test_find_direct_message_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25747,17 +25802,20 @@ def test_find_direct_message_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_find_direct_message" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_find_direct_message_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_find_direct_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_find_direct_message" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_find_direct_message_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_find_direct_message" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25808,8 +25866,9 @@ def test_create_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25958,17 +26017,20 @@ def test_create_membership_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_membership" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_create_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_membership" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_create_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_create_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26021,8 +26083,9 @@ def test_update_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26171,17 +26234,20 @@ def test_update_membership_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_membership" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_update_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_update_membership" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_update_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_update_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26234,8 +26300,9 @@ def test_delete_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26302,17 +26369,20 @@ def test_delete_membership_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_delete_membership" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_delete_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_delete_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_delete_membership" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_delete_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_delete_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26365,8 +26435,9 @@ def test_create_reaction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26519,17 +26590,19 @@ def test_create_reaction_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_reaction" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_reaction_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_create_reaction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_reaction" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_reaction_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_create_reaction" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26580,8 +26653,9 @@ def test_list_reactions_rest_bad_request(request_type=reaction.ListReactionsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26644,17 +26718,19 @@ def test_list_reactions_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_reactions" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_reactions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_list_reactions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_reactions" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_reactions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_list_reactions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26705,8 +26781,9 @@ def test_delete_reaction_rest_bad_request(request_type=reaction.DeleteReactionRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26763,13 +26840,13 @@ def test_delete_reaction_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_delete_reaction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_delete_reaction" + ) as pre, + ): pre.assert_not_called() pb_message = reaction.DeleteReactionRequest.pb(reaction.DeleteReactionRequest()) transcode.return_value = { @@ -26812,8 +26889,9 @@ def test_create_custom_emoji_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26956,17 +27034,20 @@ def test_create_custom_emoji_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_custom_emoji" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_create_custom_emoji_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_create_custom_emoji" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_create_custom_emoji" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_create_custom_emoji_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_create_custom_emoji" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27017,8 +27098,9 @@ def test_get_custom_emoji_rest_bad_request(request_type=reaction.GetCustomEmojiR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27087,17 +27169,19 @@ def test_get_custom_emoji_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_custom_emoji" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_custom_emoji_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_custom_emoji" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_custom_emoji" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_custom_emoji_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_custom_emoji" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27148,8 +27232,9 @@ def test_list_custom_emojis_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27212,17 +27297,20 @@ def test_list_custom_emojis_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_custom_emojis" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_custom_emojis_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_list_custom_emojis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_custom_emojis" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_list_custom_emojis_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_list_custom_emojis" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27277,8 +27365,9 @@ def test_delete_custom_emoji_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27335,13 +27424,13 @@ def test_delete_custom_emoji_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_delete_custom_emoji" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_delete_custom_emoji" + ) as pre, + ): pre.assert_not_called() pb_message = reaction.DeleteCustomEmojiRequest.pb( reaction.DeleteCustomEmojiRequest() @@ -27386,8 +27475,9 @@ def test_get_space_read_state_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27450,17 +27540,20 @@ def test_get_space_read_state_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space_read_state" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space_read_state_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_space_read_state" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_space_read_state" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_get_space_read_state_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_space_read_state" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27517,8 +27610,9 @@ def test_update_space_read_state_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27656,18 +27750,20 @@ def test_update_space_read_state_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_space_read_state" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, - "post_update_space_read_state_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_update_space_read_state" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_update_space_read_state" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_update_space_read_state_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_update_space_read_state" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27724,8 +27820,9 @@ def test_get_thread_read_state_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27790,18 +27887,20 @@ def test_get_thread_read_state_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_thread_read_state" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, - "post_get_thread_read_state_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_thread_read_state" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_thread_read_state" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_get_thread_read_state_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_thread_read_state" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27856,8 +27955,9 @@ def test_get_space_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27922,17 +28022,19 @@ def test_get_space_event_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space_event" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space_event_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_space_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_space_event" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_space_event_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_space_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27985,8 +28087,9 @@ def test_list_space_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28049,17 +28152,20 @@ def test_list_space_events_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_space_events" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_list_space_events_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_list_space_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_list_space_events" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_list_space_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_list_space_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28117,8 +28223,9 @@ def test_get_space_notification_setting_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28193,18 +28300,20 @@ def test_get_space_notification_setting_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_get_space_notification_setting" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, - "post_get_space_notification_setting_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_get_space_notification_setting" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, "post_get_space_notification_setting" + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_get_space_notification_setting_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, "pre_get_space_notification_setting" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28266,8 +28375,9 @@ def test_update_space_notification_setting_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28426,18 +28536,22 @@ def test_update_space_notification_setting_rest_interceptors(null_interceptor): ) client = ChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChatServiceRestInterceptor, "post_update_space_notification_setting" - ) as post, mock.patch.object( - transports.ChatServiceRestInterceptor, - "post_update_space_notification_setting_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ChatServiceRestInterceptor, "pre_update_space_notification_setting" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_update_space_notification_setting", + ) as post, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "post_update_space_notification_setting_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ChatServiceRestInterceptor, + "pre_update_space_notification_setting", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29312,11 +29426,14 @@ def test_chat_service_base_transport(): def test_chat_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.chat_v1.services.chat_service.transports.ChatServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.chat_v1.services.chat_service.transports.ChatServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChatServiceTransport( @@ -29364,9 +29481,12 @@ def test_chat_service_base_transport_with_credentials_file(): def test_chat_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.chat_v1.services.chat_service.transports.ChatServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.chat_v1.services.chat_service.transports.ChatServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChatServiceTransport() @@ -29500,11 +29620,12 @@ def test_chat_service_transport_auth_gdch_credentials(transport_class): def test_chat_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/async_client.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/async_client.py index a62289ae9b2f..fef654456cac 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/async_client.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/async_client.py @@ -206,7 +206,7 @@ def transport(self) -> SubscriptionsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1152,7 +1152,7 @@ async def sample_reactivate_subscription(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1178,8 +1178,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1188,7 +1192,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1196,7 +1200,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/client.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/client.py index e275254e3ec8..5d90465bcfa1 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/client.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/client.py @@ -122,7 +122,7 @@ class SubscriptionsServiceClient(metaclass=SubscriptionsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = SubscriptionsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1595,7 +1599,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1621,8 +1625,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1631,7 +1639,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1640,7 +1648,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/README.rst b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/README.rst index 3adaca8c76c3..e855f90d4807 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/README.rst +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SubscriptionsServiceTransport` is the ABC for all transports. -- public child `SubscriptionsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SubscriptionsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSubscriptionsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SubscriptionsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SubscriptionsServiceTransport`` is the ABC for all transports. + +- public child ``SubscriptionsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SubscriptionsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSubscriptionsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SubscriptionsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/base.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/base.py index 87e36dd552ba..beae19e66378 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/base.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/base.py @@ -95,6 +95,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -144,6 +148,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc.py index 39fd42071c2d..4f3b83ec7b21 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc_asyncio.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc_asyncio.py index 0ce652006f7b..effb51e23fc8 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc_asyncio.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/rest.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/rest.py index 65032f193995..347072e41e9e 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/rest.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1/services/subscriptions_service/transports/rest.py @@ -522,6 +522,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SubscriptionsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/async_client.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/async_client.py index 7d44a9c9b117..882af3fd20cb 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/async_client.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/async_client.py @@ -208,7 +208,7 @@ def transport(self) -> SubscriptionsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1164,7 +1164,7 @@ async def sample_reactivate_subscription(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1190,8 +1190,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1200,7 +1204,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1208,7 +1212,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/client.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/client.py index 371973e741a8..496597efd929 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/client.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/client.py @@ -124,7 +124,7 @@ class SubscriptionsServiceClient(metaclass=SubscriptionsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -474,7 +478,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -571,7 +575,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -671,7 +675,7 @@ def __init__( self._universe_domain = SubscriptionsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1607,7 +1611,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1633,8 +1637,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1643,7 +1651,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1652,7 +1660,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/README.rst b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/README.rst index 3adaca8c76c3..e855f90d4807 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/README.rst +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SubscriptionsServiceTransport` is the ABC for all transports. -- public child `SubscriptionsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SubscriptionsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSubscriptionsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SubscriptionsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SubscriptionsServiceTransport`` is the ABC for all transports. + +- public child ``SubscriptionsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SubscriptionsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSubscriptionsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SubscriptionsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/base.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/base.py index c3c9e1156820..2ac6e5094763 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/base.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/base.py @@ -100,6 +100,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -149,6 +153,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc.py index d2f551a2601d..63e3e92e0e72 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc_asyncio.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc_asyncio.py index 3d76f5a03e84..6590e45fe158 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc_asyncio.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/rest.py b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/rest.py index 00d3d950633a..3c5ed90ab642 100644 --- a/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/rest.py +++ b/packages/google-apps-events-subscriptions/google/apps/events_subscriptions_v1beta/services/subscriptions_service/transports/rest.py @@ -522,6 +522,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SubscriptionsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-events-subscriptions/noxfile.py b/packages/google-apps-events-subscriptions/noxfile.py index 5c3b1612729b..ed575ff62175 100644 --- a/packages/google-apps-events-subscriptions/noxfile.py +++ b/packages/google-apps-events-subscriptions/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-apps-events-subscriptions/setup.py b/packages/google-apps-events-subscriptions/setup.py index 6d35ebd74fbc..b688e7954aa2 100644 --- a/packages/google-apps-events-subscriptions/setup.py +++ b/packages/google-apps-events-subscriptions/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-apps-events-subscriptions" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-apps-events-subscriptions/testing/constraints-3.7.txt b/packages/google-apps-events-subscriptions/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-apps-events-subscriptions/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-apps-events-subscriptions/testing/constraints-3.8.txt b/packages/google-apps-events-subscriptions/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-apps-events-subscriptions/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-apps-events-subscriptions/testing/constraints-3.9.txt b/packages/google-apps-events-subscriptions/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-apps-events-subscriptions/testing/constraints-3.9.txt +++ b/packages/google-apps-events-subscriptions/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1/test_subscriptions_service.py b/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1/test_subscriptions_service.py index 07c5a86a3bfe..34d1a6d72478 100644 --- a/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1/test_subscriptions_service.py +++ b/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1/test_subscriptions_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SubscriptionsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): SubscriptionsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SubscriptionsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_subscriptions_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5229,8 +5236,9 @@ def test_create_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5376,20 +5384,21 @@ def test_create_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_create_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_create_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_create_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_create_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_create_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_create_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5442,8 +5451,9 @@ def test_delete_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5500,20 +5510,21 @@ def test_delete_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_delete_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_delete_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_delete_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_delete_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_delete_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_delete_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5566,8 +5577,9 @@ def test_get_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5649,18 +5661,20 @@ def test_get_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_get_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_get_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_get_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_get_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_get_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_get_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5715,8 +5729,9 @@ def test_list_subscriptions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5779,18 +5794,20 @@ def test_list_subscriptions_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_list_subscriptions" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_list_subscriptions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_list_subscriptions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_list_subscriptions" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_list_subscriptions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_list_subscriptions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5848,8 +5865,9 @@ def test_update_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5995,20 +6013,21 @@ def test_update_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_update_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_update_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_update_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_update_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_update_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_update_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6061,8 +6080,9 @@ def test_reactivate_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6119,20 +6139,23 @@ def test_reactivate_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_reactivate_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_reactivate_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_reactivate_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_reactivate_subscription", + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_reactivate_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "pre_reactivate_subscription", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6185,8 +6208,9 @@ def test_get_operation_rest_bad_request( request = json_format.ParseDict({"name": "operations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6452,11 +6476,14 @@ def test_subscriptions_service_base_transport(): def test_subscriptions_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.events_subscriptions_v1.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.events_subscriptions_v1.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubscriptionsServiceTransport( @@ -6484,9 +6511,12 @@ def test_subscriptions_service_base_transport_with_credentials_file(): def test_subscriptions_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.events_subscriptions_v1.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.events_subscriptions_v1.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubscriptionsServiceTransport() @@ -6580,11 +6610,12 @@ def test_subscriptions_service_transport_auth_gdch_credentials(transport_class): def test_subscriptions_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7252,6 +7283,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SubscriptionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SubscriptionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = SubscriptionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1beta/test_subscriptions_service.py b/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1beta/test_subscriptions_service.py index acd262e8dac7..3b2ffa867385 100644 --- a/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1beta/test_subscriptions_service.py +++ b/packages/google-apps-events-subscriptions/tests/unit/gapic/events_subscriptions_v1beta/test_subscriptions_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SubscriptionsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): SubscriptionsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SubscriptionsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_subscriptions_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5267,8 +5274,9 @@ def test_create_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5415,20 +5423,21 @@ def test_create_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_create_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_create_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_create_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_create_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_create_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_create_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5481,8 +5490,9 @@ def test_delete_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5539,20 +5549,21 @@ def test_delete_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_delete_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_delete_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_delete_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_delete_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_delete_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_delete_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5605,8 +5616,9 @@ def test_get_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5688,18 +5700,20 @@ def test_get_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_get_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_get_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_get_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_get_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_get_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_get_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5754,8 +5768,9 @@ def test_list_subscriptions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5818,18 +5833,20 @@ def test_list_subscriptions_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_list_subscriptions" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_list_subscriptions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_list_subscriptions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_list_subscriptions" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_list_subscriptions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_list_subscriptions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5887,8 +5904,9 @@ def test_update_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6035,20 +6053,21 @@ def test_update_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_update_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_update_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_update_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "post_update_subscription" + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_update_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, "pre_update_subscription" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6101,8 +6120,9 @@ def test_reactivate_subscription_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6159,20 +6179,23 @@ def test_reactivate_subscription_rest_interceptors(null_interceptor): ) client = SubscriptionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "post_reactivate_subscription" - ) as post, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, - "post_reactivate_subscription_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubscriptionsServiceRestInterceptor, "pre_reactivate_subscription" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_reactivate_subscription", + ) as post, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "post_reactivate_subscription_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubscriptionsServiceRestInterceptor, + "pre_reactivate_subscription", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6225,8 +6248,9 @@ def test_get_operation_rest_bad_request( request = json_format.ParseDict({"name": "operations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6492,11 +6516,14 @@ def test_subscriptions_service_base_transport(): def test_subscriptions_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.events_subscriptions_v1beta.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.events_subscriptions_v1beta.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubscriptionsServiceTransport( @@ -6529,9 +6556,12 @@ def test_subscriptions_service_base_transport_with_credentials_file(): def test_subscriptions_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.events_subscriptions_v1beta.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.events_subscriptions_v1beta.services.subscriptions_service.transports.SubscriptionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubscriptionsServiceTransport() @@ -6635,11 +6665,12 @@ def test_subscriptions_service_transport_auth_gdch_credentials(transport_class): def test_subscriptions_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7312,6 +7343,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SubscriptionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SubscriptionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = SubscriptionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/async_client.py b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/async_client.py index 6ced5e69c195..b19e773c507a 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/async_client.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/async_client.py @@ -227,7 +227,7 @@ def transport(self) -> ConferenceRecordsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/client.py b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/client.py index b19c9c54cc1e..c1ec2628df13 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/client.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/client.py @@ -111,7 +111,7 @@ class ConferenceRecordsServiceClient(metaclass=ConferenceRecordsServiceClientMet """REST API for services dealing with conference records.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -550,7 +554,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -649,7 +653,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -751,7 +755,7 @@ def __init__( self._universe_domain = ConferenceRecordsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/README.rst b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/README.rst index 784d2ae0b1c0..15dc4caa1725 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/README.rst +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConferenceRecordsServiceTransport` is the ABC for all transports. -- public child `ConferenceRecordsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConferenceRecordsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConferenceRecordsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConferenceRecordsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConferenceRecordsServiceTransport`` is the ABC for all transports. + +- public child ``ConferenceRecordsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConferenceRecordsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConferenceRecordsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConferenceRecordsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/base.py b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/base.py index aa002a3134d0..390cd2411d85 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/base.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc.py b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc.py index 231ad3e69673..6d274be8f1e8 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc_asyncio.py b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc_asyncio.py index d6e2980fa0b5..84105db5643b 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc_asyncio.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/rest.py b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/rest.py index 57908da6b142..38be93d91340 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/rest.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/conference_records_service/transports/rest.py @@ -813,6 +813,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConferenceRecordsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/async_client.py b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/async_client.py index 4778e31319d0..4c5d10cb5020 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/async_client.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> SpacesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/client.py b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/client.py index 7cb4c64002f1..3e5a7c5fa42d 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/client.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/client.py @@ -110,7 +110,7 @@ class SpacesServiceClient(metaclass=SpacesServiceClientMeta): """REST API for services dealing with spaces.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = SpacesServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/README.rst b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/README.rst index a89dc8923e55..b98b637a23f9 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/README.rst +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SpacesServiceTransport` is the ABC for all transports. -- public child `SpacesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SpacesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSpacesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SpacesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SpacesServiceTransport`` is the ABC for all transports. + +- public child ``SpacesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SpacesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSpacesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SpacesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/base.py b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/base.py index d29771d937b0..b70d54f4c6a4 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/base.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc.py b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc.py index 5cc533c7b0a9..a3c5a5f7b244 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc_asyncio.py b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc_asyncio.py index 80eecf91769e..073664c97b29 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc_asyncio.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/rest.py b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/rest.py index d72035b2e2f4..530fb39c9551 100644 --- a/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/rest.py +++ b/packages/google-apps-meet/google/apps/meet_v2/services/spaces_service/transports/rest.py @@ -320,6 +320,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SpacesServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/async_client.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/async_client.py index 2b066417b6b4..e8b50eb35750 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/async_client.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/async_client.py @@ -227,7 +227,7 @@ def transport(self) -> ConferenceRecordsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/client.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/client.py index 69e5f4cd3fc2..237f4434de87 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/client.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/client.py @@ -111,7 +111,7 @@ class ConferenceRecordsServiceClient(metaclass=ConferenceRecordsServiceClientMet """REST API for services dealing with conference records.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -550,7 +554,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -649,7 +653,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -751,7 +755,7 @@ def __init__( self._universe_domain = ConferenceRecordsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/README.rst b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/README.rst index 784d2ae0b1c0..15dc4caa1725 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/README.rst +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConferenceRecordsServiceTransport` is the ABC for all transports. -- public child `ConferenceRecordsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConferenceRecordsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConferenceRecordsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConferenceRecordsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConferenceRecordsServiceTransport`` is the ABC for all transports. + +- public child ``ConferenceRecordsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConferenceRecordsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConferenceRecordsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConferenceRecordsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/base.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/base.py index d76b6664ec76..4508170c42a3 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/base.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc.py index 382eb7bbc2a7..f6667f024bf1 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc_asyncio.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc_asyncio.py index 0ad1fa40bcb0..6c8e6785703a 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc_asyncio.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/rest.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/rest.py index d153e4fa6a0f..1246215d2384 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/rest.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/conference_records_service/transports/rest.py @@ -813,6 +813,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConferenceRecordsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/async_client.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/async_client.py index 50b4b9133a5a..07fc76cabb68 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/async_client.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> SpacesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/client.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/client.py index 8cd34b022a28..279a4aebdf64 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/client.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/client.py @@ -111,7 +111,7 @@ class SpacesServiceClient(metaclass=SpacesServiceClientMeta): """REST API for services dealing with spaces.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -654,7 +658,7 @@ def __init__( self._universe_domain = SpacesServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/README.rst b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/README.rst index a89dc8923e55..b98b637a23f9 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/README.rst +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SpacesServiceTransport` is the ABC for all transports. -- public child `SpacesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SpacesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSpacesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SpacesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SpacesServiceTransport`` is the ABC for all transports. + +- public child ``SpacesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SpacesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSpacesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SpacesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/base.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/base.py index 24661d9788cc..660de24070e8 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/base.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc.py index ed8ca49b27cd..d8466bfda3ab 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc_asyncio.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc_asyncio.py index 70f96e397218..20e842c3d8ee 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc_asyncio.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/rest.py b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/rest.py index c67cd089ad1f..8ae33b0234b9 100644 --- a/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/rest.py +++ b/packages/google-apps-meet/google/apps/meet_v2beta/services/spaces_service/transports/rest.py @@ -552,6 +552,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SpacesServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-apps-meet/noxfile.py b/packages/google-apps-meet/noxfile.py index 216ac0fca57c..884b2312ccbd 100644 --- a/packages/google-apps-meet/noxfile.py +++ b/packages/google-apps-meet/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-apps-meet/setup.py b/packages/google-apps-meet/setup.py index ef7ad66adc4c..428f94952aec 100644 --- a/packages/google-apps-meet/setup.py +++ b/packages/google-apps-meet/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-apps-meet" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-apps-meet/testing/constraints-3.7.txt b/packages/google-apps-meet/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-apps-meet/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-apps-meet/testing/constraints-3.8.txt b/packages/google-apps-meet/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-apps-meet/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-apps-meet/testing/constraints-3.9.txt b/packages/google-apps-meet/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-apps-meet/testing/constraints-3.9.txt +++ b/packages/google-apps-meet/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_conference_records_service.py b/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_conference_records_service.py index af2a1046da66..183a554e2c7e 100644 --- a/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_conference_records_service.py +++ b/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_conference_records_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConferenceRecordsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ConferenceRecordsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConferenceRecordsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1353,11 +1358,13 @@ def test_conference_records_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9688,8 +9695,9 @@ def test_get_conference_record_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9754,18 +9762,22 @@ def test_get_conference_record_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_conference_record" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_conference_record_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_conference_record" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_conference_record", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_conference_record_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_get_conference_record", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9818,8 +9830,9 @@ def test_list_conference_records_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9882,20 +9895,22 @@ def test_list_conference_records_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_conference_records", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_conference_records_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_list_conference_records", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_conference_records", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_conference_records_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_list_conference_records", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9951,8 +9966,9 @@ def test_get_participant_rest_bad_request(request_type=service.GetParticipantReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10015,18 +10031,20 @@ def test_get_participant_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_participant" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_participant_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_get_participant" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_participant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_get_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10077,8 +10095,9 @@ def test_list_participants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10143,18 +10162,20 @@ def test_list_participants_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_list_participants" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_participants_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_list_participants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_list_participants" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_participants_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_list_participants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10211,8 +10232,9 @@ def test_get_participant_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10277,20 +10299,22 @@ def test_get_participant_session_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_participant_session", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_participant_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_get_participant_session", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_participant_session", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_participant_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_get_participant_session", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10345,8 +10369,9 @@ def test_list_participant_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10409,20 +10434,22 @@ def test_list_participant_sessions_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_participant_sessions", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_participant_sessions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_list_participant_sessions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_participant_sessions", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_participant_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_list_participant_sessions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10478,8 +10505,9 @@ def test_get_recording_rest_bad_request(request_type=service.GetRecordingRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10544,18 +10572,20 @@ def test_get_recording_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_recording" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_recording_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_recording" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_get_recording" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_recording_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_get_recording" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10604,8 +10634,9 @@ def test_list_recordings_rest_bad_request(request_type=service.ListRecordingsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10668,18 +10699,20 @@ def test_list_recordings_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_list_recordings" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_recordings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_list_recordings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_list_recordings" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_recordings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_list_recordings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10730,8 +10763,9 @@ def test_get_transcript_rest_bad_request(request_type=service.GetTranscriptReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10796,18 +10830,20 @@ def test_get_transcript_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_transcript" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_transcript_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_transcript" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_get_transcript" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_transcript_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_get_transcript" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10856,8 +10892,9 @@ def test_list_transcripts_rest_bad_request(request_type=service.ListTranscriptsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10920,18 +10957,20 @@ def test_list_transcripts_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_list_transcripts" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_transcripts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_list_transcripts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_list_transcripts" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_transcripts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_list_transcripts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10986,8 +11025,9 @@ def test_get_transcript_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11058,18 +11098,22 @@ def test_get_transcript_entry_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_transcript_entry" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_transcript_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_transcript_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_transcript_entry", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_transcript_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_get_transcript_entry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11122,8 +11166,9 @@ def test_list_transcript_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11186,20 +11231,22 @@ def test_list_transcript_entries_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_transcript_entries", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_transcript_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_list_transcript_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_transcript_entries", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_transcript_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_list_transcript_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11571,11 +11618,14 @@ def test_conference_records_service_base_transport(): def test_conference_records_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.meet_v2.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.meet_v2.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConferenceRecordsServiceTransport( @@ -11595,9 +11645,12 @@ def test_conference_records_service_base_transport_with_credentials_file(): def test_conference_records_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.meet_v2.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.meet_v2.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConferenceRecordsServiceTransport() @@ -11677,11 +11730,12 @@ def test_conference_records_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_spaces_service.py b/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_spaces_service.py index 0ecd762a837f..c8a32f53d6be 100644 --- a/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_spaces_service.py +++ b/packages/google-apps-meet/tests/unit/gapic/meet_v2/test_spaces_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SpacesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( SpacesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SpacesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1276,11 +1281,13 @@ def test_spaces_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3508,8 +3515,9 @@ def test_create_space_rest_bad_request(request_type=service.CreateSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3650,17 +3658,19 @@ def test_create_space_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_create_space" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_create_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_create_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_create_space" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_create_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_create_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3709,8 +3719,9 @@ def test_get_space_rest_bad_request(request_type=service.GetSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3777,17 +3788,19 @@ def test_get_space_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_get_space" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_get_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_get_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_get_space" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_get_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_get_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3836,8 +3849,9 @@ def test_update_space_rest_bad_request(request_type=service.UpdateSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3978,17 +3992,19 @@ def test_update_space_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_update_space" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_update_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_update_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_update_space" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_update_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_update_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4039,8 +4055,9 @@ def test_end_active_conference_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4097,13 +4114,13 @@ def test_end_active_conference_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_end_active_conference" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_end_active_conference" + ) as pre, + ): pre.assert_not_called() pb_message = service.EndActiveConferenceRequest.pb( service.EndActiveConferenceRequest() @@ -4282,11 +4299,14 @@ def test_spaces_service_base_transport(): def test_spaces_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.meet_v2.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.meet_v2.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpacesServiceTransport( @@ -4307,9 +4327,12 @@ def test_spaces_service_base_transport_with_credentials_file(): def test_spaces_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.meet_v2.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.meet_v2.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpacesServiceTransport() @@ -4389,11 +4412,12 @@ def test_spaces_service_transport_auth_gdch_credentials(transport_class): def test_spaces_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_conference_records_service.py b/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_conference_records_service.py index 2657b73a1dd8..b183bdef95d1 100644 --- a/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_conference_records_service.py +++ b/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_conference_records_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConferenceRecordsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ConferenceRecordsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConferenceRecordsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1353,11 +1358,13 @@ def test_conference_records_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9694,8 +9701,9 @@ def test_get_conference_record_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9760,18 +9768,22 @@ def test_get_conference_record_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_conference_record" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_conference_record_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_conference_record" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_conference_record", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_conference_record_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_get_conference_record", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9824,8 +9836,9 @@ def test_list_conference_records_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9888,20 +9901,22 @@ def test_list_conference_records_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_conference_records", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_conference_records_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_list_conference_records", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_conference_records", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_conference_records_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_list_conference_records", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9957,8 +9972,9 @@ def test_get_participant_rest_bad_request(request_type=service.GetParticipantReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10021,18 +10037,20 @@ def test_get_participant_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_participant" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_participant_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_get_participant" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_participant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_get_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10083,8 +10101,9 @@ def test_list_participants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10149,18 +10168,20 @@ def test_list_participants_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_list_participants" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_participants_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_list_participants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_list_participants" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_participants_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_list_participants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10217,8 +10238,9 @@ def test_get_participant_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10283,20 +10305,22 @@ def test_get_participant_session_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_participant_session", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_participant_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_get_participant_session", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_participant_session", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_participant_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_get_participant_session", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10351,8 +10375,9 @@ def test_list_participant_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10415,20 +10440,22 @@ def test_list_participant_sessions_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_participant_sessions", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_participant_sessions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_list_participant_sessions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_participant_sessions", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_participant_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_list_participant_sessions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10484,8 +10511,9 @@ def test_get_recording_rest_bad_request(request_type=service.GetRecordingRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10550,18 +10578,20 @@ def test_get_recording_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_recording" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_recording_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_recording" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_get_recording" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_recording_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_get_recording" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10610,8 +10640,9 @@ def test_list_recordings_rest_bad_request(request_type=service.ListRecordingsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10674,18 +10705,20 @@ def test_list_recordings_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_list_recordings" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_recordings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_list_recordings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_list_recordings" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_recordings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_list_recordings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10736,8 +10769,9 @@ def test_get_transcript_rest_bad_request(request_type=service.GetTranscriptReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10802,18 +10836,20 @@ def test_get_transcript_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_transcript" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_transcript_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_transcript" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_get_transcript" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_transcript_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_get_transcript" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10862,8 +10898,9 @@ def test_list_transcripts_rest_bad_request(request_type=service.ListTranscriptsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10926,18 +10963,20 @@ def test_list_transcripts_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_list_transcripts" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_transcripts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_list_transcripts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "post_list_transcripts" + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_transcripts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, "pre_list_transcripts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10992,8 +11031,9 @@ def test_get_transcript_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11064,18 +11104,22 @@ def test_get_transcript_entry_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "post_get_transcript_entry" - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_get_transcript_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, "pre_get_transcript_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_transcript_entry", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_get_transcript_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_get_transcript_entry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11128,8 +11172,9 @@ def test_list_transcript_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11192,20 +11237,22 @@ def test_list_transcript_entries_rest_interceptors(null_interceptor): ) client = ConferenceRecordsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_transcript_entries", - ) as post, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "post_list_transcript_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConferenceRecordsServiceRestInterceptor, - "pre_list_transcript_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_transcript_entries", + ) as post, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "post_list_transcript_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConferenceRecordsServiceRestInterceptor, + "pre_list_transcript_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11577,11 +11624,14 @@ def test_conference_records_service_base_transport(): def test_conference_records_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.meet_v2beta.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.meet_v2beta.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConferenceRecordsServiceTransport( @@ -11601,9 +11651,12 @@ def test_conference_records_service_base_transport_with_credentials_file(): def test_conference_records_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.meet_v2beta.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.meet_v2beta.services.conference_records_service.transports.ConferenceRecordsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConferenceRecordsServiceTransport() @@ -11683,11 +11736,12 @@ def test_conference_records_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_spaces_service.py b/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_spaces_service.py index 5ae15c07615b..90ed7bfce87b 100644 --- a/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_spaces_service.py +++ b/packages/google-apps-meet/tests/unit/gapic/meet_v2beta/test_spaces_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SpacesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( SpacesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SpacesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1277,11 +1282,13 @@ def test_spaces_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6583,8 +6590,9 @@ def test_create_space_rest_bad_request(request_type=service.CreateSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6741,17 +6749,19 @@ def test_create_space_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_create_space" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_create_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_create_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_create_space" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_create_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_create_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6800,8 +6810,9 @@ def test_get_space_rest_bad_request(request_type=service.GetSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6868,17 +6879,19 @@ def test_get_space_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_get_space" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_get_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_get_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_get_space" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_get_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_get_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6927,8 +6940,9 @@ def test_update_space_rest_bad_request(request_type=service.UpdateSpaceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7085,17 +7099,19 @@ def test_update_space_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_update_space" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_update_space_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_update_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_update_space" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_update_space_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_update_space" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7146,8 +7162,9 @@ def test_connect_active_conference_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7212,18 +7229,20 @@ def test_connect_active_conference_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_connect_active_conference" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, - "post_connect_active_conference_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_connect_active_conference" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_connect_active_conference" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, + "post_connect_active_conference_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_connect_active_conference" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7281,8 +7300,9 @@ def test_end_active_conference_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7339,13 +7359,13 @@ def test_end_active_conference_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_end_active_conference" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_end_active_conference" + ) as pre, + ): pre.assert_not_called() pb_message = service.EndActiveConferenceRequest.pb( service.EndActiveConferenceRequest() @@ -7388,8 +7408,9 @@ def test_create_member_rest_bad_request(request_type=service.CreateMemberRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7531,17 +7552,19 @@ def test_create_member_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_create_member" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_create_member_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_create_member" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_create_member" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_create_member_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_create_member" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7590,8 +7613,9 @@ def test_get_member_rest_bad_request(request_type=service.GetMemberRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7660,17 +7684,19 @@ def test_get_member_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_get_member" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_get_member_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_get_member" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_get_member" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_get_member_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_get_member" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7719,8 +7745,9 @@ def test_list_members_rest_bad_request(request_type=service.ListMembersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7783,17 +7810,19 @@ def test_list_members_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_list_members" - ) as post, mock.patch.object( - transports.SpacesServiceRestInterceptor, "post_list_members_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_list_members" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_list_members" + ) as post, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "post_list_members_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_list_members" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7844,8 +7873,9 @@ def test_delete_member_rest_bad_request(request_type=service.DeleteMemberRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7902,13 +7932,13 @@ def test_delete_member_rest_interceptors(null_interceptor): ) client = SpacesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SpacesServiceRestInterceptor, "pre_delete_member" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SpacesServiceRestInterceptor, "pre_delete_member" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteMemberRequest.pb(service.DeleteMemberRequest()) transcode.return_value = { @@ -8192,11 +8222,14 @@ def test_spaces_service_base_transport(): def test_spaces_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.apps.meet_v2beta.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.apps.meet_v2beta.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpacesServiceTransport( @@ -8220,9 +8253,12 @@ def test_spaces_service_base_transport_with_credentials_file(): def test_spaces_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.apps.meet_v2beta.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.apps.meet_v2beta.services.spaces_service.transports.SpacesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpacesServiceTransport() @@ -8308,11 +8344,12 @@ def test_spaces_service_transport_auth_gdch_credentials(transport_class): def test_spaces_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-apps-script-type/noxfile.py b/packages/google-apps-script-type/noxfile.py index d5aa3f80c289..7f5d236975a9 100644 --- a/packages/google-apps-script-type/noxfile.py +++ b/packages/google-apps-script-type/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-apps-script-type/setup.py b/packages/google-apps-script-type/setup.py index bf3c1d89124b..127283140d91 100644 --- a/packages/google-apps-script-type/setup.py +++ b/packages/google-apps-script-type/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-apps-script-type" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-apps-script-type/testing/constraints-3.7.txt b/packages/google-apps-script-type/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-apps-script-type/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-apps-script-type/testing/constraints-3.8.txt b/packages/google-apps-script-type/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-apps-script-type/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-apps-script-type/testing/constraints-3.9.txt b/packages/google-apps-script-type/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-apps-script-type/testing/constraints-3.9.txt +++ b/packages/google-apps-script-type/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/async_client.py b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/async_client.py index e5f1e28a0c78..d469471d1f49 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/async_client.py +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> TablesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/client.py b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/client.py index 1b5a03ac3865..7fb41dc31424 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/client.py +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/client.py @@ -125,7 +125,7 @@ class TablesServiceClient(metaclass=TablesServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -475,7 +479,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -572,7 +576,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -668,7 +672,7 @@ def __init__( self._universe_domain = TablesServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/README.rst b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/README.rst index 05ae9557a04a..f6deff92c2a6 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/README.rst +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TablesServiceTransport` is the ABC for all transports. -- public child `TablesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TablesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTablesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TablesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TablesServiceTransport`` is the ABC for all transports. + +- public child ``TablesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TablesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTablesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TablesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/base.py b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/base.py index d648b39f918b..ac6aa464a6e1 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/base.py +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc.py b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc.py index 1395c30512c4..5adc7210ff64 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc.py +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -198,6 +198,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc_asyncio.py b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc_asyncio.py index 4c4055ac251d..2fafea236179 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc_asyncio.py +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -249,6 +249,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/rest.py b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/rest.py index 8a95d8c06fce..76e728f0f7f4 100644 --- a/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/rest.py +++ b/packages/google-area120-tables/google/area120/tables_v1alpha1/services/tables_service/transports/rest.py @@ -713,6 +713,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TablesServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-area120-tables/noxfile.py b/packages/google-area120-tables/noxfile.py index b567322c1b48..167932e25231 100644 --- a/packages/google-area120-tables/noxfile.py +++ b/packages/google-area120-tables/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-area120-tables/setup.py b/packages/google-area120-tables/setup.py index 144db13315d6..9c82d34c8c63 100644 --- a/packages/google-area120-tables/setup.py +++ b/packages/google-area120-tables/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-area120-tables" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-area120-tables/testing/constraints-3.7.txt b/packages/google-area120-tables/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-area120-tables/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-area120-tables/testing/constraints-3.8.txt b/packages/google-area120-tables/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-area120-tables/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-area120-tables/testing/constraints-3.9.txt b/packages/google-area120-tables/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-area120-tables/testing/constraints-3.9.txt +++ b/packages/google-area120-tables/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-area120-tables/tests/unit/gapic/tables_v1alpha1/test_tables_service.py b/packages/google-area120-tables/tests/unit/gapic/tables_v1alpha1/test_tables_service.py index b85f4de07366..5d8fc82e4a4f 100644 --- a/packages/google-area120-tables/tests/unit/gapic/tables_v1alpha1/test_tables_service.py +++ b/packages/google-area120-tables/tests/unit/gapic/tables_v1alpha1/test_tables_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TablesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( TablesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TablesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1278,11 +1283,13 @@ def test_tables_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7852,8 +7859,9 @@ def test_get_table_rest_bad_request(request_type=tables.GetTableRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7918,17 +7926,19 @@ def test_get_table_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_get_table" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_get_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_get_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_get_table" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_get_table_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_get_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7977,8 +7987,9 @@ def test_list_tables_rest_bad_request(request_type=tables.ListTablesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8041,17 +8052,19 @@ def test_list_tables_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_list_tables" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_list_tables_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_list_tables" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_list_tables" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_list_tables_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_list_tables" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8100,8 +8113,9 @@ def test_get_workspace_rest_bad_request(request_type=tables.GetWorkspaceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8166,17 +8180,19 @@ def test_get_workspace_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_get_workspace" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_get_workspace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_get_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_get_workspace" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_get_workspace_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_get_workspace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8225,8 +8241,9 @@ def test_list_workspaces_rest_bad_request(request_type=tables.ListWorkspacesRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8289,17 +8306,20 @@ def test_list_workspaces_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_list_workspaces" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_list_workspaces_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_list_workspaces" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_list_workspaces" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, + "post_list_workspaces_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_list_workspaces" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8350,8 +8370,9 @@ def test_get_row_rest_bad_request(request_type=tables.GetRowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8414,17 +8435,19 @@ def test_get_row_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_get_row" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_get_row_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_get_row" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_get_row" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_get_row_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_get_row" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8473,8 +8496,9 @@ def test_list_rows_rest_bad_request(request_type=tables.ListRowsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8537,17 +8561,19 @@ def test_list_rows_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_list_rows" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_list_rows_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_list_rows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_list_rows" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_list_rows_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_list_rows" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8596,8 +8622,9 @@ def test_create_row_rest_bad_request(request_type=tables.CreateRowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8728,17 +8755,19 @@ def test_create_row_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_create_row" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_create_row_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_create_row" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_create_row" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_create_row_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_create_row" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8787,8 +8816,9 @@ def test_batch_create_rows_rest_bad_request(request_type=tables.BatchCreateRowsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8848,17 +8878,20 @@ def test_batch_create_rows_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_batch_create_rows" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_batch_create_rows_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_batch_create_rows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_batch_create_rows" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, + "post_batch_create_rows_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_batch_create_rows" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8909,8 +8942,9 @@ def test_update_row_rest_bad_request(request_type=tables.UpdateRowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9041,17 +9075,19 @@ def test_update_row_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_update_row" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_update_row_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_update_row" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_update_row" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_update_row_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_update_row" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9100,8 +9136,9 @@ def test_batch_update_rows_rest_bad_request(request_type=tables.BatchUpdateRowsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9161,17 +9198,20 @@ def test_batch_update_rows_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_batch_update_rows" - ) as post, mock.patch.object( - transports.TablesServiceRestInterceptor, "post_batch_update_rows_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_batch_update_rows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "post_batch_update_rows" + ) as post, + mock.patch.object( + transports.TablesServiceRestInterceptor, + "post_batch_update_rows_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_batch_update_rows" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9222,8 +9262,9 @@ def test_delete_row_rest_bad_request(request_type=tables.DeleteRowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9280,13 +9321,13 @@ def test_delete_row_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_delete_row" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_delete_row" + ) as pre, + ): pre.assert_not_called() pb_message = tables.DeleteRowRequest.pb(tables.DeleteRowRequest()) transcode.return_value = { @@ -9327,8 +9368,9 @@ def test_batch_delete_rows_rest_bad_request(request_type=tables.BatchDeleteRowsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9385,13 +9427,13 @@ def test_batch_delete_rows_rest_interceptors(null_interceptor): ) client = TablesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TablesServiceRestInterceptor, "pre_batch_delete_rows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TablesServiceRestInterceptor, "pre_batch_delete_rows" + ) as pre, + ): pre.assert_not_called() pb_message = tables.BatchDeleteRowsRequest.pb(tables.BatchDeleteRowsRequest()) transcode.return_value = { @@ -9740,11 +9782,14 @@ def test_tables_service_base_transport(): def test_tables_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.area120.tables_v1alpha1.services.tables_service.transports.TablesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.area120.tables_v1alpha1.services.tables_service.transports.TablesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TablesServiceTransport( @@ -9768,9 +9813,12 @@ def test_tables_service_base_transport_with_credentials_file(): def test_tables_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.area120.tables_v1alpha1.services.tables_service.transports.TablesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.area120.tables_v1alpha1.services.tables_service.transports.TablesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TablesServiceTransport() @@ -9856,11 +9904,12 @@ def test_tables_service_transport_auth_gdch_credentials(transport_class): def test_tables_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py index 8573338f49f9..87855f00545b 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/async_client.py @@ -237,7 +237,7 @@ def transport(self) -> AccessApprovalTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py index fba24683e9f7..03ca551c8828 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/client.py @@ -147,7 +147,7 @@ class AccessApprovalClient(metaclass=AccessApprovalClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -155,7 +155,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -165,6 +165,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -500,7 +504,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -597,7 +601,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -693,7 +697,7 @@ def __init__( self._universe_domain = AccessApprovalClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/README.rst b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/README.rst index 06af384c0f8a..9597c78cfe33 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/README.rst +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AccessApprovalTransport` is the ABC for all transports. -- public child `AccessApprovalGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AccessApprovalGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAccessApprovalRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AccessApprovalRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AccessApprovalTransport`` is the ABC for all transports. + +- public child ``AccessApprovalGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AccessApprovalGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAccessApprovalRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AccessApprovalRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py index d38492a7f73c..f0f298046e31 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py index 28d227fe9043..2b8e9457a774 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -219,6 +219,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py index 74454dd68364..7b72b1909615 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -270,6 +270,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/rest.py b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/rest.py index 6119ab7b910c..c4fcc98d0f6c 100644 --- a/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/rest.py +++ b/packages/google-cloud-access-approval/google/cloud/accessapproval_v1/services/access_approval/transports/rest.py @@ -665,6 +665,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AccessApprovalRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-access-approval/noxfile.py b/packages/google-cloud-access-approval/noxfile.py index c219dc76a1e6..e8c058cfd34d 100644 --- a/packages/google-cloud-access-approval/noxfile.py +++ b/packages/google-cloud-access-approval/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-access-approval/setup.py b/packages/google-cloud-access-approval/setup.py index f625bcdb171f..1453290de178 100644 --- a/packages/google-cloud-access-approval/setup.py +++ b/packages/google-cloud-access-approval/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-access-approval" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-access-approval/testing/constraints-3.7.txt b/packages/google-cloud-access-approval/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-access-approval/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-access-approval/testing/constraints-3.8.txt b/packages/google-cloud-access-approval/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-access-approval/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-access-approval/testing/constraints-3.9.txt b/packages/google-cloud-access-approval/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-access-approval/testing/constraints-3.9.txt +++ b/packages/google-cloud-access-approval/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py b/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py index 8c7248d9a6b3..62eee46f7ede 100644 --- a/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py +++ b/packages/google-cloud-access-approval/tests/unit/gapic/accessapproval_v1/test_access_approval.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AccessApprovalClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( AccessApprovalClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AccessApprovalClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1282,11 +1287,13 @@ def test_access_approval_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5790,8 +5797,9 @@ def test_list_approval_requests_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5854,18 +5862,20 @@ def test_list_approval_requests_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_list_approval_requests" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_list_approval_requests_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_list_approval_requests" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "post_list_approval_requests" + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_list_approval_requests_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "pre_list_approval_requests" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5923,8 +5933,9 @@ def test_get_approval_request_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5989,18 +6000,20 @@ def test_get_approval_request_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_get_approval_request" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_get_approval_request_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_get_approval_request" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "post_get_approval_request" + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_get_approval_request_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "pre_get_approval_request" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6055,8 +6068,9 @@ def test_approve_approval_request_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6121,18 +6135,20 @@ def test_approve_approval_request_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_approve_approval_request" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_approve_approval_request_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_approve_approval_request" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "post_approve_approval_request" + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_approve_approval_request_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "pre_approve_approval_request" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6187,8 +6203,9 @@ def test_dismiss_approval_request_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6253,18 +6270,20 @@ def test_dismiss_approval_request_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_dismiss_approval_request" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_dismiss_approval_request_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_dismiss_approval_request" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "post_dismiss_approval_request" + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_dismiss_approval_request_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "pre_dismiss_approval_request" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6319,8 +6338,9 @@ def test_invalidate_approval_request_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6385,18 +6405,20 @@ def test_invalidate_approval_request_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_invalidate_approval_request" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_invalidate_approval_request_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_invalidate_approval_request" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "post_invalidate_approval_request" + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_invalidate_approval_request_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "pre_invalidate_approval_request" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6451,8 +6473,9 @@ def test_get_access_approval_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6525,18 +6548,21 @@ def test_get_access_approval_settings_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_get_access_approval_settings" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_get_access_approval_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_get_access_approval_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_get_access_approval_settings", + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_get_access_approval_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, "pre_get_access_approval_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6594,8 +6620,9 @@ def test_update_access_approval_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6751,18 +6778,22 @@ def test_update_access_approval_settings_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "post_update_access_approval_settings" - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_update_access_approval_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_update_access_approval_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_update_access_approval_settings", + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_update_access_approval_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "pre_update_access_approval_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6820,8 +6851,9 @@ def test_delete_access_approval_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6878,13 +6910,14 @@ def test_delete_access_approval_settings_rest_interceptors(null_interceptor): ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, "pre_delete_access_approval_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "pre_delete_access_approval_settings", + ) as pre, + ): pre.assert_not_called() pb_message = accessapproval.DeleteAccessApprovalSettingsMessage.pb( accessapproval.DeleteAccessApprovalSettingsMessage() @@ -6929,8 +6962,9 @@ def test_get_access_approval_service_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6995,20 +7029,22 @@ def test_get_access_approval_service_account_rest_interceptors(null_interceptor) ) client = AccessApprovalClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_get_access_approval_service_account", - ) as post, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "post_get_access_approval_service_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AccessApprovalRestInterceptor, - "pre_get_access_approval_service_account", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_get_access_approval_service_account", + ) as post, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "post_get_access_approval_service_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AccessApprovalRestInterceptor, + "pre_get_access_approval_service_account", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7321,11 +7357,14 @@ def test_access_approval_base_transport(): def test_access_approval_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AccessApprovalTransport( @@ -7342,9 +7381,12 @@ def test_access_approval_base_transport_with_credentials_file(): def test_access_approval_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.accessapproval_v1.services.access_approval.transports.AccessApprovalTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AccessApprovalTransport() @@ -7416,11 +7458,12 @@ def test_access_approval_transport_auth_gdch_credentials(transport_class): def test_access_approval_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.py b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.py index 7d241b53784f..accc75c92063 100644 --- a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.py +++ b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.py @@ -35,11 +35,6 @@ from google.api import resource_pb2 as google_dot_api_dot_resource__pb2 from google.iam.v1 import iam_policy_pb2 as google_dot_iam_dot_v1_dot_iam__policy__pb2 from google.iam.v1 import policy_pb2 as google_dot_iam_dot_v1_dot_policy__pb2 -from google.longrunning import ( - operations_pb2 as google_dot_longrunning_dot_operations__pb2, -) -from google.protobuf import field_mask_pb2 as google_dot_protobuf_dot_field__mask__pb2 - from google.identity.accesscontextmanager.v1 import ( access_level_pb2 as google_dot_identity_dot_accesscontextmanager_dot_v1_dot_access__level__pb2, ) @@ -52,6 +47,10 @@ from google.identity.accesscontextmanager.v1 import ( service_perimeter_pb2 as google_dot_identity_dot_accesscontextmanager_dot_v1_dot_service__perimeter__pb2, ) +from google.longrunning import ( + operations_pb2 as google_dot_longrunning_dot_operations__pb2, +) +from google.protobuf import field_mask_pb2 as google_dot_protobuf_dot_field__mask__pb2 DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( b'\nDgoogle/identity/accesscontextmanager/v1/access_context_manager.proto\x12\'google.identity.accesscontextmanager.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1egoogle/iam/v1/iam_policy.proto\x1a\x1agoogle/iam/v1/policy.proto\x1a:google/identity/accesscontextmanager/v1/access_level.proto\x1a;google/identity/accesscontextmanager/v1/access_policy.proto\x1a\x45google/identity/accesscontextmanager/v1/gcp_user_access_binding.proto\x1a?google/identity/accesscontextmanager/v1/service_perimeter.proto\x1a#google/longrunning/operations.proto\x1a google/protobuf/field_mask.proto"\x8c\x01\n\x19ListAccessPoliciesRequest\x12H\n\x06parent\x18\x01 \x01(\tB8\xe0\x41\x02\xfa\x41\x32\n0cloudresourcemanager.googleapis.com/Organization\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t"\x85\x01\n\x1aListAccessPoliciesResponse\x12N\n\x0f\x61\x63\x63\x65ss_policies\x18\x01 \x03(\x0b\x32\x35.google.identity.accesscontextmanager.v1.AccessPolicy\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t"`\n\x16GetAccessPolicyRequest\x12\x46\n\x04name\x18\x01 \x01(\tB8\xe0\x41\x02\xfa\x41\x32\n0accesscontextmanager.googleapis.com/AccessPolicy"\x9d\x01\n\x19UpdateAccessPolicyRequest\x12J\n\x06policy\x18\x01 \x01(\x0b\x32\x35.google.identity.accesscontextmanager.v1.AccessPolicyB\x03\xe0\x41\x02\x12\x34\n\x0bupdate_mask\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.FieldMaskB\x03\xe0\x41\x02"c\n\x19\x44\x65leteAccessPolicyRequest\x12\x46\n\x04name\x18\x01 \x01(\tB8\xe0\x41\x02\xfa\x41\x32\n0accesscontextmanager.googleapis.com/AccessPolicy"\xdc\x01\n\x17ListAccessLevelsRequest\x12G\n\x06parent\x18\x01 \x01(\tB7\xe0\x41\x02\xfa\x41\x31\x12/accesscontextmanager.googleapis.com/AccessLevel\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t\x12Q\n\x13\x61\x63\x63\x65ss_level_format\x18\x04 \x01(\x0e\x32\x34.google.identity.accesscontextmanager.v1.LevelFormat"\x80\x01\n\x18ListAccessLevelsResponse\x12K\n\raccess_levels\x18\x01 \x03(\x0b\x32\x34.google.identity.accesscontextmanager.v1.AccessLevel\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t"\xb1\x01\n\x15GetAccessLevelRequest\x12\x45\n\x04name\x18\x01 \x01(\tB7\xe0\x41\x02\xfa\x41\x31\n/accesscontextmanager.googleapis.com/AccessLevel\x12Q\n\x13\x61\x63\x63\x65ss_level_format\x18\x02 \x01(\x0e\x32\x34.google.identity.accesscontextmanager.v1.LevelFormat"\xb4\x01\n\x18\x43reateAccessLevelRequest\x12G\n\x06parent\x18\x01 \x01(\tB7\xe0\x41\x02\xfa\x41\x31\x12/accesscontextmanager.googleapis.com/AccessLevel\x12O\n\x0c\x61\x63\x63\x65ss_level\x18\x02 \x01(\x0b\x32\x34.google.identity.accesscontextmanager.v1.AccessLevelB\x03\xe0\x41\x02"\xa1\x01\n\x18UpdateAccessLevelRequest\x12O\n\x0c\x61\x63\x63\x65ss_level\x18\x01 \x01(\x0b\x32\x34.google.identity.accesscontextmanager.v1.AccessLevelB\x03\xe0\x41\x02\x12\x34\n\x0bupdate_mask\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.FieldMaskB\x03\xe0\x41\x02"a\n\x18\x44\x65leteAccessLevelRequest\x12\x45\n\x04name\x18\x01 \x01(\tB7\xe0\x41\x02\xfa\x41\x31\n/accesscontextmanager.googleapis.com/AccessLevel"\xc5\x01\n\x1aReplaceAccessLevelsRequest\x12G\n\x06parent\x18\x01 \x01(\tB7\xe0\x41\x02\xfa\x41\x31\x12/accesscontextmanager.googleapis.com/AccessLevel\x12P\n\raccess_levels\x18\x02 \x03(\x0b\x32\x34.google.identity.accesscontextmanager.v1.AccessLevelB\x03\xe0\x41\x02\x12\x0c\n\x04\x65tag\x18\x04 \x01(\t"j\n\x1bReplaceAccessLevelsResponse\x12K\n\raccess_levels\x18\x01 \x03(\x0b\x32\x34.google.identity.accesscontextmanager.v1.AccessLevel"\x93\x01\n\x1cListServicePerimetersRequest\x12L\n\x06parent\x18\x01 \x01(\tB<\xe0\x41\x02\xfa\x41\x36\x12\x34\x61\x63\x63\x65sscontextmanager.googleapis.com/ServicePerimeter\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t"\x8f\x01\n\x1dListServicePerimetersResponse\x12U\n\x12service_perimeters\x18\x01 \x03(\x0b\x32\x39.google.identity.accesscontextmanager.v1.ServicePerimeter\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t"h\n\x1aGetServicePerimeterRequest\x12J\n\x04name\x18\x01 \x01(\tB<\xe0\x41\x02\xfa\x41\x36\n4accesscontextmanager.googleapis.com/ServicePerimeter"\xc8\x01\n\x1d\x43reateServicePerimeterRequest\x12L\n\x06parent\x18\x01 \x01(\tB<\xe0\x41\x02\xfa\x41\x36\x12\x34\x61\x63\x63\x65sscontextmanager.googleapis.com/ServicePerimeter\x12Y\n\x11service_perimeter\x18\x02 \x01(\x0b\x32\x39.google.identity.accesscontextmanager.v1.ServicePerimeterB\x03\xe0\x41\x02"\xb0\x01\n\x1dUpdateServicePerimeterRequest\x12Y\n\x11service_perimeter\x18\x01 \x01(\x0b\x32\x39.google.identity.accesscontextmanager.v1.ServicePerimeterB\x03\xe0\x41\x02\x12\x34\n\x0bupdate_mask\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.FieldMaskB\x03\xe0\x41\x02"k\n\x1d\x44\x65leteServicePerimeterRequest\x12J\n\x04name\x18\x01 \x01(\tB<\xe0\x41\x02\xfa\x41\x36\n4accesscontextmanager.googleapis.com/ServicePerimeter"\xd9\x01\n\x1fReplaceServicePerimetersRequest\x12L\n\x06parent\x18\x01 \x01(\tB<\xe0\x41\x02\xfa\x41\x36\x12\x34\x61\x63\x63\x65sscontextmanager.googleapis.com/ServicePerimeter\x12Z\n\x12service_perimeters\x18\x02 \x03(\x0b\x32\x39.google.identity.accesscontextmanager.v1.ServicePerimeterB\x03\xe0\x41\x02\x12\x0c\n\x04\x65tag\x18\x03 \x01(\t"y\n ReplaceServicePerimetersResponse\x12U\n\x12service_perimeters\x18\x01 \x03(\x0b\x32\x39.google.identity.accesscontextmanager.v1.ServicePerimeter"|\n\x1e\x43ommitServicePerimetersRequest\x12L\n\x06parent\x18\x01 \x01(\tB<\xe0\x41\x02\xfa\x41\x36\x12\x34\x61\x63\x63\x65sscontextmanager.googleapis.com/ServicePerimeter\x12\x0c\n\x04\x65tag\x18\x02 \x01(\t"x\n\x1f\x43ommitServicePerimetersResponse\x12U\n\x12service_perimeters\x18\x01 \x03(\x0b\x32\x39.google.identity.accesscontextmanager.v1.ServicePerimeter"\x9d\x01\n ListGcpUserAccessBindingsRequest\x12H\n\x06parent\x18\x01 \x01(\tB8\xe0\x41\x02\xfa\x41\x32\n0cloudresourcemanager.googleapis.com/Organization\x12\x16\n\tpage_size\x18\x02 \x01(\x05\x42\x03\xe0\x41\x01\x12\x17\n\npage_token\x18\x03 \x01(\tB\x03\xe0\x41\x01"\x9d\x01\n!ListGcpUserAccessBindingsResponse\x12_\n\x18gcp_user_access_bindings\x18\x01 \x03(\x0b\x32=.google.identity.accesscontextmanager.v1.GcpUserAccessBinding\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t"p\n\x1eGetGcpUserAccessBindingRequest\x12N\n\x04name\x18\x01 \x01(\tB@\xe0\x41\x02\xfa\x41:\n8accesscontextmanager.googleapis.com/GcpUserAccessBinding"\xd2\x01\n!CreateGcpUserAccessBindingRequest\x12H\n\x06parent\x18\x01 \x01(\tB8\xe0\x41\x02\xfa\x41\x32\n0cloudresourcemanager.googleapis.com/Organization\x12\x63\n\x17gcp_user_access_binding\x18\x02 \x01(\x0b\x32=.google.identity.accesscontextmanager.v1.GcpUserAccessBindingB\x03\xe0\x41\x02"\xbe\x01\n!UpdateGcpUserAccessBindingRequest\x12\x63\n\x17gcp_user_access_binding\x18\x01 \x01(\x0b\x32=.google.identity.accesscontextmanager.v1.GcpUserAccessBindingB\x03\xe0\x41\x02\x12\x34\n\x0bupdate_mask\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.FieldMaskB\x03\xe0\x41\x02"s\n!DeleteGcpUserAccessBindingRequest\x12N\n\x04name\x18\x01 \x01(\tB@\xe0\x41\x02\xfa\x41:\n8accesscontextmanager.googleapis.com/GcpUserAccessBinding"\'\n%GcpUserAccessBindingOperationMetadata"\'\n%AccessContextManagerOperationMetadata*D\n\x0bLevelFormat\x12\x1c\n\x18LEVEL_FORMAT_UNSPECIFIED\x10\x00\x12\x0e\n\nAS_DEFINED\x10\x01\x12\x07\n\x03\x43\x45L\x10\x02\x32\xf1\x32\n\x14\x41\x63\x63\x65ssContextManager\x12\xb9\x01\n\x12ListAccessPolicies\x12\x42.google.identity.accesscontextmanager.v1.ListAccessPoliciesRequest\x1a\x43.google.identity.accesscontextmanager.v1.ListAccessPoliciesResponse"\x1a\x82\xd3\xe4\x93\x02\x14\x12\x12/v1/accessPolicies\x12\xb5\x01\n\x0fGetAccessPolicy\x12?.google.identity.accesscontextmanager.v1.GetAccessPolicyRequest\x1a\x35.google.identity.accesscontextmanager.v1.AccessPolicy"*\xda\x41\x04name\x82\xd3\xe4\x93\x02\x1d\x12\x1b/v1/{name=accessPolicies/*}\x12\xc1\x01\n\x12\x43reateAccessPolicy\x12\x35.google.identity.accesscontextmanager.v1.AccessPolicy\x1a\x1d.google.longrunning.Operation"U\xca\x41\x35\n\x0c\x41\x63\x63\x65ssPolicy\x12%AccessContextManagerOperationMetadata\x82\xd3\xe4\x93\x02\x17"\x12/v1/accessPolicies:\x01*\x12\xf8\x01\n\x12UpdateAccessPolicy\x12\x42.google.identity.accesscontextmanager.v1.UpdateAccessPolicyRequest\x1a\x1d.google.longrunning.Operation"\x7f\xca\x41\x35\n\x0c\x41\x63\x63\x65ssPolicy\x12%AccessContextManagerOperationMetadata\xda\x41\x12policy,update_mask\x82\xd3\xe4\x93\x02,2"/v1/{policy.name=accessPolicies/*}:\x06policy\x12\xe4\x01\n\x12\x44\x65leteAccessPolicy\x12\x42.google.identity.accesscontextmanager.v1.DeleteAccessPolicyRequest\x1a\x1d.google.longrunning.Operation"k\xca\x41>\n\x15google.protobuf.Empty\x12%AccessContextManagerOperationMetadata\xda\x41\x04name\x82\xd3\xe4\x93\x02\x1d*\x1b/v1/{name=accessPolicies/*}\x12\xd4\x01\n\x10ListAccessLevels\x12@.google.identity.accesscontextmanager.v1.ListAccessLevelsRequest\x1a\x41.google.identity.accesscontextmanager.v1.ListAccessLevelsResponse";\xda\x41\x06parent\x82\xd3\xe4\x93\x02,\x12*/v1/{parent=accessPolicies/*}/accessLevels\x12\xc1\x01\n\x0eGetAccessLevel\x12>.google.identity.accesscontextmanager.v1.GetAccessLevelRequest\x1a\x34.google.identity.accesscontextmanager.v1.AccessLevel"9\xda\x41\x04name\x82\xd3\xe4\x93\x02,\x12*/v1/{name=accessPolicies/*/accessLevels/*}\x12\x85\x02\n\x11\x43reateAccessLevel\x12\x41.google.identity.accesscontextmanager.v1.CreateAccessLevelRequest\x1a\x1d.google.longrunning.Operation"\x8d\x01\xca\x41\x34\n\x0b\x41\x63\x63\x65ssLevel\x12%AccessContextManagerOperationMetadata\xda\x41\x13parent,access_level\x82\xd3\xe4\x93\x02:"*/v1/{parent=accessPolicies/*}/accessLevels:\x0c\x61\x63\x63\x65ss_level\x12\x97\x02\n\x11UpdateAccessLevel\x12\x41.google.identity.accesscontextmanager.v1.UpdateAccessLevelRequest\x1a\x1d.google.longrunning.Operation"\x9f\x01\xca\x41\x34\n\x0b\x41\x63\x63\x65ssLevel\x12%AccessContextManagerOperationMetadata\xda\x41\x18\x61\x63\x63\x65ss_level,update_mask\x82\xd3\xe4\x93\x02G27/v1/{access_level.name=accessPolicies/*/accessLevels/*}:\x0c\x61\x63\x63\x65ss_level\x12\xf1\x01\n\x11\x44\x65leteAccessLevel\x12\x41.google.identity.accesscontextmanager.v1.DeleteAccessLevelRequest\x1a\x1d.google.longrunning.Operation"z\xca\x41>\n\x15google.protobuf.Empty\x12%AccessContextManagerOperationMetadata\xda\x41\x04name\x82\xd3\xe4\x93\x02,**/v1/{name=accessPolicies/*/accessLevels/*}\x12\x83\x02\n\x13ReplaceAccessLevels\x12\x43.google.identity.accesscontextmanager.v1.ReplaceAccessLevelsRequest\x1a\x1d.google.longrunning.Operation"\x87\x01\xca\x41\x44\n\x1bReplaceAccessLevelsResponse\x12%AccessContextManagerOperationMetadata\x82\xd3\xe4\x93\x02:"5/v1/{parent=accessPolicies/*}/accessLevels:replaceAll:\x01*\x12\xe8\x01\n\x15ListServicePerimeters\x12\x45.google.identity.accesscontextmanager.v1.ListServicePerimetersRequest\x1a\x46.google.identity.accesscontextmanager.v1.ListServicePerimetersResponse"@\xda\x41\x06parent\x82\xd3\xe4\x93\x02\x31\x12//v1/{parent=accessPolicies/*}/servicePerimeters\x12\xd5\x01\n\x13GetServicePerimeter\x12\x43.google.identity.accesscontextmanager.v1.GetServicePerimeterRequest\x1a\x39.google.identity.accesscontextmanager.v1.ServicePerimeter">\xda\x41\x04name\x82\xd3\xe4\x93\x02\x31\x12//v1/{name=accessPolicies/*/servicePerimeters/*}\x12\xa3\x02\n\x16\x43reateServicePerimeter\x12\x46.google.identity.accesscontextmanager.v1.CreateServicePerimeterRequest\x1a\x1d.google.longrunning.Operation"\xa1\x01\xca\x41\x39\n\x10ServicePerimeter\x12%AccessContextManagerOperationMetadata\xda\x41\x18parent,service_perimeter\x82\xd3\xe4\x93\x02\x44"//v1/{parent=accessPolicies/*}/servicePerimeters:\x11service_perimeter\x12\xba\x02\n\x16UpdateServicePerimeter\x12\x46.google.identity.accesscontextmanager.v1.UpdateServicePerimeterRequest\x1a\x1d.google.longrunning.Operation"\xb8\x01\xca\x41\x39\n\x10ServicePerimeter\x12%AccessContextManagerOperationMetadata\xda\x41\x1dservice_perimeter,update_mask\x82\xd3\xe4\x93\x02V2A/v1/{service_perimeter.name=accessPolicies/*/servicePerimeters/*}:\x11service_perimeter\x12\x80\x02\n\x16\x44\x65leteServicePerimeter\x12\x46.google.identity.accesscontextmanager.v1.DeleteServicePerimeterRequest\x1a\x1d.google.longrunning.Operation"\x7f\xca\x41>\n\x15google.protobuf.Empty\x12%AccessContextManagerOperationMetadata\xda\x41\x04name\x82\xd3\xe4\x93\x02\x31*//v1/{name=accessPolicies/*/servicePerimeters/*}\x12\x97\x02\n\x18ReplaceServicePerimeters\x12H.google.identity.accesscontextmanager.v1.ReplaceServicePerimetersRequest\x1a\x1d.google.longrunning.Operation"\x91\x01\xca\x41I\n ReplaceServicePerimetersResponse\x12%AccessContextManagerOperationMetadata\x82\xd3\xe4\x93\x02?":/v1/{parent=accessPolicies/*}/servicePerimeters:replaceAll:\x01*\x12\x90\x02\n\x17\x43ommitServicePerimeters\x12G.google.identity.accesscontextmanager.v1.CommitServicePerimetersRequest\x1a\x1d.google.longrunning.Operation"\x8c\x01\xca\x41H\n\x1f\x43ommitServicePerimetersResponse\x12%AccessContextManagerOperationMetadata\x82\xd3\xe4\x93\x02;"6/v1/{parent=accessPolicies/*}/servicePerimeters:commit:\x01*\x12\xf7\x01\n\x19ListGcpUserAccessBindings\x12I.google.identity.accesscontextmanager.v1.ListGcpUserAccessBindingsRequest\x1aJ.google.identity.accesscontextmanager.v1.ListGcpUserAccessBindingsResponse"C\xda\x41\x06parent\x82\xd3\xe4\x93\x02\x34\x12\x32/v1/{parent=organizations/*}/gcpUserAccessBindings\x12\xe4\x01\n\x17GetGcpUserAccessBinding\x12G.google.identity.accesscontextmanager.v1.GetGcpUserAccessBindingRequest\x1a=.google.identity.accesscontextmanager.v1.GcpUserAccessBinding"A\xda\x41\x04name\x82\xd3\xe4\x93\x02\x34\x12\x32/v1/{name=organizations/*/gcpUserAccessBindings/*}\x12\xbe\x02\n\x1a\x43reateGcpUserAccessBinding\x12J.google.identity.accesscontextmanager.v1.CreateGcpUserAccessBindingRequest\x1a\x1d.google.longrunning.Operation"\xb4\x01\xca\x41=\n\x14GcpUserAccessBinding\x12%GcpUserAccessBindingOperationMetadata\xda\x41\x1eparent,gcp_user_access_binding\x82\xd3\xe4\x93\x02M"2/v1/{parent=organizations/*}/gcpUserAccessBindings:\x17gcp_user_access_binding\x12\xdb\x02\n\x1aUpdateGcpUserAccessBinding\x12J.google.identity.accesscontextmanager.v1.UpdateGcpUserAccessBindingRequest\x1a\x1d.google.longrunning.Operation"\xd1\x01\xca\x41=\n\x14GcpUserAccessBinding\x12%GcpUserAccessBindingOperationMetadata\xda\x41#gcp_user_access_binding,update_mask\x82\xd3\xe4\x93\x02\x65\x32J/v1/{gcp_user_access_binding.name=organizations/*/gcpUserAccessBindings/*}:\x17gcp_user_access_binding\x12\x8c\x02\n\x1a\x44\x65leteGcpUserAccessBinding\x12J.google.identity.accesscontextmanager.v1.DeleteGcpUserAccessBindingRequest\x1a\x1d.google.longrunning.Operation"\x82\x01\xca\x41>\n\x15google.protobuf.Empty\x12%GcpUserAccessBindingOperationMetadata\xda\x41\x04name\x82\xd3\xe4\x93\x02\x34*2/v1/{name=organizations/*/gcpUserAccessBindings/*}\x12\x82\x01\n\x0cSetIamPolicy\x12".google.iam.v1.SetIamPolicyRequest\x1a\x15.google.iam.v1.Policy"7\x82\xd3\xe4\x93\x02\x31",/v1/{resource=accessPolicies/*}:setIamPolicy:\x01*\x12\x82\x01\n\x0cGetIamPolicy\x12".google.iam.v1.GetIamPolicyRequest\x1a\x15.google.iam.v1.Policy"7\x82\xd3\xe4\x93\x02\x31",/v1/{resource=accessPolicies/*}:getIamPolicy:\x01*\x12\xbf\x02\n\x12TestIamPermissions\x12(.google.iam.v1.TestIamPermissionsRequest\x1a).google.iam.v1.TestIamPermissionsResponse"\xd3\x01\x82\xd3\xe4\x93\x02\xcc\x01"2/v1/{resource=accessPolicies/*}:testIamPermissions:\x01*ZF"A/v1/{resource=accessPolicies/*/accessLevels/*}:testIamPermissions:\x01*ZK"F/v1/{resource=accessPolicies/*/servicePerimeters/*}:testIamPermissions:\x01*\x1aW\xca\x41#accesscontextmanager.googleapis.com\xd2\x41.https://www.googleapis.com/auth/cloud-platformB\xb0\x02\n+com.google.identity.accesscontextmanager.v1B\x19\x41\x63\x63\x65ssContextManagerProtoP\x01Z\\cloud.google.com/go/accesscontextmanager/apiv1/accesscontextmanagerpb;accesscontextmanagerpb\xa2\x02\x04GACM\xaa\x02\'Google.Identity.AccessContextManager.V1\xca\x02\'Google\\Identity\\AccessContextManager\\V1\xea\x02*Google::Identity::AccessContextManager::V1b\x06proto3' diff --git a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.pyi b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.pyi index 224259c3ce20..18dd69c9ff91 100644 --- a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.pyi +++ b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_context_manager_pb2.pyi @@ -24,13 +24,6 @@ from google.api import field_behavior_pb2 as _field_behavior_pb2 from google.api import resource_pb2 as _resource_pb2 from google.iam.v1 import iam_policy_pb2 as _iam_policy_pb2 from google.iam.v1 import policy_pb2 as _policy_pb2 -from google.longrunning import operations_pb2 as _operations_pb2 -from google.protobuf import descriptor as _descriptor -from google.protobuf import field_mask_pb2 as _field_mask_pb2 -from google.protobuf import message as _message -from google.protobuf.internal import containers as _containers -from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper - from google.identity.accesscontextmanager.v1 import ( access_level_pb2 as _access_level_pb2, ) @@ -43,6 +36,12 @@ from google.identity.accesscontextmanager.v1 import ( from google.identity.accesscontextmanager.v1 import ( service_perimeter_pb2 as _service_perimeter_pb2, ) +from google.longrunning import operations_pb2 as _operations_pb2 +from google.protobuf import descriptor as _descriptor +from google.protobuf import field_mask_pb2 as _field_mask_pb2 +from google.protobuf import message as _message +from google.protobuf.internal import containers as _containers +from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper DESCRIPTOR: _descriptor.FileDescriptor diff --git a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.py b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.py index a38fabfc12b2..08cd949e9c0b 100644 --- a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.py +++ b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.py @@ -30,12 +30,11 @@ from google.api import resource_pb2 as google_dot_api_dot_resource__pb2 -from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 -from google.type import expr_pb2 as google_dot_type_dot_expr__pb2 - from google.identity.accesscontextmanager.type import ( device_resources_pb2 as google_dot_identity_dot_accesscontextmanager_dot_type_dot_device__resources__pb2, ) +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 +from google.type import expr_pb2 as google_dot_type_dot_expr__pb2 DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( b'\n:google/identity/accesscontextmanager/v1/access_level.proto\x12\'google.identity.accesscontextmanager.v1\x1a\x19google/api/resource.proto\x1a@google/identity/accesscontextmanager/type/device_resources.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x16google/type/expr.proto"\xaa\x03\n\x0b\x41\x63\x63\x65ssLevel\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05title\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x44\n\x05\x62\x61sic\x18\x04 \x01(\x0b\x32\x33.google.identity.accesscontextmanager.v1.BasicLevelH\x00\x12\x46\n\x06\x63ustom\x18\x05 \x01(\x0b\x32\x34.google.identity.accesscontextmanager.v1.CustomLevelH\x00\x12/\n\x0b\x63reate_time\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12/\n\x0bupdate_time\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.Timestamp:p\xea\x41m\n/accesscontextmanager.googleapis.com/AccessLevel\x12:accessPolicies/{access_policy}/accessLevels/{access_level}B\x07\n\x05level"\xef\x01\n\nBasicLevel\x12\x46\n\nconditions\x18\x01 \x03(\x0b\x32\x32.google.identity.accesscontextmanager.v1.Condition\x12j\n\x12\x63ombining_function\x18\x02 \x01(\x0e\x32N.google.identity.accesscontextmanager.v1.BasicLevel.ConditionCombiningFunction"-\n\x1a\x43onditionCombiningFunction\x12\x07\n\x03\x41ND\x10\x00\x12\x06\n\x02OR\x10\x01"\xc3\x01\n\tCondition\x12\x16\n\x0eip_subnetworks\x18\x01 \x03(\t\x12L\n\rdevice_policy\x18\x02 \x01(\x0b\x32\x35.google.identity.accesscontextmanager.v1.DevicePolicy\x12\x1e\n\x16required_access_levels\x18\x03 \x03(\t\x12\x0e\n\x06negate\x18\x05 \x01(\x08\x12\x0f\n\x07members\x18\x06 \x03(\t\x12\x0f\n\x07regions\x18\x07 \x03(\t".\n\x0b\x43ustomLevel\x12\x1f\n\x04\x65xpr\x18\x01 \x01(\x0b\x32\x11.google.type.Expr"\x89\x03\n\x0c\x44\x65vicePolicy\x12\x1a\n\x12require_screenlock\x18\x01 \x01(\x08\x12\x66\n\x1b\x61llowed_encryption_statuses\x18\x02 \x03(\x0e\x32\x41.google.identity.accesscontextmanager.type.DeviceEncryptionStatus\x12M\n\x0eos_constraints\x18\x03 \x03(\x0b\x32\x35.google.identity.accesscontextmanager.v1.OsConstraint\x12j\n allowed_device_management_levels\x18\x06 \x03(\x0e\x32@.google.identity.accesscontextmanager.type.DeviceManagementLevel\x12\x1e\n\x16require_admin_approval\x18\x07 \x01(\x08\x12\x1a\n\x12require_corp_owned\x18\x08 \x01(\x08"\x8f\x01\n\x0cOsConstraint\x12\x42\n\x07os_type\x18\x01 \x01(\x0e\x32\x31.google.identity.accesscontextmanager.type.OsType\x12\x17\n\x0fminimum_version\x18\x02 \x01(\t\x12"\n\x1arequire_verified_chrome_os\x18\x03 \x01(\x08\x42\xa7\x02\n+com.google.identity.accesscontextmanager.v1B\x10\x41\x63\x63\x65ssLevelProtoP\x01Z\\cloud.google.com/go/accesscontextmanager/apiv1/accesscontextmanagerpb;accesscontextmanagerpb\xa2\x02\x04GACM\xaa\x02\'Google.Identity.AccessContextManager.V1\xca\x02\'Google\\Identity\\AccessContextManager\\V1\xea\x02*Google::Identity::AccessContextManager::V1b\x06proto3' diff --git a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.pyi b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.pyi index 295578a1c520..b97e687528b9 100644 --- a/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.pyi +++ b/packages/google-cloud-access-context-manager/google/identity/accesscontextmanager/v1/access_level_pb2.pyi @@ -19,6 +19,9 @@ from typing import Optional as _Optional from typing import Union as _Union from google.api import resource_pb2 as _resource_pb2 +from google.identity.accesscontextmanager.type import ( + device_resources_pb2 as _device_resources_pb2, +) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import timestamp_pb2 as _timestamp_pb2 @@ -26,10 +29,6 @@ from google.protobuf.internal import containers as _containers from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper from google.type import expr_pb2 as _expr_pb2 -from google.identity.accesscontextmanager.type import ( - device_resources_pb2 as _device_resources_pb2, -) - DESCRIPTOR: _descriptor.FileDescriptor class AccessLevel(_message.Message): diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/async_client.py b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/async_client.py index 2b00aa9a3aee..e70d2136dcf7 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/async_client.py +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> AdvisoryNotificationsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/client.py b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/client.py index 47cec9048972..35886db17d36 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/client.py +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/client.py @@ -117,7 +117,7 @@ class AdvisoryNotificationsServiceClient( """Service to manage Security and Privacy Notifications.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -466,7 +470,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -667,7 +671,7 @@ def __init__( self._universe_domain = AdvisoryNotificationsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/README.rst b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/README.rst index 8e602234652d..61b44fd9303c 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/README.rst +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AdvisoryNotificationsServiceTransport` is the ABC for all transports. -- public child `AdvisoryNotificationsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AdvisoryNotificationsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAdvisoryNotificationsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AdvisoryNotificationsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AdvisoryNotificationsServiceTransport`` is the ABC for all transports. + +- public child ``AdvisoryNotificationsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AdvisoryNotificationsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAdvisoryNotificationsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AdvisoryNotificationsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/base.py b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/base.py index 1528dbcbeafe..15bdef2a3f2d 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/base.py +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc.py b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc.py index e8d913c28d4e..55c71adf8e3d 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc.py +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc_asyncio.py b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc_asyncio.py index 91ff73349717..f1ce3f6f1571 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/rest.py b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/rest.py index 91ddddfc9f8a..52b050752b41 100644 --- a/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/rest.py +++ b/packages/google-cloud-advisorynotifications/google/cloud/advisorynotifications_v1/services/advisory_notifications_service/transports/rest.py @@ -363,6 +363,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AdvisoryNotificationsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-advisorynotifications/noxfile.py b/packages/google-cloud-advisorynotifications/noxfile.py index 8b9d807cd503..eca950b035cd 100644 --- a/packages/google-cloud-advisorynotifications/noxfile.py +++ b/packages/google-cloud-advisorynotifications/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-advisorynotifications/setup.py b/packages/google-cloud-advisorynotifications/setup.py index 690f40307cf9..35a4aa8cffac 100644 --- a/packages/google-cloud-advisorynotifications/setup.py +++ b/packages/google-cloud-advisorynotifications/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-advisorynotifications" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-advisorynotifications/testing/constraints-3.7.txt b/packages/google-cloud-advisorynotifications/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-advisorynotifications/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-advisorynotifications/testing/constraints-3.8.txt b/packages/google-cloud-advisorynotifications/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-advisorynotifications/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-advisorynotifications/testing/constraints-3.9.txt b/packages/google-cloud-advisorynotifications/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-advisorynotifications/testing/constraints-3.9.txt +++ b/packages/google-cloud-advisorynotifications/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-advisorynotifications/tests/unit/gapic/advisorynotifications_v1/test_advisory_notifications_service.py b/packages/google-cloud-advisorynotifications/tests/unit/gapic/advisorynotifications_v1/test_advisory_notifications_service.py index 305ca1b6cc37..f46b55e0d2b5 100644 --- a/packages/google-cloud-advisorynotifications/tests/unit/gapic/advisorynotifications_v1/test_advisory_notifications_service.py +++ b/packages/google-cloud-advisorynotifications/tests/unit/gapic/advisorynotifications_v1/test_advisory_notifications_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AdvisoryNotificationsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): AdvisoryNotificationsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AdvisoryNotificationsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1388,11 +1393,13 @@ def test_advisory_notifications_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4080,8 +4087,9 @@ def test_list_notifications_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4146,19 +4154,22 @@ def test_list_notifications_rest_interceptors(null_interceptor): ) client = AdvisoryNotificationsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, - "post_list_notifications", - ) as post, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, - "post_list_notifications_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "pre_list_notifications" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_list_notifications", + ) as post, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_list_notifications_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "pre_list_notifications", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4213,8 +4224,9 @@ def test_get_notification_rest_bad_request(request_type=service.GetNotificationR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4284,18 +4296,22 @@ def test_get_notification_rest_interceptors(null_interceptor): ) client = AdvisoryNotificationsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "post_get_notification" - ) as post, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, - "post_get_notification_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "pre_get_notification" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_get_notification", + ) as post, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_get_notification_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "pre_get_notification", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4344,8 +4360,9 @@ def test_get_settings_rest_bad_request(request_type=service.GetSettingsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4410,18 +4427,20 @@ def test_get_settings_rest_interceptors(null_interceptor): ) client = AdvisoryNotificationsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "post_get_settings" - ) as post, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, - "post_get_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "pre_get_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, "post_get_settings" + ) as post, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_get_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, "pre_get_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4472,8 +4491,9 @@ def test_update_settings_rest_bad_request(request_type=service.UpdateSettingsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4612,18 +4632,22 @@ def test_update_settings_rest_interceptors(null_interceptor): ) client = AdvisoryNotificationsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "post_update_settings" - ) as post, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, - "post_update_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AdvisoryNotificationsServiceRestInterceptor, "pre_update_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_update_settings", + ) as post, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "post_update_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AdvisoryNotificationsServiceRestInterceptor, + "pre_update_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4808,11 +4832,14 @@ def test_advisory_notifications_service_base_transport(): def test_advisory_notifications_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.advisorynotifications_v1.services.advisory_notifications_service.transports.AdvisoryNotificationsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.advisorynotifications_v1.services.advisory_notifications_service.transports.AdvisoryNotificationsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdvisoryNotificationsServiceTransport( @@ -4829,9 +4856,12 @@ def test_advisory_notifications_service_base_transport_with_credentials_file(): def test_advisory_notifications_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.advisorynotifications_v1.services.advisory_notifications_service.transports.AdvisoryNotificationsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.advisorynotifications_v1.services.advisory_notifications_service.transports.AdvisoryNotificationsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdvisoryNotificationsServiceTransport() @@ -4910,11 +4940,12 @@ def test_advisory_notifications_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-alloydb-connectors/noxfile.py b/packages/google-cloud-alloydb-connectors/noxfile.py index 6e156b7ef562..a6b788dcb03e 100644 --- a/packages/google-cloud-alloydb-connectors/noxfile.py +++ b/packages/google-cloud-alloydb-connectors/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-alloydb-connectors/setup.py b/packages/google-cloud-alloydb-connectors/setup.py index 0dcf9d4d58b3..f69d50cfb965 100644 --- a/packages/google-cloud-alloydb-connectors/setup.py +++ b/packages/google-cloud-alloydb-connectors/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-alloydb-connectors" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-alloydb-connectors/testing/constraints-3.7.txt b/packages/google-cloud-alloydb-connectors/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-alloydb-connectors/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-alloydb-connectors/testing/constraints-3.8.txt b/packages/google-cloud-alloydb-connectors/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-alloydb-connectors/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-alloydb-connectors/testing/constraints-3.9.txt b/packages/google-cloud-alloydb-connectors/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-alloydb-connectors/testing/constraints-3.9.txt +++ b/packages/google-cloud-alloydb-connectors/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/async_client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/async_client.py index 518ebc19544e..0cb4cef4115e 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/async_client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/async_client.py @@ -223,7 +223,7 @@ def transport(self) -> AlloyDBAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5243,7 +5243,7 @@ async def sample_list_databases(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5269,8 +5269,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5279,7 +5283,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5287,7 +5291,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5298,7 +5302,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5324,8 +5328,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5334,7 +5342,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5342,7 +5350,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5353,7 +5361,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5383,8 +5391,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5393,7 +5405,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5401,7 +5413,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5409,7 +5421,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5438,8 +5450,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5448,7 +5464,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5456,7 +5472,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5464,7 +5480,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5490,8 +5506,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5500,7 +5520,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5508,7 +5528,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5519,7 +5539,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5545,8 +5565,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5555,7 +5579,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5563,7 +5587,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/client.py index 0ac012522395..3107d05de2ab 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/client.py @@ -121,7 +121,7 @@ class AlloyDBAdminClient(metaclass=AlloyDBAdminClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -677,7 +681,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -774,7 +778,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -870,7 +874,7 @@ def __init__( self._universe_domain = AlloyDBAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5787,7 +5791,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5813,8 +5817,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5823,7 +5831,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5832,7 +5840,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5846,7 +5854,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5872,8 +5880,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5882,7 +5894,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5891,7 +5903,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5905,7 +5917,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5935,8 +5947,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5945,7 +5961,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5953,7 +5969,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5961,7 +5977,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5990,8 +6006,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6000,7 +6020,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6008,7 +6028,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6016,7 +6036,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6042,8 +6062,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6052,7 +6076,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6061,7 +6085,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6075,7 +6099,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6101,8 +6125,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6111,7 +6139,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6120,7 +6148,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/README.rst b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/README.rst index 6bacf2452a64..31b9a5a9ef4f 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/README.rst +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlloyDBAdminTransport` is the ABC for all transports. -- public child `AlloyDBAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlloyDBAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlloyDBAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlloyDBAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlloyDBAdminTransport`` is the ABC for all transports. + +- public child ``AlloyDBAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlloyDBAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlloyDBAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlloyDBAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/base.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/base.py index b3813310d6dc..ca5ddaa043ec 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/base.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc.py index 6b1ca683c616..aad70fc3dfed 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc_asyncio.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc_asyncio.py index 6c118b0b9003..dac4f74b7d28 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/rest.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/rest.py index 6e3683c3cfb9..f5324ad09b68 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/rest.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_db_admin/transports/rest.py @@ -2270,6 +2270,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlloyDBAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/async_client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/async_client.py index 67743977a662..fc101c598ed0 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/async_client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> AlloyDBCSQLAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -466,7 +466,7 @@ async def sample_restore_from_cloud_sql(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -492,8 +492,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -502,7 +506,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -510,7 +514,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -521,7 +525,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -547,8 +551,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -557,7 +565,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -565,7 +573,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -576,7 +584,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -606,8 +614,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -616,7 +628,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -624,7 +636,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -632,7 +644,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -661,8 +673,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -671,7 +687,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -679,7 +695,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -687,7 +703,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -713,8 +729,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -723,7 +743,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -731,7 +751,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -742,7 +762,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -768,8 +788,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -778,7 +802,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -786,7 +810,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/client.py index b2ee864de728..78ff1330e750 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/client.py @@ -117,7 +117,7 @@ class AlloyDBCSQLAdminClient(metaclass=AlloyDBCSQLAdminClientMeta): """Service for interactions with CloudSQL.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -533,7 +537,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -630,7 +634,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -728,7 +732,7 @@ def __init__( self._universe_domain = AlloyDBCSQLAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -986,7 +990,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1012,8 +1016,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1022,7 +1030,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1031,7 +1039,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1045,7 +1053,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1071,8 +1079,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1081,7 +1093,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1090,7 +1102,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1116,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1146,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1160,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1168,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1160,7 +1176,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1189,8 +1205,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1199,7 +1219,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1207,7 +1227,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1215,7 +1235,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1241,8 +1261,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1251,7 +1275,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1260,7 +1284,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1274,7 +1298,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1300,8 +1324,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1310,7 +1338,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1319,7 +1347,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/README.rst b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/README.rst index ba9a1b018967..951cec18ca3d 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/README.rst +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlloyDBCSQLAdminTransport` is the ABC for all transports. -- public child `AlloyDBCSQLAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlloyDBCSQLAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlloyDBCSQLAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlloyDBCSQLAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlloyDBCSQLAdminTransport`` is the ABC for all transports. + +- public child ``AlloyDBCSQLAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlloyDBCSQLAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlloyDBCSQLAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlloyDBCSQLAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/base.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/base.py index ea345918b998..b7733b583138 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/base.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc.py index b38cd72fa72d..604c93a16677 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc_asyncio.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc_asyncio.py index c485adf330f8..6b9ac1dbd927 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/rest.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/rest.py index 6e85f65244af..66a5b64d47ee 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/rest.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1/services/alloy_dbcsql_admin/transports/rest.py @@ -353,6 +353,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlloyDBCSQLAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/async_client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/async_client.py index 42be693bf78b..8d5ef443544f 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/async_client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> AlloyDBAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5376,7 +5376,7 @@ async def sample_create_database(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5402,8 +5402,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5412,7 +5416,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5420,7 +5424,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5431,7 +5435,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5457,8 +5461,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5467,7 +5475,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5475,7 +5483,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5486,7 +5494,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5516,8 +5524,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5526,7 +5538,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5534,7 +5546,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5542,7 +5554,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5571,8 +5583,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5581,7 +5597,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5589,7 +5605,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5597,7 +5613,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5623,8 +5639,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5633,7 +5653,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5641,7 +5661,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5652,7 +5672,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5678,8 +5698,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5688,7 +5712,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5696,7 +5720,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/client.py index 468894db98a4..2dd6d514ef76 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/client.py @@ -127,7 +127,7 @@ class AlloyDBAdminClient(metaclass=AlloyDBAdminClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -683,7 +687,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -780,7 +784,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -876,7 +880,7 @@ def __init__( self._universe_domain = AlloyDBAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5917,7 +5921,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5943,8 +5947,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5953,7 +5961,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5962,7 +5970,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5976,7 +5984,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6002,8 +6010,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6012,7 +6024,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6021,7 +6033,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6035,7 +6047,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6065,8 +6077,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6075,7 +6091,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6083,7 +6099,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6091,7 +6107,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6120,8 +6136,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6130,7 +6150,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6138,7 +6158,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6146,7 +6166,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6172,8 +6192,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6182,7 +6206,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6191,7 +6215,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6205,7 +6229,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6231,8 +6255,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6241,7 +6269,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6250,7 +6278,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/README.rst b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/README.rst index 6bacf2452a64..31b9a5a9ef4f 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/README.rst +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlloyDBAdminTransport` is the ABC for all transports. -- public child `AlloyDBAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlloyDBAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlloyDBAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlloyDBAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlloyDBAdminTransport`` is the ABC for all transports. + +- public child ``AlloyDBAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlloyDBAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlloyDBAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlloyDBAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/base.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/base.py index 6f00282f2e2a..63d8cbb31e70 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/base.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc.py index f64c0aa3c67c..c5ad3a51055c 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc_asyncio.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc_asyncio.py index f01a3ce516ba..269b7318d0d3 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/rest.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/rest.py index eca3c90c1956..8283e5bdc92b 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/rest.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_db_admin/transports/rest.py @@ -2322,6 +2322,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlloyDBAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/async_client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/async_client.py index 16fd573599f1..11d8d1d18bc0 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/async_client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> AlloyDBCSQLAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -466,7 +466,7 @@ async def sample_restore_from_cloud_sql(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -492,8 +492,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -502,7 +506,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -510,7 +514,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -521,7 +525,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -547,8 +551,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -557,7 +565,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -565,7 +573,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -576,7 +584,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -606,8 +614,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -616,7 +628,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -624,7 +636,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -632,7 +644,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -661,8 +673,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -671,7 +687,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -679,7 +695,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -687,7 +703,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -713,8 +729,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -723,7 +743,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -731,7 +751,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -742,7 +762,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -768,8 +788,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -778,7 +802,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -786,7 +810,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/client.py index dbe86d771cb7..8cc607021ef0 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/client.py @@ -117,7 +117,7 @@ class AlloyDBCSQLAdminClient(metaclass=AlloyDBCSQLAdminClientMeta): """Service for interactions with CloudSQL.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -533,7 +537,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -630,7 +634,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -728,7 +732,7 @@ def __init__( self._universe_domain = AlloyDBCSQLAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -986,7 +990,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1012,8 +1016,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1022,7 +1030,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1031,7 +1039,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1045,7 +1053,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1071,8 +1079,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1081,7 +1093,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1090,7 +1102,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1116,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1146,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1160,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1168,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1160,7 +1176,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1189,8 +1205,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1199,7 +1219,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1207,7 +1227,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1215,7 +1235,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1241,8 +1261,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1251,7 +1275,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1260,7 +1284,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1274,7 +1298,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1300,8 +1324,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1310,7 +1338,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1319,7 +1347,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/README.rst b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/README.rst index ba9a1b018967..951cec18ca3d 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/README.rst +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlloyDBCSQLAdminTransport` is the ABC for all transports. -- public child `AlloyDBCSQLAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlloyDBCSQLAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlloyDBCSQLAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlloyDBCSQLAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlloyDBCSQLAdminTransport`` is the ABC for all transports. + +- public child ``AlloyDBCSQLAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlloyDBCSQLAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlloyDBCSQLAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlloyDBCSQLAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/base.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/base.py index 62f62b593678..443813e0f3ee 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/base.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc.py index 90f57676e2df..878d1c3d01fc 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc_asyncio.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc_asyncio.py index 566a453f1729..3f7fb8ecddcd 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/rest.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/rest.py index ecedad1d48a4..131dcb8deb31 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/rest.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1alpha/services/alloy_dbcsql_admin/transports/rest.py @@ -353,6 +353,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlloyDBCSQLAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/async_client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/async_client.py index 792b5ddbcd67..f949850773d3 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/async_client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> AlloyDBAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5376,7 +5376,7 @@ async def sample_create_database(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5402,8 +5402,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5412,7 +5416,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5420,7 +5424,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5431,7 +5435,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5457,8 +5461,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5467,7 +5475,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5475,7 +5483,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5486,7 +5494,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5516,8 +5524,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5526,7 +5538,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5534,7 +5546,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5542,7 +5554,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5571,8 +5583,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5581,7 +5597,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5589,7 +5605,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5597,7 +5613,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5623,8 +5639,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5633,7 +5653,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5641,7 +5661,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5652,7 +5672,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5678,8 +5698,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5688,7 +5712,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5696,7 +5720,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/client.py index 477d6f002f3e..c2b942e6c0a1 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/client.py @@ -127,7 +127,7 @@ class AlloyDBAdminClient(metaclass=AlloyDBAdminClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -683,7 +687,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -780,7 +784,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -876,7 +880,7 @@ def __init__( self._universe_domain = AlloyDBAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5917,7 +5921,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5943,8 +5947,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5953,7 +5961,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5962,7 +5970,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5976,7 +5984,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6002,8 +6010,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6012,7 +6024,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6021,7 +6033,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6035,7 +6047,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6065,8 +6077,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6075,7 +6091,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6083,7 +6099,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6091,7 +6107,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6120,8 +6136,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6130,7 +6150,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6138,7 +6158,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6146,7 +6166,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6172,8 +6192,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6182,7 +6206,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6191,7 +6215,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6205,7 +6229,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6231,8 +6255,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6241,7 +6269,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6250,7 +6278,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/README.rst b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/README.rst index 6bacf2452a64..31b9a5a9ef4f 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/README.rst +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlloyDBAdminTransport` is the ABC for all transports. -- public child `AlloyDBAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlloyDBAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlloyDBAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlloyDBAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlloyDBAdminTransport`` is the ABC for all transports. + +- public child ``AlloyDBAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlloyDBAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlloyDBAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlloyDBAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/base.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/base.py index cf4e4bc918fd..5007fa6a65b3 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/base.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc.py index 58ac88b797c1..d5f6bcbfa5eb 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc_asyncio.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc_asyncio.py index a98a6290f2ca..5ddd4e50b2b1 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/rest.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/rest.py index bead9dbdf12a..14faaee1af1e 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/rest.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_db_admin/transports/rest.py @@ -2322,6 +2322,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlloyDBAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/async_client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/async_client.py index 8c5896fe9171..d2bf30a1b0e2 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/async_client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> AlloyDBCSQLAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -466,7 +466,7 @@ async def sample_restore_from_cloud_sql(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -492,8 +492,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -502,7 +506,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -510,7 +514,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -521,7 +525,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -547,8 +551,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -557,7 +565,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -565,7 +573,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -576,7 +584,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -606,8 +614,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -616,7 +628,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -624,7 +636,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -632,7 +644,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -661,8 +673,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -671,7 +687,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -679,7 +695,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -687,7 +703,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -713,8 +729,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -723,7 +743,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -731,7 +751,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -742,7 +762,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -768,8 +788,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -778,7 +802,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -786,7 +810,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/client.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/client.py index bbe4a9e2094b..a0229d1933d6 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/client.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/client.py @@ -117,7 +117,7 @@ class AlloyDBCSQLAdminClient(metaclass=AlloyDBCSQLAdminClientMeta): """Service for interactions with CloudSQL.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -533,7 +537,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -630,7 +634,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -728,7 +732,7 @@ def __init__( self._universe_domain = AlloyDBCSQLAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -986,7 +990,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1012,8 +1016,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1022,7 +1030,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1031,7 +1039,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1045,7 +1053,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1071,8 +1079,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1081,7 +1093,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1090,7 +1102,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1116,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1146,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1160,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1168,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1160,7 +1176,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1189,8 +1205,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1199,7 +1219,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1207,7 +1227,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1215,7 +1235,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1241,8 +1261,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1251,7 +1275,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1260,7 +1284,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1274,7 +1298,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1300,8 +1324,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1310,7 +1338,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1319,7 +1347,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/README.rst b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/README.rst index ba9a1b018967..951cec18ca3d 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/README.rst +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlloyDBCSQLAdminTransport` is the ABC for all transports. -- public child `AlloyDBCSQLAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlloyDBCSQLAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlloyDBCSQLAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlloyDBCSQLAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlloyDBCSQLAdminTransport`` is the ABC for all transports. + +- public child ``AlloyDBCSQLAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlloyDBCSQLAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlloyDBCSQLAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlloyDBCSQLAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/base.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/base.py index d734eb1eaf37..d8c5ca7b9ea0 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/base.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc.py index ed5d0c25af5b..d8d59189b6cb 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc_asyncio.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc_asyncio.py index c1080166df9c..45326cf2910d 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/rest.py b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/rest.py index 75def1049b10..abb6c02765fe 100644 --- a/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/rest.py +++ b/packages/google-cloud-alloydb/google/cloud/alloydb_v1beta/services/alloy_dbcsql_admin/transports/rest.py @@ -353,6 +353,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AlloyDBCSQLAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-alloydb/noxfile.py b/packages/google-cloud-alloydb/noxfile.py index 3115969ad8cc..9ae5c8729f11 100644 --- a/packages/google-cloud-alloydb/noxfile.py +++ b/packages/google-cloud-alloydb/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-alloydb/setup.py b/packages/google-cloud-alloydb/setup.py index 51f37c7faff5..7d665d1514ba 100644 --- a/packages/google-cloud-alloydb/setup.py +++ b/packages/google-cloud-alloydb/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-alloydb/testing/constraints-3.7.txt b/packages/google-cloud-alloydb/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-alloydb/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-alloydb/testing/constraints-3.8.txt b/packages/google-cloud-alloydb/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-alloydb/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-alloydb/testing/constraints-3.9.txt b/packages/google-cloud-alloydb/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-alloydb/testing/constraints-3.9.txt +++ b/packages/google-cloud-alloydb/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_db_admin.py b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_db_admin.py index d8e49963ce63..6c4493dbb5f8 100644 --- a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_db_admin.py +++ b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_db_admin.py @@ -137,6 +137,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlloyDBAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AlloyDBAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AlloyDBAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1275,11 +1280,13 @@ def test_alloy_db_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -24544,8 +24551,9 @@ def test_list_clusters_rest_bad_request(request_type=service.ListClustersRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24610,17 +24618,19 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_clusters_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24671,8 +24681,9 @@ def test_get_cluster_rest_bad_request(request_type=service.GetClusterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24755,17 +24766,19 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24814,8 +24827,9 @@ def test_create_cluster_rest_bad_request(request_type=service.CreateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25037,19 +25051,20 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25100,8 +25115,9 @@ def test_update_cluster_rest_bad_request(request_type=service.UpdateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25325,19 +25341,20 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25386,8 +25403,9 @@ def test_export_cluster_rest_bad_request(request_type=service.ExportClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25444,19 +25462,20 @@ def test_export_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_export_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_export_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_export_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_export_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_export_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_export_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25505,8 +25524,9 @@ def test_import_cluster_rest_bad_request(request_type=service.ImportClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25563,19 +25583,20 @@ def test_import_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_import_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_import_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_import_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_import_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_import_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_import_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25624,8 +25645,9 @@ def test_upgrade_cluster_rest_bad_request(request_type=service.UpgradeClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25682,19 +25704,20 @@ def test_upgrade_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_upgrade_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_upgrade_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25743,8 +25766,9 @@ def test_delete_cluster_rest_bad_request(request_type=service.DeleteClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25801,19 +25825,20 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25862,8 +25887,9 @@ def test_promote_cluster_rest_bad_request(request_type=service.PromoteClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25920,19 +25946,20 @@ def test_promote_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_promote_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_promote_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_promote_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_promote_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_promote_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_promote_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25983,8 +26010,9 @@ def test_switchover_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26041,19 +26069,21 @@ def test_switchover_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_switchover_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_switchover_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_switchover_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26104,8 +26134,9 @@ def test_restore_cluster_rest_bad_request(request_type=service.RestoreClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26162,19 +26193,20 @@ def test_restore_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restore_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restore_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_restore_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restore_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restore_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_restore_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26225,8 +26257,9 @@ def test_create_secondary_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26448,20 +26481,21 @@ def test_create_secondary_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_secondary_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_create_secondary_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_secondary_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_create_secondary_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26512,8 +26546,9 @@ def test_list_instances_rest_bad_request(request_type=service.ListInstancesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26578,17 +26613,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26641,8 +26678,9 @@ def test_get_instance_rest_bad_request(request_type=service.GetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26735,17 +26773,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26794,8 +26834,9 @@ def test_create_instance_rest_bad_request(request_type=service.CreateInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27001,19 +27042,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27064,8 +27106,9 @@ def test_create_secondary_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27271,20 +27314,21 @@ def test_create_secondary_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_secondary_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_create_secondary_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_secondary_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_create_secondary_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27337,8 +27381,9 @@ def test_batch_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27565,20 +27610,21 @@ def test_batch_create_instances_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_batch_create_instances" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_batch_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_batch_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_batch_create_instances" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_batch_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_batch_create_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27633,8 +27679,9 @@ def test_update_instance_rest_bad_request(request_type=service.UpdateInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27844,19 +27891,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27907,8 +27955,9 @@ def test_delete_instance_rest_bad_request(request_type=service.DeleteInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27967,19 +28016,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28032,8 +28082,9 @@ def test_failover_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28092,19 +28143,21 @@ def test_failover_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_failover_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_failover_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_failover_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_failover_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_failover_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_failover_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28157,8 +28210,9 @@ def test_inject_fault_rest_bad_request(request_type=service.InjectFaultRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28217,19 +28271,20 @@ def test_inject_fault_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_inject_fault" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_inject_fault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_inject_fault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_inject_fault" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_inject_fault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_inject_fault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28280,8 +28335,9 @@ def test_restart_instance_rest_bad_request(request_type=service.RestartInstanceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28340,19 +28396,21 @@ def test_restart_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restart_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restart_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_restart_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restart_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_restart_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_restart_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28403,8 +28461,9 @@ def test_execute_sql_rest_bad_request(request_type=service.ExecuteSqlRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28466,17 +28525,19 @@ def test_execute_sql_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_execute_sql" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_execute_sql_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_execute_sql" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_execute_sql" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_execute_sql_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_execute_sql" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28525,8 +28586,9 @@ def test_list_backups_rest_bad_request(request_type=service.ListBackupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28591,17 +28653,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28652,8 +28716,9 @@ def test_get_backup_rest_bad_request(request_type=service.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28740,17 +28805,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28799,8 +28866,9 @@ def test_create_backup_rest_bad_request(request_type=service.CreateBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28953,19 +29021,20 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29016,8 +29085,9 @@ def test_update_backup_rest_bad_request(request_type=service.UpdateBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29172,19 +29242,20 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29233,8 +29304,9 @@ def test_delete_backup_rest_bad_request(request_type=service.DeleteBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29291,19 +29363,20 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29354,8 +29427,9 @@ def test_list_supported_database_flags_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29418,18 +29492,20 @@ def test_list_supported_database_flags_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_supported_database_flags" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_list_supported_database_flags_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_supported_database_flags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_supported_database_flags" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_list_supported_database_flags_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_supported_database_flags" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29487,8 +29563,9 @@ def test_generate_client_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29553,18 +29630,20 @@ def test_generate_client_certificate_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_generate_client_certificate" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_generate_client_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_generate_client_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_generate_client_certificate" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_generate_client_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_generate_client_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29624,8 +29703,9 @@ def test_get_connection_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29696,17 +29776,20 @@ def test_get_connection_info_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_connection_info" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_connection_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_connection_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_connection_info" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_get_connection_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_connection_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29757,8 +29840,9 @@ def test_list_users_rest_bad_request(request_type=service.ListUsersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29823,17 +29907,19 @@ def test_list_users_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_users" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_users_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_users" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_users" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_users_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_users" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29884,8 +29970,9 @@ def test_get_user_rest_bad_request(request_type=service.GetUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29958,17 +30045,19 @@ def test_get_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30017,8 +30106,9 @@ def test_create_user_rest_bad_request(request_type=service.CreateUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30163,17 +30253,19 @@ def test_create_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30226,8 +30318,9 @@ def test_update_user_rest_bad_request(request_type=service.UpdateUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30376,17 +30469,19 @@ def test_update_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30437,8 +30532,9 @@ def test_delete_user_rest_bad_request(request_type=service.DeleteUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30497,13 +30593,13 @@ def test_delete_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_user" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteUserRequest.pb(service.DeleteUserRequest()) transcode.return_value = { @@ -30544,8 +30640,9 @@ def test_list_databases_rest_bad_request(request_type=service.ListDatabasesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30608,17 +30705,19 @@ def test_list_databases_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_databases" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_databases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_databases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_databases" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_databases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_databases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30671,8 +30770,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -30731,8 +30831,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -30793,8 +30894,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -30855,8 +30957,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -30917,8 +31020,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -30979,8 +31083,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31908,11 +32013,14 @@ def test_alloy_db_admin_base_transport(): def test_alloy_db_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.alloydb_v1.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.alloydb_v1.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBAdminTransport( @@ -31929,9 +32037,12 @@ def test_alloy_db_admin_base_transport_with_credentials_file(): def test_alloy_db_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.alloydb_v1.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.alloydb_v1.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBAdminTransport() @@ -32003,11 +32114,12 @@ def test_alloy_db_admin_transport_auth_gdch_credentials(transport_class): def test_alloy_db_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -32985,6 +33097,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33124,6 +33268,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33269,6 +33445,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33414,6 +33624,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33559,6 +33803,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33700,6 +33978,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_dbcsql_admin.py b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_dbcsql_admin.py index 68d69375e44f..029aa2390644 100644 --- a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_dbcsql_admin.py +++ b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1/test_alloy_dbcsql_admin.py @@ -139,6 +139,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlloyDBCSQLAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +162,10 @@ def test__get_default_mtls_endpoint(): AlloyDBCSQLAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AlloyDBCSQLAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_alloy_dbcsql_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2101,8 +2108,9 @@ def test_restore_from_cloud_sql_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2159,20 +2167,21 @@ def test_restore_from_cloud_sql_rest_interceptors(null_interceptor): ) client = AlloyDBCSQLAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, "post_restore_from_cloud_sql" - ) as post, mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, - "post_restore_from_cloud_sql_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, "pre_restore_from_cloud_sql" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, "post_restore_from_cloud_sql" + ) as post, + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, + "post_restore_from_cloud_sql_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, "pre_restore_from_cloud_sql" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2225,8 +2234,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2285,8 +2295,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2347,8 +2358,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2409,8 +2421,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2471,8 +2484,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2533,8 +2547,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2692,11 +2707,14 @@ def test_alloy_dbcsql_admin_base_transport(): def test_alloy_dbcsql_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.alloydb_v1.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.alloydb_v1.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBCSQLAdminTransport( @@ -2713,9 +2731,12 @@ def test_alloy_dbcsql_admin_base_transport_with_credentials_file(): def test_alloy_dbcsql_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.alloydb_v1.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.alloydb_v1.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBCSQLAdminTransport() @@ -2787,11 +2808,12 @@ def test_alloy_dbcsql_admin_transport_auth_gdch_credentials(transport_class): def test_alloy_dbcsql_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3502,6 +3524,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3641,6 +3695,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3786,6 +3872,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3931,6 +4051,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4076,6 +4230,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4217,6 +4405,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_db_admin.py b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_db_admin.py index 81cf2acf3c9e..3a9d18bf4c16 100644 --- a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_db_admin.py +++ b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_db_admin.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlloyDBAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +162,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AlloyDBAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AlloyDBAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1281,11 +1286,13 @@ def test_alloy_db_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -25228,8 +25235,9 @@ def test_list_clusters_rest_bad_request(request_type=service.ListClustersRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25294,17 +25302,19 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_clusters_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25355,8 +25365,9 @@ def test_get_cluster_rest_bad_request(request_type=service.GetClusterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25443,17 +25454,19 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25502,8 +25515,9 @@ def test_create_cluster_rest_bad_request(request_type=service.CreateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25728,19 +25742,20 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25791,8 +25806,9 @@ def test_update_cluster_rest_bad_request(request_type=service.UpdateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26019,19 +26035,20 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26080,8 +26097,9 @@ def test_export_cluster_rest_bad_request(request_type=service.ExportClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26138,19 +26156,20 @@ def test_export_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_export_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_export_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_export_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_export_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_export_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_export_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26199,8 +26218,9 @@ def test_import_cluster_rest_bad_request(request_type=service.ImportClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26257,19 +26277,20 @@ def test_import_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_import_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_import_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_import_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_import_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_import_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_import_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26318,8 +26339,9 @@ def test_upgrade_cluster_rest_bad_request(request_type=service.UpgradeClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26376,19 +26398,20 @@ def test_upgrade_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_upgrade_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_upgrade_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26437,8 +26460,9 @@ def test_delete_cluster_rest_bad_request(request_type=service.DeleteClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26495,19 +26519,20 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26556,8 +26581,9 @@ def test_promote_cluster_rest_bad_request(request_type=service.PromoteClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26614,19 +26640,20 @@ def test_promote_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_promote_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_promote_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_promote_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_promote_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_promote_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_promote_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26677,8 +26704,9 @@ def test_switchover_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26735,19 +26763,21 @@ def test_switchover_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_switchover_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_switchover_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_switchover_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26798,8 +26828,9 @@ def test_restore_cluster_rest_bad_request(request_type=service.RestoreClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26856,19 +26887,20 @@ def test_restore_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restore_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restore_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_restore_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restore_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restore_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_restore_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26919,8 +26951,9 @@ def test_create_secondary_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27145,20 +27178,21 @@ def test_create_secondary_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_secondary_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_create_secondary_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_secondary_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_create_secondary_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27209,8 +27243,9 @@ def test_list_instances_rest_bad_request(request_type=service.ListInstancesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27275,17 +27310,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27338,8 +27375,9 @@ def test_get_instance_rest_bad_request(request_type=service.GetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27434,17 +27472,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27493,8 +27533,9 @@ def test_create_instance_rest_bad_request(request_type=service.CreateInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27706,19 +27747,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27769,8 +27811,9 @@ def test_create_secondary_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27982,20 +28025,21 @@ def test_create_secondary_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_secondary_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_create_secondary_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_secondary_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_create_secondary_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28048,8 +28092,9 @@ def test_batch_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28282,20 +28327,21 @@ def test_batch_create_instances_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_batch_create_instances" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_batch_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_batch_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_batch_create_instances" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_batch_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_batch_create_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28350,8 +28396,9 @@ def test_update_instance_rest_bad_request(request_type=service.UpdateInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28567,19 +28614,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28630,8 +28678,9 @@ def test_delete_instance_rest_bad_request(request_type=service.DeleteInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28690,19 +28739,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28755,8 +28805,9 @@ def test_failover_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28815,19 +28866,21 @@ def test_failover_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_failover_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_failover_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_failover_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_failover_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_failover_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_failover_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28880,8 +28933,9 @@ def test_inject_fault_rest_bad_request(request_type=service.InjectFaultRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28940,19 +28994,20 @@ def test_inject_fault_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_inject_fault" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_inject_fault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_inject_fault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_inject_fault" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_inject_fault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_inject_fault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29003,8 +29058,9 @@ def test_restart_instance_rest_bad_request(request_type=service.RestartInstanceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29063,19 +29119,21 @@ def test_restart_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restart_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restart_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_restart_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restart_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_restart_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_restart_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29126,8 +29184,9 @@ def test_execute_sql_rest_bad_request(request_type=service.ExecuteSqlRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29189,17 +29248,19 @@ def test_execute_sql_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_execute_sql" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_execute_sql_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_execute_sql" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_execute_sql" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_execute_sql_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_execute_sql" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29248,8 +29309,9 @@ def test_list_backups_rest_bad_request(request_type=service.ListBackupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29314,17 +29376,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29375,8 +29439,9 @@ def test_get_backup_rest_bad_request(request_type=service.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29465,17 +29530,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29524,8 +29591,9 @@ def test_create_backup_rest_bad_request(request_type=service.CreateBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29679,19 +29747,20 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29742,8 +29811,9 @@ def test_update_backup_rest_bad_request(request_type=service.UpdateBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29899,19 +29969,20 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29960,8 +30031,9 @@ def test_delete_backup_rest_bad_request(request_type=service.DeleteBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30018,19 +30090,20 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30081,8 +30154,9 @@ def test_list_supported_database_flags_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30145,18 +30219,20 @@ def test_list_supported_database_flags_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_supported_database_flags" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_list_supported_database_flags_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_supported_database_flags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_supported_database_flags" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_list_supported_database_flags_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_supported_database_flags" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30214,8 +30290,9 @@ def test_generate_client_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30282,18 +30359,20 @@ def test_generate_client_certificate_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_generate_client_certificate" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_generate_client_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_generate_client_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_generate_client_certificate" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_generate_client_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_generate_client_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30353,8 +30432,9 @@ def test_get_connection_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30429,17 +30509,20 @@ def test_get_connection_info_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_connection_info" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_connection_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_connection_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_connection_info" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_get_connection_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_connection_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30490,8 +30573,9 @@ def test_list_users_rest_bad_request(request_type=service.ListUsersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30556,17 +30640,19 @@ def test_list_users_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_users" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_users_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_users" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_users" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_users_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_users" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30617,8 +30703,9 @@ def test_get_user_rest_bad_request(request_type=service.GetUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30691,17 +30778,19 @@ def test_get_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30750,8 +30839,9 @@ def test_create_user_rest_bad_request(request_type=service.CreateUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30896,17 +30986,19 @@ def test_create_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30959,8 +31051,9 @@ def test_update_user_rest_bad_request(request_type=service.UpdateUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31109,17 +31202,19 @@ def test_update_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31170,8 +31265,9 @@ def test_delete_user_rest_bad_request(request_type=service.DeleteUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31230,13 +31326,13 @@ def test_delete_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_user" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteUserRequest.pb(service.DeleteUserRequest()) transcode.return_value = { @@ -31277,8 +31373,9 @@ def test_list_databases_rest_bad_request(request_type=service.ListDatabasesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31341,17 +31438,19 @@ def test_list_databases_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_databases" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_databases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_databases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_databases" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_databases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_databases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31402,8 +31501,9 @@ def test_create_database_rest_bad_request(request_type=service.CreateDatabaseReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31554,17 +31654,19 @@ def test_create_database_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_database" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_database" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_database_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31615,8 +31717,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31675,8 +31778,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31737,8 +31841,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31799,8 +31904,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31861,8 +31967,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31923,8 +32030,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32873,11 +32981,14 @@ def test_alloy_db_admin_base_transport(): def test_alloy_db_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.alloydb_v1alpha.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.alloydb_v1alpha.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBAdminTransport( @@ -32894,9 +33005,12 @@ def test_alloy_db_admin_base_transport_with_credentials_file(): def test_alloy_db_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.alloydb_v1alpha.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.alloydb_v1alpha.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBAdminTransport() @@ -32968,11 +33082,12 @@ def test_alloy_db_admin_transport_auth_gdch_credentials(transport_class): def test_alloy_db_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -33953,6 +34068,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34092,6 +34239,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34237,6 +34416,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34382,6 +34595,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34527,6 +34774,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34668,6 +34949,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_dbcsql_admin.py b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_dbcsql_admin.py index f8a60370c0b2..0d200194cc29 100644 --- a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_dbcsql_admin.py +++ b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1alpha/test_alloy_dbcsql_admin.py @@ -140,6 +140,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlloyDBCSQLAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -162,6 +163,10 @@ def test__get_default_mtls_endpoint(): AlloyDBCSQLAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AlloyDBCSQLAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1331,11 +1336,13 @@ def test_alloy_dbcsql_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2102,8 +2109,9 @@ def test_restore_from_cloud_sql_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2160,20 +2168,21 @@ def test_restore_from_cloud_sql_rest_interceptors(null_interceptor): ) client = AlloyDBCSQLAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, "post_restore_from_cloud_sql" - ) as post, mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, - "post_restore_from_cloud_sql_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, "pre_restore_from_cloud_sql" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, "post_restore_from_cloud_sql" + ) as post, + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, + "post_restore_from_cloud_sql_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, "pre_restore_from_cloud_sql" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2226,8 +2235,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2286,8 +2296,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2348,8 +2359,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2410,8 +2422,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2472,8 +2485,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2534,8 +2548,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2693,11 +2708,14 @@ def test_alloy_dbcsql_admin_base_transport(): def test_alloy_dbcsql_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.alloydb_v1alpha.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.alloydb_v1alpha.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBCSQLAdminTransport( @@ -2714,9 +2732,12 @@ def test_alloy_dbcsql_admin_base_transport_with_credentials_file(): def test_alloy_dbcsql_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.alloydb_v1alpha.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.alloydb_v1alpha.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBCSQLAdminTransport() @@ -2788,11 +2809,12 @@ def test_alloy_dbcsql_admin_transport_auth_gdch_credentials(transport_class): def test_alloy_dbcsql_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3503,6 +3525,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3642,6 +3696,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3787,6 +3873,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3932,6 +4052,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4077,6 +4231,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4218,6 +4406,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_db_admin.py b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_db_admin.py index d9f54930d923..83e7c5c75251 100644 --- a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_db_admin.py +++ b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_db_admin.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlloyDBAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +162,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AlloyDBAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AlloyDBAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1281,11 +1286,13 @@ def test_alloy_db_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -25213,8 +25220,9 @@ def test_list_clusters_rest_bad_request(request_type=service.ListClustersRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25279,17 +25287,19 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_clusters_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25340,8 +25350,9 @@ def test_get_cluster_rest_bad_request(request_type=service.GetClusterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25426,17 +25437,19 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25485,8 +25498,9 @@ def test_create_cluster_rest_bad_request(request_type=service.CreateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25710,19 +25724,20 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25773,8 +25788,9 @@ def test_update_cluster_rest_bad_request(request_type=service.UpdateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26000,19 +26016,20 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26061,8 +26078,9 @@ def test_export_cluster_rest_bad_request(request_type=service.ExportClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26119,19 +26137,20 @@ def test_export_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_export_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_export_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_export_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_export_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_export_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_export_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26180,8 +26199,9 @@ def test_import_cluster_rest_bad_request(request_type=service.ImportClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26238,19 +26258,20 @@ def test_import_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_import_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_import_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_import_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_import_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_import_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_import_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26299,8 +26320,9 @@ def test_upgrade_cluster_rest_bad_request(request_type=service.UpgradeClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26357,19 +26379,20 @@ def test_upgrade_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_upgrade_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_upgrade_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_upgrade_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26418,8 +26441,9 @@ def test_delete_cluster_rest_bad_request(request_type=service.DeleteClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26476,19 +26500,20 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26537,8 +26562,9 @@ def test_promote_cluster_rest_bad_request(request_type=service.PromoteClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26595,19 +26621,20 @@ def test_promote_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_promote_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_promote_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_promote_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_promote_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_promote_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_promote_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26658,8 +26685,9 @@ def test_switchover_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26716,19 +26744,21 @@ def test_switchover_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_switchover_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_switchover_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_switchover_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_switchover_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26779,8 +26809,9 @@ def test_restore_cluster_rest_bad_request(request_type=service.RestoreClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26837,19 +26868,20 @@ def test_restore_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restore_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restore_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_restore_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restore_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restore_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_restore_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26900,8 +26932,9 @@ def test_create_secondary_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27125,20 +27158,21 @@ def test_create_secondary_cluster_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_secondary_cluster" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_create_secondary_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_secondary_cluster" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_create_secondary_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27189,8 +27223,9 @@ def test_list_instances_rest_bad_request(request_type=service.ListInstancesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27255,17 +27290,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27318,8 +27355,9 @@ def test_get_instance_rest_bad_request(request_type=service.GetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27412,17 +27450,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27471,8 +27511,9 @@ def test_create_instance_rest_bad_request(request_type=service.CreateInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27683,19 +27724,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27746,8 +27788,9 @@ def test_create_secondary_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27958,20 +28001,21 @@ def test_create_secondary_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_secondary_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_create_secondary_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_secondary_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_create_secondary_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_secondary_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28024,8 +28068,9 @@ def test_batch_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28257,20 +28302,21 @@ def test_batch_create_instances_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_batch_create_instances" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_batch_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_batch_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_batch_create_instances" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_batch_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_batch_create_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28325,8 +28371,9 @@ def test_update_instance_rest_bad_request(request_type=service.UpdateInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28541,19 +28588,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28604,8 +28652,9 @@ def test_delete_instance_rest_bad_request(request_type=service.DeleteInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28664,19 +28713,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28729,8 +28779,9 @@ def test_failover_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28789,19 +28840,21 @@ def test_failover_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_failover_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_failover_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_failover_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_failover_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_failover_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_failover_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28854,8 +28907,9 @@ def test_inject_fault_rest_bad_request(request_type=service.InjectFaultRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28914,19 +28968,20 @@ def test_inject_fault_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_inject_fault" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_inject_fault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_inject_fault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_inject_fault" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_inject_fault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_inject_fault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28977,8 +29032,9 @@ def test_restart_instance_rest_bad_request(request_type=service.RestartInstanceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29037,19 +29093,21 @@ def test_restart_instance_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restart_instance" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_restart_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_restart_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_restart_instance" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_restart_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_restart_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29100,8 +29158,9 @@ def test_execute_sql_rest_bad_request(request_type=service.ExecuteSqlRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29163,17 +29222,19 @@ def test_execute_sql_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_execute_sql" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_execute_sql_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_execute_sql" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_execute_sql" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_execute_sql_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_execute_sql" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29222,8 +29283,9 @@ def test_list_backups_rest_bad_request(request_type=service.ListBackupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29288,17 +29350,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29349,8 +29413,9 @@ def test_get_backup_rest_bad_request(request_type=service.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29437,17 +29502,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29496,8 +29563,9 @@ def test_create_backup_rest_bad_request(request_type=service.CreateBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29650,19 +29718,20 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29713,8 +29782,9 @@ def test_update_backup_rest_bad_request(request_type=service.UpdateBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29869,19 +29939,20 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29930,8 +30001,9 @@ def test_delete_backup_rest_bad_request(request_type=service.DeleteBackupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29988,19 +30060,20 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30051,8 +30124,9 @@ def test_list_supported_database_flags_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30115,18 +30189,20 @@ def test_list_supported_database_flags_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_supported_database_flags" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_list_supported_database_flags_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_supported_database_flags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_supported_database_flags" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_list_supported_database_flags_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_supported_database_flags" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30184,8 +30260,9 @@ def test_generate_client_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30252,18 +30329,20 @@ def test_generate_client_certificate_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_generate_client_certificate" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, - "post_generate_client_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_generate_client_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_generate_client_certificate" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_generate_client_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_generate_client_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30323,8 +30402,9 @@ def test_get_connection_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30399,17 +30479,20 @@ def test_get_connection_info_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_connection_info" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_connection_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_connection_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_connection_info" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, + "post_get_connection_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_connection_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30460,8 +30543,9 @@ def test_list_users_rest_bad_request(request_type=service.ListUsersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30526,17 +30610,19 @@ def test_list_users_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_users" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_users_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_users" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_users" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_users_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_users" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30587,8 +30673,9 @@ def test_get_user_rest_bad_request(request_type=service.GetUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30661,17 +30748,19 @@ def test_get_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_get_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_get_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_get_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_get_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30720,8 +30809,9 @@ def test_create_user_rest_bad_request(request_type=service.CreateUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30866,17 +30956,19 @@ def test_create_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30929,8 +31021,9 @@ def test_update_user_rest_bad_request(request_type=service.UpdateUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31079,17 +31172,19 @@ def test_update_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_user" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_update_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_update_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_user" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_update_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_update_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31140,8 +31235,9 @@ def test_delete_user_rest_bad_request(request_type=service.DeleteUserRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31200,13 +31296,13 @@ def test_delete_user_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_delete_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_delete_user" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteUserRequest.pb(service.DeleteUserRequest()) transcode.return_value = { @@ -31247,8 +31343,9 @@ def test_list_databases_rest_bad_request(request_type=service.ListDatabasesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31311,17 +31408,19 @@ def test_list_databases_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_databases" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_list_databases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_list_databases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_databases" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_list_databases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_list_databases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31372,8 +31471,9 @@ def test_create_database_rest_bad_request(request_type=service.CreateDatabaseReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31524,17 +31624,19 @@ def test_create_database_rest_interceptors(null_interceptor): ) client = AlloyDBAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_database" - ) as post, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "post_create_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBAdminRestInterceptor, "pre_create_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_database" + ) as post, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "post_create_database_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBAdminRestInterceptor, "pre_create_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31585,8 +31687,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31645,8 +31748,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31707,8 +31811,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31769,8 +31874,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31831,8 +31937,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31893,8 +32000,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32843,11 +32951,14 @@ def test_alloy_db_admin_base_transport(): def test_alloy_db_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.alloydb_v1beta.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.alloydb_v1beta.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBAdminTransport( @@ -32864,9 +32975,12 @@ def test_alloy_db_admin_base_transport_with_credentials_file(): def test_alloy_db_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.alloydb_v1beta.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.alloydb_v1beta.services.alloy_db_admin.transports.AlloyDBAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBAdminTransport() @@ -32938,11 +33052,12 @@ def test_alloy_db_admin_transport_auth_gdch_credentials(transport_class): def test_alloy_db_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -33923,6 +34038,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34062,6 +34209,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34207,6 +34386,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34352,6 +34565,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34497,6 +34744,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34638,6 +34919,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AlloyDBAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AlloyDBAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AlloyDBAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_dbcsql_admin.py b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_dbcsql_admin.py index b4e1d75b5b1d..adbf2cc62c34 100644 --- a/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_dbcsql_admin.py +++ b/packages/google-cloud-alloydb/tests/unit/gapic/alloydb_v1beta/test_alloy_dbcsql_admin.py @@ -140,6 +140,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlloyDBCSQLAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -162,6 +163,10 @@ def test__get_default_mtls_endpoint(): AlloyDBCSQLAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AlloyDBCSQLAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1331,11 +1336,13 @@ def test_alloy_dbcsql_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2102,8 +2109,9 @@ def test_restore_from_cloud_sql_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2160,20 +2168,21 @@ def test_restore_from_cloud_sql_rest_interceptors(null_interceptor): ) client = AlloyDBCSQLAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, "post_restore_from_cloud_sql" - ) as post, mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, - "post_restore_from_cloud_sql_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AlloyDBCSQLAdminRestInterceptor, "pre_restore_from_cloud_sql" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, "post_restore_from_cloud_sql" + ) as post, + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, + "post_restore_from_cloud_sql_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AlloyDBCSQLAdminRestInterceptor, "pre_restore_from_cloud_sql" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2226,8 +2235,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2286,8 +2296,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2348,8 +2359,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2410,8 +2422,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2472,8 +2485,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2534,8 +2548,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2693,11 +2708,14 @@ def test_alloy_dbcsql_admin_base_transport(): def test_alloy_dbcsql_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.alloydb_v1beta.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.alloydb_v1beta.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBCSQLAdminTransport( @@ -2714,9 +2732,12 @@ def test_alloy_dbcsql_admin_base_transport_with_credentials_file(): def test_alloy_dbcsql_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.alloydb_v1beta.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.alloydb_v1beta.services.alloy_dbcsql_admin.transports.AlloyDBCSQLAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlloyDBCSQLAdminTransport() @@ -2788,11 +2809,12 @@ def test_alloy_dbcsql_admin_transport_auth_gdch_credentials(transport_class): def test_alloy_dbcsql_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3503,6 +3525,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3642,6 +3696,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3787,6 +3873,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3932,6 +4052,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4077,6 +4231,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4218,6 +4406,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AlloyDBCSQLAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AlloyDBCSQLAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AlloyDBCSQLAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/async_client.py b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/async_client.py index 2a9ac9d933aa..da534126f432 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/async_client.py +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> ApiGatewayServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/client.py b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/client.py index b3f61b0a34ef..d499747da835 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/client.py +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/client.py @@ -117,7 +117,7 @@ class ApiGatewayServiceClient(metaclass=ApiGatewayServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -535,7 +539,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -632,7 +636,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -732,7 +736,7 @@ def __init__( self._universe_domain = ApiGatewayServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/README.rst b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/README.rst index 266ae4b10c46..d1193f5fe62e 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/README.rst +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiGatewayServiceTransport` is the ABC for all transports. -- public child `ApiGatewayServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiGatewayServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiGatewayServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiGatewayServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiGatewayServiceTransport`` is the ABC for all transports. + +- public child ``ApiGatewayServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiGatewayServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiGatewayServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiGatewayServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/base.py b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/base.py index 353f5e054aac..f0381ca3ab00 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/base.py +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc.py b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc.py index a5bb254672a7..14af7bcdfbe1 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc.py +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc_asyncio.py b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc_asyncio.py index cc1e02bac4e9..1ff5c146b1d2 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/rest.py b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/rest.py index 209869e97e9a..e299364367e8 100644 --- a/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/rest.py +++ b/packages/google-cloud-api-gateway/google/cloud/apigateway_v1/services/api_gateway_service/transports/rest.py @@ -971,6 +971,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiGatewayServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-api-gateway/noxfile.py b/packages/google-cloud-api-gateway/noxfile.py index 9a3012e44f78..bd9f9e075c60 100644 --- a/packages/google-cloud-api-gateway/noxfile.py +++ b/packages/google-cloud-api-gateway/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-api-gateway/setup.py b/packages/google-cloud-api-gateway/setup.py index e213bc891e23..c418d05d4bae 100644 --- a/packages/google-cloud-api-gateway/setup.py +++ b/packages/google-cloud-api-gateway/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-api-gateway" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-api-gateway/testing/constraints-3.7.txt b/packages/google-cloud-api-gateway/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-api-gateway/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-api-gateway/testing/constraints-3.8.txt b/packages/google-cloud-api-gateway/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-api-gateway/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-api-gateway/testing/constraints-3.9.txt b/packages/google-cloud-api-gateway/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-api-gateway/testing/constraints-3.9.txt +++ b/packages/google-cloud-api-gateway/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-api-gateway/tests/unit/gapic/apigateway_v1/test_api_gateway_service.py b/packages/google-cloud-api-gateway/tests/unit/gapic/apigateway_v1/test_api_gateway_service.py index 09bf0ea0a843..6ca44c7c73a3 100644 --- a/packages/google-cloud-api-gateway/tests/unit/gapic/apigateway_v1/test_api_gateway_service.py +++ b/packages/google-cloud-api-gateway/tests/unit/gapic/apigateway_v1/test_api_gateway_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiGatewayServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): ApiGatewayServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ApiGatewayServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1326,11 +1331,13 @@ def test_api_gateway_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10858,8 +10865,9 @@ def test_list_gateways_rest_bad_request(request_type=apigateway.ListGatewaysRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10924,17 +10932,20 @@ def test_list_gateways_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_list_gateways" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_list_gateways_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_list_gateways" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_list_gateways" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_list_gateways_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_list_gateways" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10985,8 +10996,9 @@ def test_get_gateway_rest_bad_request(request_type=apigateway.GetGatewayRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11057,17 +11069,20 @@ def test_get_gateway_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_get_gateway" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_get_gateway_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_get_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_get_gateway" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_get_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_get_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11116,8 +11131,9 @@ def test_create_gateway_rest_bad_request(request_type=apigateway.CreateGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11251,19 +11267,21 @@ def test_create_gateway_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_create_gateway" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_create_gateway_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_create_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_create_gateway" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_create_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_create_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11316,8 +11334,9 @@ def test_update_gateway_rest_bad_request(request_type=apigateway.UpdateGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11453,19 +11472,21 @@ def test_update_gateway_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_update_gateway" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_update_gateway_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_update_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_update_gateway" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_update_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_update_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11516,8 +11537,9 @@ def test_delete_gateway_rest_bad_request(request_type=apigateway.DeleteGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11574,19 +11596,21 @@ def test_delete_gateway_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_delete_gateway" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_delete_gateway_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_delete_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_delete_gateway" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_delete_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_delete_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11637,8 +11661,9 @@ def test_list_apis_rest_bad_request(request_type=apigateway.ListApisRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11703,17 +11728,19 @@ def test_list_apis_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_list_apis" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_list_apis_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_list_apis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_list_apis" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_list_apis_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_list_apis" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11764,8 +11791,9 @@ def test_get_api_rest_bad_request(request_type=apigateway.GetApiRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11834,17 +11862,19 @@ def test_get_api_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_get_api" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_get_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_get_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_get_api" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_get_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_get_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11893,8 +11923,9 @@ def test_create_api_rest_bad_request(request_type=apigateway.CreateApiRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12027,19 +12058,20 @@ def test_create_api_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_create_api" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_create_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_create_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_create_api" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_create_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_create_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12088,8 +12120,9 @@ def test_update_api_rest_bad_request(request_type=apigateway.UpdateApiRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12222,19 +12255,20 @@ def test_update_api_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_update_api" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_update_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_update_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_update_api" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_update_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_update_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12283,8 +12317,9 @@ def test_delete_api_rest_bad_request(request_type=apigateway.DeleteApiRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12341,19 +12376,20 @@ def test_delete_api_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_delete_api" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_delete_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_delete_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_delete_api" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_delete_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_delete_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12404,8 +12440,9 @@ def test_list_api_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12470,18 +12507,20 @@ def test_list_api_configs_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_list_api_configs" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, - "post_list_api_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_list_api_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_list_api_configs" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_list_api_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_list_api_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12536,8 +12575,9 @@ def test_get_api_config_rest_bad_request(request_type=apigateway.GetApiConfigReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12610,17 +12650,20 @@ def test_get_api_config_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_get_api_config" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_get_api_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_get_api_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_get_api_config" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_get_api_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_get_api_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12671,8 +12714,9 @@ def test_create_api_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12811,20 +12855,21 @@ def test_create_api_config_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_create_api_config" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, - "post_create_api_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_create_api_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_create_api_config" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_create_api_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_create_api_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12881,8 +12926,9 @@ def test_update_api_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13025,20 +13071,21 @@ def test_update_api_config_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_update_api_config" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, - "post_update_api_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_update_api_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_update_api_config" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_update_api_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_update_api_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13093,8 +13140,9 @@ def test_delete_api_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13153,20 +13201,21 @@ def test_delete_api_config_rest_interceptors(null_interceptor): ) client = ApiGatewayServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "post_delete_api_config" - ) as post, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, - "post_delete_api_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiGatewayServiceRestInterceptor, "pre_delete_api_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "post_delete_api_config" + ) as post, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, + "post_delete_api_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiGatewayServiceRestInterceptor, "pre_delete_api_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13610,11 +13659,14 @@ def test_api_gateway_service_base_transport(): def test_api_gateway_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apigateway_v1.services.api_gateway_service.transports.ApiGatewayServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apigateway_v1.services.api_gateway_service.transports.ApiGatewayServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiGatewayServiceTransport( @@ -13631,9 +13683,12 @@ def test_api_gateway_service_base_transport_with_credentials_file(): def test_api_gateway_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apigateway_v1.services.api_gateway_service.transports.ApiGatewayServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apigateway_v1.services.api_gateway_service.transports.ApiGatewayServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiGatewayServiceTransport() @@ -13705,11 +13760,12 @@ def test_api_gateway_service_transport_auth_gdch_credentials(transport_class): def test_api_gateway_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/async_client.py b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/async_client.py index 5d61666845a1..5a0f37c02af5 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/async_client.py +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> ApiKeysTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1261,7 +1261,7 @@ async def sample_lookup_key(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1287,8 +1287,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1297,7 +1301,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1305,7 +1309,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/client.py b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/client.py index 2a7713d2680d..f982563d310e 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/client.py +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/client.py @@ -116,7 +116,7 @@ class ApiKeysClient(metaclass=ApiKeysClientMeta): """Manages the API keys associated with projects.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = ApiKeysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1689,7 +1693,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1715,8 +1719,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1725,7 +1733,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1734,7 +1742,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/README.rst b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/README.rst index d6d7382b335c..57b95d18e183 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/README.rst +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiKeysTransport` is the ABC for all transports. -- public child `ApiKeysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiKeysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiKeysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiKeysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiKeysTransport`` is the ABC for all transports. + +- public child ``ApiKeysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiKeysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiKeysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiKeysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/base.py b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/base.py index 4e6f9956c636..bd521a738153 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/base.py +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc.py b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc.py index b1b35bd63d45..fa09148a4949 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc.py +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc_asyncio.py b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc_asyncio.py index c9301035706b..ac072b27cd01 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc_asyncio.py +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/rest.py b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/rest.py index f444b75f9312..cbb6ef15c645 100644 --- a/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/rest.py +++ b/packages/google-cloud-api-keys/google/cloud/api_keys_v2/services/api_keys/transports/rest.py @@ -599,6 +599,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiKeysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-api-keys/noxfile.py b/packages/google-cloud-api-keys/noxfile.py index 8560ee563ced..1718a6c59157 100644 --- a/packages/google-cloud-api-keys/noxfile.py +++ b/packages/google-cloud-api-keys/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-api-keys/setup.py b/packages/google-cloud-api-keys/setup.py index 24aada60734c..58e1258261f1 100644 --- a/packages/google-cloud-api-keys/setup.py +++ b/packages/google-cloud-api-keys/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-api-keys" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-api-keys/testing/constraints-3.7.txt b/packages/google-cloud-api-keys/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-api-keys/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-api-keys/testing/constraints-3.8.txt b/packages/google-cloud-api-keys/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-api-keys/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-api-keys/testing/constraints-3.9.txt b/packages/google-cloud-api-keys/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-api-keys/testing/constraints-3.9.txt +++ b/packages/google-cloud-api-keys/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-api-keys/tests/unit/gapic/api_keys_v2/test_api_keys.py b/packages/google-cloud-api-keys/tests/unit/gapic/api_keys_v2/test_api_keys.py index 67c89912e06f..f0ab3dbed3c1 100644 --- a/packages/google-cloud-api-keys/tests/unit/gapic/api_keys_v2/test_api_keys.py +++ b/packages/google-cloud-api-keys/tests/unit/gapic/api_keys_v2/test_api_keys.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiKeysClient._get_default_mtls_endpoint(None) is None assert ApiKeysClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -142,6 +143,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ApiKeysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ApiKeysClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1223,11 +1225,13 @@ def test_api_keys_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5768,8 +5772,9 @@ def test_create_key_rest_bad_request(request_type=apikeys.CreateKeyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5933,19 +5938,16 @@ def test_create_key_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiKeysRestInterceptor, "post_create_key" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_create_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_create_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.ApiKeysRestInterceptor, "post_create_key") as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_create_key_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_create_key") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5994,8 +5996,9 @@ def test_list_keys_rest_bad_request(request_type=apikeys.ListKeysRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6056,17 +6059,15 @@ def test_list_keys_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_list_keys" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_list_keys_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_list_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiKeysRestInterceptor, "post_list_keys") as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_list_keys_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_list_keys") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6115,8 +6116,9 @@ def test_get_key_rest_bad_request(request_type=apikeys.GetKeyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6185,17 +6187,15 @@ def test_get_key_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_get_key" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_get_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_get_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiKeysRestInterceptor, "post_get_key") as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_get_key_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_get_key") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6244,8 +6244,9 @@ def test_get_key_string_rest_bad_request(request_type=apikeys.GetKeyStringReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6306,17 +6307,19 @@ def test_get_key_string_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_get_key_string" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_get_key_string_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_get_key_string" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_get_key_string" + ) as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_get_key_string_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiKeysRestInterceptor, "pre_get_key_string" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6367,8 +6370,9 @@ def test_update_key_rest_bad_request(request_type=apikeys.UpdateKeyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6532,19 +6536,16 @@ def test_update_key_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiKeysRestInterceptor, "post_update_key" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_update_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_update_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.ApiKeysRestInterceptor, "post_update_key") as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_update_key_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_update_key") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6593,8 +6594,9 @@ def test_delete_key_rest_bad_request(request_type=apikeys.DeleteKeyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6649,19 +6651,16 @@ def test_delete_key_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiKeysRestInterceptor, "post_delete_key" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_delete_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_delete_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.ApiKeysRestInterceptor, "post_delete_key") as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_delete_key_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_delete_key") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6710,8 +6709,9 @@ def test_undelete_key_rest_bad_request(request_type=apikeys.UndeleteKeyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6766,19 +6766,18 @@ def test_undelete_key_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiKeysRestInterceptor, "post_undelete_key" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_undelete_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_undelete_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_undelete_key" + ) as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_undelete_key_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_undelete_key") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6827,8 +6826,9 @@ def test_lookup_key_rest_bad_request(request_type=apikeys.LookupKeyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6891,17 +6891,15 @@ def test_lookup_key_rest_interceptors(null_interceptor): ) client = ApiKeysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_lookup_key" - ) as post, mock.patch.object( - transports.ApiKeysRestInterceptor, "post_lookup_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiKeysRestInterceptor, "pre_lookup_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiKeysRestInterceptor, "post_lookup_key") as post, + mock.patch.object( + transports.ApiKeysRestInterceptor, "post_lookup_key_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiKeysRestInterceptor, "pre_lookup_key") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6952,8 +6950,9 @@ def test_get_operation_rest_bad_request( request = json_format.ParseDict({"name": "operations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7251,11 +7250,14 @@ def test_api_keys_base_transport(): def test_api_keys_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.api_keys_v2.services.api_keys.transports.ApiKeysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.api_keys_v2.services.api_keys.transports.ApiKeysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiKeysTransport( @@ -7275,9 +7277,12 @@ def test_api_keys_base_transport_with_credentials_file(): def test_api_keys_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.api_keys_v2.services.api_keys.transports.ApiKeysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.api_keys_v2.services.api_keys.transports.ApiKeysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiKeysTransport() @@ -7355,11 +7360,12 @@ def test_api_keys_transport_auth_gdch_credentials(transport_class): def test_api_keys_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7975,6 +7981,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiKeysClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiKeysAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = ApiKeysClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py index 0439e0ab6fe4..423f03681392 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> ConnectionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py index 96d087252698..88a41d4cad2f 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/client.py @@ -109,7 +109,7 @@ class ConnectionServiceClient(metaclass=ConnectionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -117,7 +117,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -127,6 +127,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -429,7 +433,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -526,7 +530,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( self._universe_domain = ConnectionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/README.rst b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/README.rst index 78c1c64f4d94..255f0213d916 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/README.rst +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConnectionServiceTransport` is the ABC for all transports. -- public child `ConnectionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConnectionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConnectionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConnectionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConnectionServiceTransport`` is the ABC for all transports. + +- public child ``ConnectionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConnectionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConnectionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConnectionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py index 42e01ef5ed1d..067c5b3aa659 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py index 87c7323bd970..8915fa96da4b 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py index aa3440968d31..35bb3045aa0d 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py index 758b11f16cdb..45c5eb9b8431 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/async_client.py @@ -181,7 +181,7 @@ def transport(self) -> TetherTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py index 5357fb9e2418..943c28c64109 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/client.py @@ -114,7 +114,7 @@ class TetherClient(metaclass=TetherClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -514,7 +518,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = TetherClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/README.rst b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/README.rst index e841871e44b6..ee3fc3671b43 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/README.rst +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TetherTransport` is the ABC for all transports. -- public child `TetherGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TetherGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTetherRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TetherRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TetherTransport`` is the ABC for all transports. + +- public child ``TetherGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TetherGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTetherRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TetherRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py index 1fb20efdb197..3e149b44163b 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py index 8a489a19df2e..9efc9440b4ec 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py index 5b102ef520e7..62bdb5f1a190 100644 --- a/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py +++ b/packages/google-cloud-apigee-connect/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-connect/noxfile.py b/packages/google-cloud-apigee-connect/noxfile.py index f463db9aa6c1..2a32633a78e5 100644 --- a/packages/google-cloud-apigee-connect/noxfile.py +++ b/packages/google-cloud-apigee-connect/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-apigee-connect/setup.py b/packages/google-cloud-apigee-connect/setup.py index 10744f6f0803..0282031ba647 100644 --- a/packages/google-cloud-apigee-connect/setup.py +++ b/packages/google-cloud-apigee-connect/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-apigee-connect" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-apigee-connect/testing/constraints-3.7.txt b/packages/google-cloud-apigee-connect/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-apigee-connect/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-apigee-connect/testing/constraints-3.8.txt b/packages/google-cloud-apigee-connect/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-apigee-connect/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-apigee-connect/testing/constraints-3.9.txt b/packages/google-cloud-apigee-connect/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-apigee-connect/testing/constraints-3.9.txt +++ b/packages/google-cloud-apigee-connect/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py index a3fe88228321..928ecdc9cc79 100644 --- a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py +++ b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConnectionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): ConnectionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConnectionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1283,11 +1288,13 @@ def test_connection_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2048,11 +2055,14 @@ def test_connection_service_base_transport(): def test_connection_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apigeeconnect_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apigeeconnect_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConnectionServiceTransport( @@ -2069,9 +2079,12 @@ def test_connection_service_base_transport_with_credentials_file(): def test_connection_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apigeeconnect_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apigeeconnect_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConnectionServiceTransport() @@ -2142,11 +2155,12 @@ def test_connection_service_transport_auth_gdch_credentials(transport_class): def test_connection_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py index 89a30f39f0be..65d5e65c6f4d 100644 --- a/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py +++ b/packages/google-cloud-apigee-connect/tests/unit/gapic/apigeeconnect_v1/test_tether.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TetherClient._get_default_mtls_endpoint(None) is None assert TetherClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -133,6 +134,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TetherClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert TetherClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1194,11 +1196,13 @@ def test_tether_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1535,11 +1539,14 @@ def test_tether_base_transport(): def test_tether_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apigeeconnect_v1.services.tether.transports.TetherTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apigeeconnect_v1.services.tether.transports.TetherTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TetherTransport( @@ -1556,9 +1563,12 @@ def test_tether_base_transport_with_credentials_file(): def test_tether_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apigeeconnect_v1.services.tether.transports.TetherTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apigeeconnect_v1.services.tether.transports.TetherTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TetherTransport() @@ -1629,11 +1639,12 @@ def test_tether_transport_auth_gdch_credentials(transport_class): def test_tether_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/async_client.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/async_client.py index f2815a419afa..00ea125d1295 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/async_client.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> ProvisioningTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -700,7 +700,7 @@ async def sample_get_instance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -726,8 +726,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -736,7 +740,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -744,7 +748,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -755,7 +759,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -781,8 +785,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -791,7 +799,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -799,7 +807,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -810,7 +818,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -840,8 +848,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -850,7 +862,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -858,7 +870,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -866,7 +878,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -895,8 +907,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -905,7 +921,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -913,7 +929,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -921,7 +937,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1013,8 +1029,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1023,7 +1043,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1031,7 +1053,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1042,7 +1064,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1135,8 +1157,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1145,7 +1171,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1153,7 +1181,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1164,7 +1192,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1195,8 +1223,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1207,7 +1239,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1215,7 +1249,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1226,7 +1260,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1252,8 +1286,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1262,7 +1300,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1270,7 +1308,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1281,7 +1319,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1307,8 +1345,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1317,7 +1359,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1325,7 +1367,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/client.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/client.py index 4d20995d7df0..797fd4d9402e 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/client.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/client.py @@ -121,7 +121,7 @@ class ProvisioningClient(metaclass=ProvisioningClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -446,7 +450,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -543,7 +547,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = ProvisioningClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1135,7 +1139,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1161,8 +1165,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1171,7 +1179,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1180,7 +1188,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1194,7 +1202,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1220,8 +1228,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1230,7 +1242,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1239,7 +1251,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1253,7 +1265,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1283,8 +1295,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1293,7 +1309,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1301,7 +1317,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1309,7 +1325,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1338,8 +1354,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1348,7 +1368,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1356,7 +1376,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1384,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1456,8 +1476,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1466,7 +1490,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1475,7 +1501,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1489,7 +1515,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1582,8 +1608,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1592,7 +1622,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1601,7 +1633,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1615,7 +1647,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1646,8 +1678,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1656,7 +1692,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1665,7 +1703,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1679,7 +1717,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1705,8 +1743,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1715,7 +1757,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1724,7 +1766,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1738,7 +1780,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1764,8 +1806,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1774,7 +1820,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1783,7 +1829,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/README.rst b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/README.rst index b4ffb54c2b53..8ab0531ac8a1 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/README.rst +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProvisioningTransport` is the ABC for all transports. -- public child `ProvisioningGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProvisioningGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProvisioningRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProvisioningRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProvisioningTransport`` is the ABC for all transports. + +- public child ``ProvisioningGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProvisioningGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProvisioningRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProvisioningRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/base.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/base.py index 21908bec15b7..8753a2c59eec 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/base.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc.py index e4ca9064ca24..5f415c9c8d27 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc_asyncio.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc_asyncio.py index d34e586db240..ce822df655cd 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc_asyncio.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/rest.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/rest.py index 8bb0b7779add..59b26ad6c03e 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/rest.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/provisioning/transports/rest.py @@ -540,6 +540,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProvisioningRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/async_client.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/async_client.py index 80c62972f5c7..830effcee7b5 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/async_client.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> RegistryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4548,7 +4548,7 @@ async def sample_delete_artifact(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4574,8 +4574,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4584,7 +4588,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4592,7 +4596,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4603,7 +4607,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4629,8 +4633,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4639,7 +4647,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4647,7 +4655,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4658,7 +4666,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4688,8 +4696,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4698,7 +4710,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4706,7 +4718,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4714,7 +4726,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4743,8 +4755,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4753,7 +4769,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4761,7 +4777,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4769,7 +4785,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4861,8 +4877,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4871,7 +4891,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4879,7 +4901,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4890,7 +4912,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4983,8 +5005,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4993,7 +5019,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5001,7 +5029,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5012,7 +5040,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5043,8 +5071,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5055,7 +5087,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5063,7 +5097,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5074,7 +5108,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5100,8 +5134,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5110,7 +5148,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5118,7 +5156,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5129,7 +5167,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5155,8 +5193,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5165,7 +5207,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5173,7 +5215,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/client.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/client.py index 70d0fe4c5c94..7576dbb431cc 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/client.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/client.py @@ -122,7 +122,7 @@ class RegistryClient(metaclass=RegistryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -543,7 +547,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -640,7 +644,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -736,7 +740,7 @@ def __init__( self._universe_domain = RegistryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4993,7 +4997,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5019,8 +5023,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5029,7 +5037,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5038,7 +5046,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5052,7 +5060,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5078,8 +5086,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5088,7 +5100,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5097,7 +5109,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5111,7 +5123,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5141,8 +5153,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5151,7 +5167,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5159,7 +5175,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5167,7 +5183,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5196,8 +5212,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5206,7 +5226,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5214,7 +5234,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5222,7 +5242,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5314,8 +5334,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5324,7 +5348,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5333,7 +5359,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5347,7 +5373,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5440,8 +5466,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5450,7 +5480,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5459,7 +5491,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5473,7 +5505,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5504,8 +5536,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5514,7 +5550,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5523,7 +5561,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5537,7 +5575,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5563,8 +5601,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5573,7 +5615,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5582,7 +5624,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5596,7 +5638,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5622,8 +5664,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5632,7 +5678,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5641,7 +5687,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/README.rst b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/README.rst index d12b693a74fe..7d798922d542 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/README.rst +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegistryTransport` is the ABC for all transports. -- public child `RegistryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegistryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegistryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegistryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegistryTransport`` is the ABC for all transports. + +- public child ``RegistryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegistryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegistryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegistryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/base.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/base.py index 2d2f111b2d1c..622023ed5490 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/base.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc.py index 49030f6dd07a..29e54a3c725a 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc_asyncio.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc_asyncio.py index 434ee227aee4..98e16c3e72f7 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc_asyncio.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/rest.py b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/rest.py index 5bb18ffc0993..6e5ffeb49566 100644 --- a/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/rest.py +++ b/packages/google-cloud-apigee-registry/google/cloud/apigee_registry_v1/services/registry/transports/rest.py @@ -2169,6 +2169,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegistryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apigee-registry/noxfile.py b/packages/google-cloud-apigee-registry/noxfile.py index 9ea07ae813e3..e4dcd7b3739a 100644 --- a/packages/google-cloud-apigee-registry/noxfile.py +++ b/packages/google-cloud-apigee-registry/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-apigee-registry/setup.py b/packages/google-cloud-apigee-registry/setup.py index 4a7550e5120f..a90c4653c159 100644 --- a/packages/google-cloud-apigee-registry/setup.py +++ b/packages/google-cloud-apigee-registry/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-apigee-registry/testing/constraints-3.7.txt b/packages/google-cloud-apigee-registry/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-apigee-registry/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-apigee-registry/testing/constraints-3.8.txt b/packages/google-cloud-apigee-registry/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-apigee-registry/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-apigee-registry/testing/constraints-3.9.txt b/packages/google-cloud-apigee-registry/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-apigee-registry/testing/constraints-3.9.txt +++ b/packages/google-cloud-apigee-registry/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_provisioning.py b/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_provisioning.py index bc094b4878d6..b4f2e301af79 100644 --- a/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_provisioning.py +++ b/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_provisioning.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProvisioningClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ProvisioningClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ProvisioningClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1269,11 +1274,13 @@ def test_provisioning_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3147,8 +3154,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3283,19 +3291,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProvisioningRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3348,8 +3357,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3406,19 +3416,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProvisioningRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3471,8 +3482,9 @@ def test_get_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3539,17 +3551,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProvisioningRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3604,8 +3618,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3664,8 +3679,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3726,8 +3742,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3788,8 +3805,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3850,8 +3868,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3912,8 +3931,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3974,8 +3994,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4036,8 +4057,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4098,8 +4120,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4300,11 +4323,14 @@ def test_provisioning_base_transport(): def test_provisioning_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apigee_registry_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apigee_registry_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProvisioningTransport( @@ -4321,9 +4347,12 @@ def test_provisioning_base_transport_with_credentials_file(): def test_provisioning_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apigee_registry_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apigee_registry_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProvisioningTransport() @@ -4395,11 +4424,12 @@ def test_provisioning_transport_auth_gdch_credentials(transport_class): def test_provisioning_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4991,6 +5021,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5130,6 +5192,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5275,6 +5369,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5420,6 +5548,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5565,6 +5727,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5706,6 +5902,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5870,6 +6100,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = ProvisioningClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6037,6 +6302,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = ProvisioningClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6214,6 +6514,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = ProvisioningClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_registry.py b/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_registry.py index aa3516329585..c4d086002489 100644 --- a/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_registry.py +++ b/packages/google-cloud-apigee-registry/tests/unit/gapic/apigee_registry_v1/test_registry.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegistryClient._get_default_mtls_endpoint(None) is None assert RegistryClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -146,6 +147,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegistryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RegistryClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1235,11 +1237,13 @@ def test_registry_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -23224,8 +23228,9 @@ def test_list_apis_rest_bad_request(request_type=registry_service.ListApisReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23286,17 +23291,15 @@ def test_list_apis_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_apis" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_apis_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_apis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegistryRestInterceptor, "post_list_apis") as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_apis_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegistryRestInterceptor, "pre_list_apis") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23349,8 +23352,9 @@ def test_get_api_rest_bad_request(request_type=registry_service.GetApiRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23421,17 +23425,15 @@ def test_get_api_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegistryRestInterceptor, "post_get_api") as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegistryRestInterceptor, "pre_get_api") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23480,8 +23482,9 @@ def test_create_api_rest_bad_request(request_type=registry_service.CreateApiRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23631,17 +23634,17 @@ def test_create_api_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_create_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegistryRestInterceptor, "pre_create_api") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23692,8 +23695,9 @@ def test_update_api_rest_bad_request(request_type=registry_service.UpdateApiRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23843,17 +23847,17 @@ def test_update_api_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_update_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegistryRestInterceptor, "pre_update_api") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23904,8 +23908,9 @@ def test_delete_api_rest_bad_request(request_type=registry_service.DeleteApiRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23960,13 +23965,11 @@ def test_delete_api_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegistryRestInterceptor, "pre_delete_api") as pre, + ): pre.assert_not_called() pb_message = registry_service.DeleteApiRequest.pb( registry_service.DeleteApiRequest() @@ -24011,8 +24014,9 @@ def test_list_api_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24073,17 +24077,19 @@ def test_list_api_versions_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_versions" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_api_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_versions" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_list_api_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24143,8 +24149,9 @@ def test_get_api_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24213,17 +24220,19 @@ def test_get_api_version_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_version" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_api_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_version" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_get_api_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24276,8 +24285,9 @@ def test_create_api_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24421,17 +24431,19 @@ def test_create_api_version_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_version" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_create_api_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api_version" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_create_api_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24488,8 +24500,9 @@ def test_update_api_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24637,17 +24650,19 @@ def test_update_api_version_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_version" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_update_api_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api_version" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_update_api_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24702,8 +24717,9 @@ def test_delete_api_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24760,13 +24776,13 @@ def test_delete_api_version_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_api_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_delete_api_version" + ) as pre, + ): pre.assert_not_called() pb_message = registry_service.DeleteApiVersionRequest.pb( registry_service.DeleteApiVersionRequest() @@ -24813,8 +24829,9 @@ def test_list_api_specs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24877,17 +24894,19 @@ def test_list_api_specs_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_specs" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_specs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_api_specs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_specs" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_specs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_list_api_specs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24945,8 +24964,9 @@ def test_get_api_spec_rest_bad_request(request_type=registry_service.GetApiSpecR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25025,17 +25045,19 @@ def test_get_api_spec_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_spec" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_api_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_spec" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_get_api_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25090,8 +25112,9 @@ def test_get_api_spec_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25153,17 +25176,20 @@ def test_get_api_spec_contents_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_spec_contents" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_spec_contents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_api_spec_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_spec_contents" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_get_api_spec_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_get_api_spec_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25218,8 +25244,9 @@ def test_create_api_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25381,17 +25408,19 @@ def test_create_api_spec_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_spec" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_create_api_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api_spec" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_create_api_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25448,8 +25477,9 @@ def test_update_api_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25613,17 +25643,19 @@ def test_update_api_spec_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_spec" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_update_api_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api_spec" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_update_api_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25678,8 +25710,9 @@ def test_delete_api_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25736,13 +25769,13 @@ def test_delete_api_spec_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_api_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_delete_api_spec" + ) as pre, + ): pre.assert_not_called() pb_message = registry_service.DeleteApiSpecRequest.pb( registry_service.DeleteApiSpecRequest() @@ -25789,8 +25822,9 @@ def test_tag_api_spec_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25869,17 +25903,20 @@ def test_tag_api_spec_revision_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_tag_api_spec_revision" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_tag_api_spec_revision_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_tag_api_spec_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_tag_api_spec_revision" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_tag_api_spec_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_tag_api_spec_revision" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25934,8 +25971,9 @@ def test_list_api_spec_revisions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25998,17 +26036,20 @@ def test_list_api_spec_revisions_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_spec_revisions" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_spec_revisions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_api_spec_revisions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_spec_revisions" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_list_api_spec_revisions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_list_api_spec_revisions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26068,8 +26109,9 @@ def test_rollback_api_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26148,17 +26190,19 @@ def test_rollback_api_spec_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_rollback_api_spec" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_rollback_api_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_rollback_api_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_rollback_api_spec" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_rollback_api_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_rollback_api_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26213,8 +26257,9 @@ def test_delete_api_spec_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26293,18 +26338,20 @@ def test_delete_api_spec_revision_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_delete_api_spec_revision" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, - "post_delete_api_spec_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_api_spec_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_delete_api_spec_revision" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_delete_api_spec_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_delete_api_spec_revision" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26357,8 +26404,9 @@ def test_list_api_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26419,17 +26467,20 @@ def test_list_api_deployments_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_deployments" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_api_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_deployments" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_list_api_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_list_api_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26489,8 +26540,9 @@ def test_get_api_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26569,17 +26621,19 @@ def test_get_api_deployment_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_deployment" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_api_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_api_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_deployment" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_api_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_get_api_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26634,8 +26688,9 @@ def test_create_api_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26797,17 +26852,20 @@ def test_create_api_deployment_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_deployment" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_api_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_create_api_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_api_deployment" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_create_api_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_create_api_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26866,8 +26924,9 @@ def test_update_api_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27033,17 +27092,20 @@ def test_update_api_deployment_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_deployment" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_update_api_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_update_api_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_update_api_deployment" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_update_api_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_update_api_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27100,8 +27162,9 @@ def test_delete_api_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27158,13 +27221,13 @@ def test_delete_api_deployment_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_api_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_delete_api_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = registry_service.DeleteApiDeploymentRequest.pb( registry_service.DeleteApiDeploymentRequest() @@ -27211,8 +27274,9 @@ def test_tag_api_deployment_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27291,18 +27355,20 @@ def test_tag_api_deployment_revision_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_tag_api_deployment_revision" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, - "post_tag_api_deployment_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_tag_api_deployment_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_tag_api_deployment_revision" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_tag_api_deployment_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_tag_api_deployment_revision" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27359,8 +27425,9 @@ def test_list_api_deployment_revisions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27425,18 +27492,20 @@ def test_list_api_deployment_revisions_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_api_deployment_revisions" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, - "post_list_api_deployment_revisions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_api_deployment_revisions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_api_deployment_revisions" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_list_api_deployment_revisions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_list_api_deployment_revisions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27496,8 +27565,9 @@ def test_rollback_api_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27576,17 +27646,20 @@ def test_rollback_api_deployment_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_rollback_api_deployment" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_rollback_api_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_rollback_api_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_rollback_api_deployment" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_rollback_api_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_rollback_api_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27643,8 +27716,9 @@ def test_delete_api_deployment_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27723,18 +27797,20 @@ def test_delete_api_deployment_revision_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_delete_api_deployment_revision" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, - "post_delete_api_deployment_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_api_deployment_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_delete_api_deployment_revision" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_delete_api_deployment_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_delete_api_deployment_revision" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27789,8 +27865,9 @@ def test_list_artifacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27851,17 +27928,19 @@ def test_list_artifacts_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_artifacts" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_list_artifacts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_list_artifacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_artifacts" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_list_artifacts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_list_artifacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27919,8 +27998,9 @@ def test_get_artifact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27989,17 +28069,19 @@ def test_get_artifact_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_artifact" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_artifact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_artifact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_artifact" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_artifact_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_get_artifact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28052,8 +28134,9 @@ def test_get_artifact_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28113,17 +28196,20 @@ def test_get_artifact_contents_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_artifact_contents" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_get_artifact_contents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_get_artifact_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_get_artifact_contents" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, + "post_get_artifact_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_get_artifact_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28176,8 +28262,9 @@ def test_create_artifact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28322,17 +28409,19 @@ def test_create_artifact_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_artifact" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_create_artifact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_create_artifact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_artifact" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_create_artifact_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_create_artifact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28387,8 +28476,9 @@ def test_replace_artifact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28535,17 +28625,19 @@ def test_replace_artifact_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "post_replace_artifact" - ) as post, mock.patch.object( - transports.RegistryRestInterceptor, "post_replace_artifact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegistryRestInterceptor, "pre_replace_artifact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "post_replace_artifact" + ) as post, + mock.patch.object( + transports.RegistryRestInterceptor, "post_replace_artifact_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_replace_artifact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28598,8 +28690,9 @@ def test_delete_artifact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28654,13 +28747,13 @@ def test_delete_artifact_rest_interceptors(null_interceptor): ) client = RegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegistryRestInterceptor, "pre_delete_artifact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegistryRestInterceptor, "pre_delete_artifact" + ) as pre, + ): pre.assert_not_called() pb_message = registry_service.DeleteArtifactRequest.pb( registry_service.DeleteArtifactRequest() @@ -28705,8 +28798,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28765,8 +28859,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28827,8 +28922,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28889,8 +28985,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28951,8 +29048,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -29013,8 +29111,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -29075,8 +29174,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -29137,8 +29237,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -29199,8 +29300,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -30089,11 +30191,14 @@ def test_registry_base_transport(): def test_registry_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apigee_registry_v1.services.registry.transports.RegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apigee_registry_v1.services.registry.transports.RegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegistryTransport( @@ -30110,9 +30215,12 @@ def test_registry_base_transport_with_credentials_file(): def test_registry_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apigee_registry_v1.services.registry.transports.RegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apigee_registry_v1.services.registry.transports.RegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegistryTransport() @@ -30184,11 +30292,12 @@ def test_registry_transport_auth_gdch_credentials(transport_class): def test_registry_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -30960,6 +31069,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = RegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31099,6 +31240,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31244,6 +31417,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31389,6 +31596,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31534,6 +31775,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = RegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31675,6 +31950,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = RegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31839,6 +32148,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = RegistryClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -32006,6 +32350,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = RegistryClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -32183,6 +32562,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = RegistryClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = RegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = RegistryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/async_client.py index ef1760ed282b..4af9eeb52b9f 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ApiHubTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5266,7 +5266,7 @@ async def sample_list_external_apis(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5292,8 +5292,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5302,7 +5306,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5310,7 +5314,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5321,7 +5325,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5347,8 +5351,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5357,7 +5365,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5365,7 +5373,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5376,7 +5384,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5406,8 +5414,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5416,7 +5428,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5424,7 +5436,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5432,7 +5444,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5461,8 +5473,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5471,7 +5487,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5479,7 +5495,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5487,7 +5503,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5513,8 +5529,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5523,7 +5543,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5531,7 +5551,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5542,7 +5562,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5568,8 +5588,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5578,7 +5602,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5586,7 +5610,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/client.py index 1d9e3fa72ffb..a4562a1889af 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/client.py @@ -114,7 +114,7 @@ class ApiHubClient(metaclass=ApiHubClientMeta): """This service provides all methods related to the API hub.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -633,7 +637,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -730,7 +734,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -826,7 +830,7 @@ def __init__( self._universe_domain = ApiHubClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5784,7 +5788,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5810,8 +5814,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5820,7 +5828,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5829,7 +5837,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5843,7 +5851,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5869,8 +5877,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5879,7 +5891,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5888,7 +5900,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5902,7 +5914,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5932,8 +5944,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5942,7 +5958,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5950,7 +5966,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5958,7 +5974,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5987,8 +6003,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5997,7 +6017,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6005,7 +6025,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6013,7 +6033,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6039,8 +6059,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6049,7 +6073,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6058,7 +6082,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6072,7 +6096,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6098,8 +6122,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6108,7 +6136,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6117,7 +6145,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/README.rst index 0b59d76af31f..87c332ea3d13 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiHubTransport` is the ABC for all transports. -- public child `ApiHubGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiHubGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiHubRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiHubRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiHubTransport`` is the ABC for all transports. + +- public child ``ApiHubGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiHubGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiHubRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiHubRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/base.py index e551dd5ecb33..d46d1ea6f54d 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc.py index af7536543a18..f684041186c7 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc_asyncio.py index 7e4654a60bdd..b16a3e42026e 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/rest.py index a2763e950bd1..374e28db5af4 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub/transports/rest.py @@ -2158,6 +2158,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiHubRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/async_client.py index a0c2c9951b74..01052211a88c 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> ApiHubCollectTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -475,7 +475,7 @@ async def sample_collect_api_data(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -501,8 +501,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -511,7 +515,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -519,7 +523,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -530,7 +534,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -556,8 +560,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -566,7 +574,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -574,7 +582,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -585,7 +593,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -615,8 +623,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -625,7 +637,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -633,7 +645,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -641,7 +653,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -670,8 +682,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -680,7 +696,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -688,7 +704,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -696,7 +712,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -722,8 +738,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -732,7 +752,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -740,7 +760,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -751,7 +771,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -777,8 +797,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -787,7 +811,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -795,7 +819,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/client.py index 49ee40f1471f..1b5dbf7ddb34 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/client.py @@ -116,7 +116,7 @@ class ApiHubCollectClient(metaclass=ApiHubCollectClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -613,7 +617,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -710,7 +714,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -806,7 +810,7 @@ def __init__( self._universe_domain = ApiHubCollectClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1069,7 +1073,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1095,8 +1099,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1105,7 +1113,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1114,7 +1122,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1128,7 +1136,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1154,8 +1162,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1164,7 +1176,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1173,7 +1185,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1187,7 +1199,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1217,8 +1229,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1227,7 +1243,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1235,7 +1251,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1243,7 +1259,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1288,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1302,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1290,7 +1310,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1298,7 +1318,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1324,8 +1344,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1334,7 +1358,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1343,7 +1367,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1357,7 +1381,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1383,8 +1407,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1393,7 +1421,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1402,7 +1430,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/README.rst index 6e21d66de1a5..c5fe7b4273d4 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiHubCollectTransport` is the ABC for all transports. -- public child `ApiHubCollectGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiHubCollectGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiHubCollectRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiHubCollectRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiHubCollectTransport`` is the ABC for all transports. + +- public child ``ApiHubCollectGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiHubCollectGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiHubCollectRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiHubCollectRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/base.py index 7cae984c266b..2096ed25e1d9 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc.py index 26f51ba38869..ad3fffd61cbd 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc_asyncio.py index f52c619571ad..2fa8e2a5eb08 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/rest.py index 2b89134bcb2b..5911896bb371 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_collect/transports/rest.py @@ -351,6 +351,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiHubCollectRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/async_client.py index 2c59c7c62d79..7ca9ce3a5d6e 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> ApiHubCurateTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -924,7 +924,7 @@ async def sample_delete_curation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -950,8 +950,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -960,7 +964,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -968,7 +972,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -979,7 +983,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1005,8 +1009,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1015,7 +1023,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1023,7 +1031,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1034,7 +1042,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1064,8 +1072,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1074,7 +1086,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1082,7 +1094,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1090,7 +1102,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1119,8 +1131,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1129,7 +1145,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1137,7 +1153,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1145,7 +1161,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1171,8 +1187,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1181,7 +1201,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1189,7 +1209,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1200,7 +1220,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1226,8 +1246,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1236,7 +1260,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1244,7 +1268,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/client.py index b9fd7ade1ebb..045c18e8ad87 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/client.py @@ -116,7 +116,7 @@ class ApiHubCurateClient(metaclass=ApiHubCurateClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -562,7 +566,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -658,7 +662,7 @@ def __init__( self._universe_domain = ApiHubCurateClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1373,7 +1377,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1399,8 +1403,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1409,7 +1417,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1418,7 +1426,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1432,7 +1440,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1458,8 +1466,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1468,7 +1480,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1477,7 +1489,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1491,7 +1503,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1521,8 +1533,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1531,7 +1547,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1539,7 +1555,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1547,7 +1563,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1576,8 +1592,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1586,7 +1606,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1594,7 +1614,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1602,7 +1622,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1628,8 +1648,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1638,7 +1662,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1647,7 +1671,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1661,7 +1685,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1687,8 +1711,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1697,7 +1725,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1706,7 +1734,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/README.rst index 4c2e30460011..f15ca34e62c0 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiHubCurateTransport` is the ABC for all transports. -- public child `ApiHubCurateGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiHubCurateGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiHubCurateRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiHubCurateRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiHubCurateTransport`` is the ABC for all transports. + +- public child ``ApiHubCurateGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiHubCurateGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiHubCurateRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiHubCurateRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/base.py index 5e1f8427118a..4a9c9b2d8c57 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc.py index 281de696e65f..83b7e5e910fa 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc_asyncio.py index 840f26e28229..9f068663ec0e 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/rest.py index ab474c981ff3..edde6054a45f 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_curate/transports/rest.py @@ -539,6 +539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiHubCurateRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/async_client.py index 448dc070cfcb..1befa72c8f2a 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ApiHubDependenciesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -955,7 +955,7 @@ async def sample_list_dependencies(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -981,8 +981,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -991,7 +995,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -999,7 +1003,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1010,7 +1014,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1036,8 +1040,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1046,7 +1054,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1054,7 +1062,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1065,7 +1073,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1095,8 +1103,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1105,7 +1117,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1113,7 +1125,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1121,7 +1133,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1150,8 +1162,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1160,7 +1176,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1168,7 +1184,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1176,7 +1192,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1202,8 +1218,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1212,7 +1232,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1220,7 +1240,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1231,7 +1251,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1257,8 +1277,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1267,7 +1291,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1275,7 +1299,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/client.py index 507e83f935b1..9e083f1d4314 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/client.py @@ -116,7 +116,7 @@ class ApiHubDependenciesClient(metaclass=ApiHubDependenciesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -562,7 +566,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = ApiHubDependenciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1404,7 +1408,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1430,8 +1434,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1440,7 +1448,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1449,7 +1457,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1463,7 +1471,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1489,8 +1497,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1499,7 +1511,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1508,7 +1520,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1522,7 +1534,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1552,8 +1564,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1562,7 +1578,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1570,7 +1586,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1578,7 +1594,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1607,8 +1623,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1617,7 +1637,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1625,7 +1645,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1633,7 +1653,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1659,8 +1679,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1669,7 +1693,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1678,7 +1702,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1692,7 +1716,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1718,8 +1742,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1728,7 +1756,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1737,7 +1765,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/README.rst index 2c35fa4431dd..02b6f1511400 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiHubDependenciesTransport` is the ABC for all transports. -- public child `ApiHubDependenciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiHubDependenciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiHubDependenciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiHubDependenciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiHubDependenciesTransport`` is the ABC for all transports. + +- public child ``ApiHubDependenciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiHubDependenciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiHubDependenciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiHubDependenciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/base.py index 4628f0b1284c..dd8b9665744e 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc.py index df8d4d549002..edee677a422d 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc_asyncio.py index 5f626f0ba80c..112b738c5e79 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/rest.py index 1fb08d0bbc1e..ad81eb094c04 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_dependencies/transports/rest.py @@ -539,6 +539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiHubDependenciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/async_client.py index b4a7036dbe5a..8f0c2106d2be 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> ApiHubDiscoveryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -815,7 +815,7 @@ async def sample_get_discovered_api_operation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -841,8 +841,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -851,7 +855,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -859,7 +863,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -870,7 +874,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -896,8 +900,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -906,7 +914,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -914,7 +922,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -925,7 +933,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -955,8 +963,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -965,7 +977,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -973,7 +985,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -981,7 +993,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1010,8 +1022,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1020,7 +1036,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1028,7 +1044,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1036,7 +1052,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1062,8 +1078,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1072,7 +1092,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1080,7 +1100,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1091,7 +1111,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1117,8 +1137,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1127,7 +1151,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1135,7 +1159,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/client.py index bd89c36804d7..1e0c1277e237 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/client.py @@ -115,7 +115,7 @@ class ApiHubDiscoveryClient(metaclass=ApiHubDiscoveryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -488,7 +492,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -585,7 +589,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -683,7 +687,7 @@ def __init__( self._universe_domain = ApiHubDiscoveryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1288,7 +1292,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1314,8 +1318,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1324,7 +1332,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1333,7 +1341,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1347,7 +1355,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1373,8 +1381,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1383,7 +1395,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1392,7 +1404,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1406,7 +1418,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1436,8 +1448,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1446,7 +1462,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1454,7 +1470,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1462,7 +1478,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1491,8 +1507,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1501,7 +1521,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1509,7 +1529,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1517,7 +1537,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1543,8 +1563,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1553,7 +1577,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1562,7 +1586,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1576,7 +1600,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1602,8 +1626,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1612,7 +1640,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1621,7 +1649,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/README.rst index 12724c54e931..cb97fc94b45d 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiHubDiscoveryTransport` is the ABC for all transports. -- public child `ApiHubDiscoveryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiHubDiscoveryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiHubDiscoveryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiHubDiscoveryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiHubDiscoveryTransport`` is the ABC for all transports. + +- public child ``ApiHubDiscoveryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiHubDiscoveryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiHubDiscoveryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiHubDiscoveryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/base.py index e439f43ad29e..e3344efd05f9 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc.py index 609c550b1961..59b09682c741 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc_asyncio.py index 7691a5ef724b..c44700a1a2e4 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/rest.py index 25d41c20c583..e1f540802ec1 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_discovery/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiHubDiscoveryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/async_client.py index e4ebaacf96ba..8a3d5849f649 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/async_client.py @@ -199,7 +199,7 @@ def transport(self) -> ApiHubPluginTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2176,7 +2176,7 @@ async def sample_delete_plugin_instance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2202,8 +2202,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2212,7 +2216,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2220,7 +2224,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2231,7 +2235,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2257,8 +2261,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2267,7 +2275,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2275,7 +2283,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2286,7 +2294,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2316,8 +2324,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2326,7 +2338,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2334,7 +2346,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2342,7 +2354,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2371,8 +2383,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2381,7 +2397,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2389,7 +2405,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2397,7 +2413,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2423,8 +2439,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2433,7 +2453,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2441,7 +2461,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2452,7 +2472,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2478,8 +2498,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2488,7 +2512,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2496,7 +2520,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/client.py index 76a137f83560..3624bde30147 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/client.py @@ -117,7 +117,7 @@ class ApiHubPluginClient(metaclass=ApiHubPluginClientMeta): """This service is used for managing plugins inside the API Hub.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -508,7 +512,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -605,7 +609,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -701,7 +705,7 @@ def __init__( self._universe_domain = ApiHubPluginClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2640,7 +2644,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2666,8 +2670,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2676,7 +2684,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2685,7 +2693,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2699,7 +2707,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2725,8 +2733,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2735,7 +2747,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2744,7 +2756,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2758,7 +2770,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2788,8 +2800,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2798,7 +2814,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2806,7 +2822,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2814,7 +2830,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2843,8 +2859,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2853,7 +2873,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2861,7 +2881,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2869,7 +2889,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2895,8 +2915,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2905,7 +2929,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2914,7 +2938,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2928,7 +2952,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2954,8 +2978,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2964,7 +2992,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2973,7 +3001,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/README.rst index c536b54ff0f2..3ae0c56e4cec 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApiHubPluginTransport` is the ABC for all transports. -- public child `ApiHubPluginGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApiHubPluginGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApiHubPluginRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApiHubPluginRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApiHubPluginTransport`` is the ABC for all transports. + +- public child ``ApiHubPluginGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApiHubPluginGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApiHubPluginRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApiHubPluginRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/base.py index b3420469a9ce..ff69604a1f08 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc.py index 98e58024f918..3b57aa24cfc3 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc_asyncio.py index edc29f977dbd..f08a168ada3d 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/rest.py index 748d05b117b1..c488730ad86f 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/api_hub_plugin/transports/rest.py @@ -1087,6 +1087,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApiHubPluginRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/async_client.py index 89f823bccc63..26bbf4a46bcb 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> HostProjectRegistrationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -768,7 +768,7 @@ async def sample_list_host_project_registrations(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -794,8 +794,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -804,7 +808,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -812,7 +816,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -823,7 +827,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -849,8 +853,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -859,7 +867,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -867,7 +875,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -878,7 +886,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -908,8 +916,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -918,7 +930,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -926,7 +938,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -934,7 +946,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -963,8 +975,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -973,7 +989,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -981,7 +997,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -989,7 +1005,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1015,8 +1031,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1025,7 +1045,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1033,7 +1053,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1044,7 +1064,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1070,8 +1090,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1080,7 +1104,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1088,7 +1112,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/client.py index 9f1252421df0..e82e54a0ba8a 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/client.py @@ -122,7 +122,7 @@ class HostProjectRegistrationServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -550,7 +554,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -654,7 +658,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1209,7 +1213,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1235,8 +1239,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1245,7 +1253,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1254,7 +1262,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1268,7 +1276,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1294,8 +1302,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1304,7 +1316,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1313,7 +1325,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1327,7 +1339,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1357,8 +1369,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1367,7 +1383,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1375,7 +1391,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1383,7 +1399,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1412,8 +1428,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1422,7 +1442,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1430,7 +1450,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1438,7 +1458,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1464,8 +1484,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1474,7 +1498,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1483,7 +1507,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1497,7 +1521,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1523,8 +1547,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1533,7 +1561,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1542,7 +1570,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/README.rst index 66029e909ab2..a885d93d6c8c 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HostProjectRegistrationServiceTransport` is the ABC for all transports. -- public child `HostProjectRegistrationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HostProjectRegistrationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHostProjectRegistrationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HostProjectRegistrationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HostProjectRegistrationServiceTransport`` is the ABC for all transports. + +- public child ``HostProjectRegistrationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HostProjectRegistrationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHostProjectRegistrationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HostProjectRegistrationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/base.py index 19f8ea517b06..93795306650d 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc.py index 8306204a9534..ce8957132594 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc_asyncio.py index 938a8bffd5d3..b87c5e1bfd12 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/rest.py index 0acc20c219af..06cda687bcb0 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/host_project_registration_service/transports/rest.py @@ -477,6 +477,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[HostProjectRegistrationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/async_client.py index 277960d3d114..b5f804a0036c 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> LintingServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -737,7 +737,7 @@ async def sample_lint_spec(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -763,8 +763,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -773,7 +777,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -781,7 +785,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -792,7 +796,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -818,8 +822,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -828,7 +836,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -836,7 +844,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -847,7 +855,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -877,8 +885,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -887,7 +899,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -895,7 +907,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -903,7 +915,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -932,8 +944,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -942,7 +958,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -950,7 +966,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -958,7 +974,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -984,8 +1000,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -994,7 +1014,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1002,7 +1022,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1013,7 +1033,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,8 +1059,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1049,7 +1073,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1057,7 +1081,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/client.py index 49d4056f2e27..e423feb7cfae 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/client.py @@ -112,7 +112,7 @@ class LintingServiceClient(metaclass=LintingServiceClientMeta): """This service provides all methods related to the 1p Linter.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -463,7 +467,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -560,7 +564,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -656,7 +660,7 @@ def __init__( self._universe_domain = LintingServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1193,7 +1197,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1219,8 +1223,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1229,7 +1237,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1238,7 +1246,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1252,7 +1260,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1278,8 +1286,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1288,7 +1300,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1297,7 +1309,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1311,7 +1323,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1341,8 +1353,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1351,7 +1367,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1359,7 +1375,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1367,7 +1383,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1396,8 +1412,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1406,7 +1426,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1414,7 +1434,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1422,7 +1442,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1448,8 +1468,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1458,7 +1482,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1467,7 +1491,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1481,7 +1505,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1507,8 +1531,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1517,7 +1545,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1526,7 +1554,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/README.rst index e13962034956..90db6d4639c2 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LintingServiceTransport` is the ABC for all transports. -- public child `LintingServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LintingServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLintingServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LintingServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LintingServiceTransport`` is the ABC for all transports. + +- public child ``LintingServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LintingServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLintingServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LintingServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/base.py index da4bbabd313c..05c0caf27544 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc.py index d8f562d8730e..6df7007284a9 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc_asyncio.py index 38b341faffdb..fc3f39dd1a06 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/rest.py index 6f6be942e354..549f68292874 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/linting_service/transports/rest.py @@ -483,6 +483,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LintingServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/async_client.py index ef6cd1c07b1f..996fefb00194 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> ProvisioningTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -827,7 +827,7 @@ async def sample_lookup_api_hub_instance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -853,8 +853,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -863,7 +867,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -871,7 +875,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -882,7 +886,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -908,8 +912,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -918,7 +926,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -926,7 +934,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -937,7 +945,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -967,8 +975,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -977,7 +989,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -985,7 +997,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -993,7 +1005,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1022,8 +1034,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1032,7 +1048,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1040,7 +1056,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1048,7 +1064,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1074,8 +1090,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1084,7 +1104,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1112,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1103,7 +1123,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1129,8 +1149,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1139,7 +1163,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1147,7 +1171,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/client.py index 7d815c935815..ca11aa3e2d9c 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/client.py @@ -117,7 +117,7 @@ class ProvisioningClient(metaclass=ProvisioningClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = ProvisioningClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1257,7 +1261,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1283,8 +1287,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1293,7 +1301,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1302,7 +1310,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1316,7 +1324,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1342,8 +1350,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1352,7 +1364,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1361,7 +1373,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1375,7 +1387,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1405,8 +1417,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1415,7 +1431,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1423,7 +1439,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1431,7 +1447,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1460,8 +1476,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1470,7 +1490,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1478,7 +1498,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1486,7 +1506,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1512,8 +1532,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1522,7 +1546,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1531,7 +1555,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1545,7 +1569,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1571,8 +1595,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1581,7 +1609,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1590,7 +1618,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/README.rst index b4ffb54c2b53..8ab0531ac8a1 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProvisioningTransport` is the ABC for all transports. -- public child `ProvisioningGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProvisioningGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProvisioningRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProvisioningRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProvisioningTransport`` is the ABC for all transports. + +- public child ``ProvisioningGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProvisioningGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProvisioningRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProvisioningRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/base.py index f139acaf443b..169cd27293c1 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc.py index 758baea7239d..be193c758941 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc_asyncio.py index 550f40f0f7f2..7407f0dfa37f 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/rest.py index 96715b819814..1cd0d0c22d78 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/provisioning/transports/rest.py @@ -525,6 +525,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProvisioningRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/async_client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/async_client.py index 2dcb75adc4ab..a0e1e8dc2ebe 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/async_client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> RuntimeProjectAttachmentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -999,7 +999,7 @@ async def sample_lookup_runtime_project_attachment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1025,8 +1025,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1035,7 +1039,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1043,7 +1047,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1054,7 +1058,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1080,8 +1084,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1090,7 +1098,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1098,7 +1106,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1109,7 +1117,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1139,8 +1147,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1149,7 +1161,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1157,7 +1169,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1165,7 +1177,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1194,8 +1206,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1204,7 +1220,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1212,7 +1228,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1220,7 +1236,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1246,8 +1262,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1256,7 +1276,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1264,7 +1284,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1275,7 +1295,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1301,8 +1321,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1311,7 +1335,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1319,7 +1343,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/client.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/client.py index f74a6bf09167..2578db1688a2 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/client.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/client.py @@ -122,7 +122,7 @@ class RuntimeProjectAttachmentServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -550,7 +554,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -654,7 +658,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1438,7 +1442,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1464,8 +1468,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1474,7 +1482,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1483,7 +1491,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1497,7 +1505,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1523,8 +1531,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1533,7 +1545,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1542,7 +1554,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1556,7 +1568,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1586,8 +1598,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1596,7 +1612,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1604,7 +1620,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1612,7 +1628,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1641,8 +1657,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1651,7 +1671,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1659,7 +1679,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1667,7 +1687,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1693,8 +1713,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1703,7 +1727,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1712,7 +1736,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1726,7 +1750,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1752,8 +1776,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1762,7 +1790,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1771,7 +1799,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/README.rst b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/README.rst index 4bd33bef66a2..45733a3a69b1 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/README.rst +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RuntimeProjectAttachmentServiceTransport` is the ABC for all transports. -- public child `RuntimeProjectAttachmentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RuntimeProjectAttachmentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRuntimeProjectAttachmentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RuntimeProjectAttachmentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RuntimeProjectAttachmentServiceTransport`` is the ABC for all transports. + +- public child ``RuntimeProjectAttachmentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RuntimeProjectAttachmentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRuntimeProjectAttachmentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RuntimeProjectAttachmentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/base.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/base.py index 487855c3d176..8ff7bb052fd3 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/base.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc.py index d79d41a07955..ea66264f9779 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc_asyncio.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc_asyncio.py index 76ad4053a3e1..0ca60183d1ff 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/rest.py b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/rest.py index 7d649e428d19..6c015d2e25cc 100644 --- a/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/rest.py +++ b/packages/google-cloud-apihub/google/cloud/apihub_v1/services/runtime_project_attachment_service/transports/rest.py @@ -558,6 +558,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RuntimeProjectAttachmentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apihub/noxfile.py b/packages/google-cloud-apihub/noxfile.py index ef708ea14615..6cc302b62ccb 100644 --- a/packages/google-cloud-apihub/noxfile.py +++ b/packages/google-cloud-apihub/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-apihub/setup.py b/packages/google-cloud-apihub/setup.py index dfc5e1a4ea2d..a3c81ae19b16 100644 --- a/packages/google-cloud-apihub/setup.py +++ b/packages/google-cloud-apihub/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-apihub" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-apihub/testing/constraints-3.7.txt b/packages/google-cloud-apihub/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-apihub/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-apihub/testing/constraints-3.8.txt b/packages/google-cloud-apihub/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-apihub/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-apihub/testing/constraints-3.9.txt b/packages/google-cloud-apihub/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-apihub/testing/constraints-3.9.txt +++ b/packages/google-cloud-apihub/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub.py index 78222151548e..2b5f8092b36e 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiHubClient._get_default_mtls_endpoint(None) is None assert ApiHubClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -138,6 +139,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ApiHubClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ApiHubClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1216,11 +1218,13 @@ def test_api_hub_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -25593,8 +25597,9 @@ def test_create_api_rest_bad_request(request_type=apihub_service.CreateApiReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25780,17 +25785,15 @@ def test_create_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_api" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_create_api") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_api_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_create_api") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25841,8 +25844,9 @@ def test_get_api_rest_bad_request(request_type=apihub_service.GetApiRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25913,17 +25917,15 @@ def test_get_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_api" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_get_api") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_api_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_get_api") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25972,8 +25974,9 @@ def test_list_apis_rest_bad_request(request_type=apihub_service.ListApisRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26034,17 +26037,15 @@ def test_list_apis_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_apis" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_apis_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_apis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_list_apis") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_apis_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_list_apis") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26095,8 +26096,9 @@ def test_update_api_rest_bad_request(request_type=apihub_service.UpdateApiReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26282,17 +26284,15 @@ def test_update_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_api" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_update_api") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_api_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_update_api") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26343,8 +26343,9 @@ def test_delete_api_rest_bad_request(request_type=apihub_service.DeleteApiReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26399,13 +26400,11 @@ def test_delete_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_delete_api") as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteApiRequest.pb( apihub_service.DeleteApiRequest() @@ -26450,8 +26449,9 @@ def test_create_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26637,17 +26637,19 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26700,8 +26702,9 @@ def test_get_version_rest_bad_request(request_type=apihub_service.GetVersionRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26778,17 +26781,15 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_get_version") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_get_version") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26841,8 +26842,9 @@ def test_list_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26903,17 +26905,17 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_list_versions") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26975,8 +26977,9 @@ def test_update_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27166,17 +27169,19 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27231,8 +27236,9 @@ def test_delete_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27289,13 +27295,13 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteVersionRequest.pb( apihub_service.DeleteVersionRequest() @@ -27340,8 +27346,9 @@ def test_create_spec_rest_bad_request(request_type=apihub_service.CreateSpecRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27540,17 +27547,15 @@ def test_create_spec_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_spec" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_create_spec") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_create_spec") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27603,8 +27608,9 @@ def test_get_spec_rest_bad_request(request_type=apihub_service.GetSpecRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27673,17 +27679,15 @@ def test_get_spec_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_spec" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_get_spec") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_get_spec") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27736,8 +27740,9 @@ def test_get_spec_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27802,17 +27807,19 @@ def test_get_spec_contents_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_spec_contents" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_spec_contents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_spec_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_spec_contents" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_spec_contents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_get_spec_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27865,8 +27872,9 @@ def test_list_specs_rest_bad_request(request_type=apihub_service.ListSpecsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27929,17 +27937,15 @@ def test_list_specs_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_specs" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_specs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_specs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_list_specs") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_specs_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_list_specs") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27996,8 +28002,9 @@ def test_update_spec_rest_bad_request(request_type=apihub_service.UpdateSpecRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28198,17 +28205,15 @@ def test_update_spec_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_spec" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "post_update_spec") as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_update_spec") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28261,8 +28266,9 @@ def test_delete_spec_rest_bad_request(request_type=apihub_service.DeleteSpecRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28319,13 +28325,11 @@ def test_delete_spec_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_delete_spec") as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteSpecRequest.pb( apihub_service.DeleteSpecRequest() @@ -28372,8 +28376,9 @@ def test_create_api_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28533,17 +28538,19 @@ def test_create_api_operation_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_api_operation" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_api_operation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_api_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_api_operation" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_api_operation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_create_api_operation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28598,8 +28605,9 @@ def test_get_api_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28664,17 +28672,19 @@ def test_get_api_operation_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_api_operation" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_api_operation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_api_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_api_operation" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_api_operation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_get_api_operation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28729,8 +28739,9 @@ def test_list_api_operations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28793,17 +28804,19 @@ def test_list_api_operations_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_api_operations" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_api_operations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_api_operations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_api_operations" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_api_operations_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_list_api_operations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28865,8 +28878,9 @@ def test_update_api_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29028,17 +29042,19 @@ def test_update_api_operation_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_api_operation" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_api_operation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_api_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_api_operation" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_api_operation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_update_api_operation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29093,8 +29109,9 @@ def test_delete_api_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29151,13 +29168,13 @@ def test_delete_api_operation_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_api_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_delete_api_operation" + ) as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteApiOperationRequest.pb( apihub_service.DeleteApiOperationRequest() @@ -29204,8 +29221,9 @@ def test_get_definition_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29272,17 +29290,19 @@ def test_get_definition_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_definition" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_definition_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_definition" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_definition" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_definition_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_get_definition" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29335,8 +29355,9 @@ def test_create_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29524,17 +29545,19 @@ def test_create_deployment_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_deployment" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_deployment" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_create_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29587,8 +29610,9 @@ def test_get_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29663,17 +29687,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29726,8 +29752,9 @@ def test_list_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29788,17 +29815,19 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_deployments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29858,8 +29887,9 @@ def test_update_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30049,17 +30079,19 @@ def test_update_deployment_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_deployment" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_deployment" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_update_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30112,8 +30144,9 @@ def test_delete_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30168,13 +30201,13 @@ def test_delete_deployment_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_delete_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteDeploymentRequest.pb( apihub_service.DeleteDeploymentRequest() @@ -30219,8 +30252,9 @@ def test_create_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30385,17 +30419,19 @@ def test_create_attribute_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_attribute" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_attribute_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_attribute" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_attribute_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_create_attribute" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30448,8 +30484,9 @@ def test_get_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30527,17 +30564,17 @@ def test_get_attribute_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_attribute" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_attribute_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_attribute" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_attribute_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ApiHubRestInterceptor, "pre_get_attribute") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30592,8 +30629,9 @@ def test_update_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30760,17 +30798,19 @@ def test_update_attribute_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_attribute" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_attribute_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_attribute" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_attribute_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_update_attribute" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30823,8 +30863,9 @@ def test_delete_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30879,13 +30920,13 @@ def test_delete_attribute_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_delete_attribute" + ) as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteAttributeRequest.pb( apihub_service.DeleteAttributeRequest() @@ -30930,8 +30971,9 @@ def test_list_attributes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30992,17 +31034,19 @@ def test_list_attributes_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_attributes" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_attributes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_attributes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_attributes" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_attributes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_list_attributes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31060,8 +31104,9 @@ def test_search_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31122,17 +31167,19 @@ def test_search_resources_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_search_resources" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_search_resources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_search_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_search_resources" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_search_resources_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_search_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31190,8 +31237,9 @@ def test_create_external_api_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31338,17 +31386,19 @@ def test_create_external_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_external_api" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_create_external_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_create_external_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_external_api" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_create_external_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_create_external_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31401,8 +31451,9 @@ def test_get_external_api_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31471,17 +31522,19 @@ def test_get_external_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_external_api" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_get_external_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_get_external_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_external_api" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_get_external_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_get_external_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31538,8 +31591,9 @@ def test_update_external_api_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31690,17 +31744,19 @@ def test_update_external_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_external_api" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_update_external_api_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_update_external_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_external_api" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_update_external_api_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_update_external_api" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31753,8 +31809,9 @@ def test_delete_external_api_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31809,13 +31866,13 @@ def test_delete_external_api_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_delete_external_api" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_delete_external_api" + ) as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteExternalApiRequest.pb( apihub_service.DeleteExternalApiRequest() @@ -31860,8 +31917,9 @@ def test_list_external_apis_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31922,17 +31980,19 @@ def test_list_external_apis_rest_interceptors(null_interceptor): ) client = ApiHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_external_apis" - ) as post, mock.patch.object( - transports.ApiHubRestInterceptor, "post_list_external_apis_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubRestInterceptor, "pre_list_external_apis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_external_apis" + ) as post, + mock.patch.object( + transports.ApiHubRestInterceptor, "post_list_external_apis_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubRestInterceptor, "pre_list_external_apis" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31990,8 +32050,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32050,8 +32111,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32112,8 +32174,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32174,8 +32237,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32236,8 +32300,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32298,8 +32363,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33236,11 +33302,14 @@ def test_api_hub_base_transport(): def test_api_hub_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.api_hub.transports.ApiHubTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.api_hub.transports.ApiHubTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubTransport( @@ -33257,9 +33326,12 @@ def test_api_hub_base_transport_with_credentials_file(): def test_api_hub_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.api_hub.transports.ApiHubTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.api_hub.transports.ApiHubTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubTransport() @@ -33331,11 +33403,12 @@ def test_api_hub_transport_auth_gdch_credentials(transport_class): def test_api_hub_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -34236,6 +34309,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ApiHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ApiHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ApiHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34375,6 +34480,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ApiHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ApiHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ApiHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34520,6 +34657,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ApiHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34665,6 +34836,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ApiHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ApiHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ApiHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34810,6 +35015,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ApiHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ApiHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ApiHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34951,6 +35190,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ApiHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ApiHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ApiHubClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_collect.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_collect.py index addf14f1a765..aa24fd309da2 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_collect.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_collect.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiHubCollectClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): assert ( ApiHubCollectClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ApiHubCollectClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1282,11 +1287,13 @@ def test_api_hub_collect_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2112,8 +2119,9 @@ def test_collect_api_data_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2170,19 +2178,21 @@ def test_collect_api_data_rest_interceptors(null_interceptor): ) client = ApiHubCollectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubCollectRestInterceptor, "post_collect_api_data" - ) as post, mock.patch.object( - transports.ApiHubCollectRestInterceptor, "post_collect_api_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubCollectRestInterceptor, "pre_collect_api_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubCollectRestInterceptor, "post_collect_api_data" + ) as post, + mock.patch.object( + transports.ApiHubCollectRestInterceptor, + "post_collect_api_data_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubCollectRestInterceptor, "pre_collect_api_data" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2235,8 +2245,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2295,8 +2306,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2357,8 +2369,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2419,8 +2432,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2481,8 +2495,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2543,8 +2558,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2700,11 +2716,14 @@ def test_api_hub_collect_base_transport(): def test_api_hub_collect_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.api_hub_collect.transports.ApiHubCollectTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_collect.transports.ApiHubCollectTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubCollectTransport( @@ -2721,9 +2740,12 @@ def test_api_hub_collect_base_transport_with_credentials_file(): def test_api_hub_collect_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.api_hub_collect.transports.ApiHubCollectTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_collect.transports.ApiHubCollectTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubCollectTransport() @@ -2795,11 +2817,12 @@ def test_api_hub_collect_transport_auth_gdch_credentials(transport_class): def test_api_hub_collect_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3612,6 +3635,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ApiHubCollectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ApiHubCollectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ApiHubCollectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3751,6 +3806,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ApiHubCollectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ApiHubCollectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ApiHubCollectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3896,6 +3983,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiHubCollectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiHubCollectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ApiHubCollectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4041,6 +4162,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ApiHubCollectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ApiHubCollectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ApiHubCollectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4186,6 +4341,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ApiHubCollectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ApiHubCollectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ApiHubCollectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4327,6 +4516,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ApiHubCollectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ApiHubCollectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ApiHubCollectClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_curate.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_curate.py index 14628ab2b935..e08459396f0f 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_curate.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_curate.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiHubCurateClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ApiHubCurateClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ApiHubCurateClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1261,11 +1266,13 @@ def test_api_hub_curate_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4583,8 +4590,9 @@ def test_create_curation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4749,17 +4757,19 @@ def test_create_curation_rest_interceptors(null_interceptor): ) client = ApiHubCurateClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_create_curation" - ) as post, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_create_curation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "pre_create_curation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_create_curation" + ) as post, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_create_curation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "pre_create_curation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4810,8 +4820,9 @@ def test_get_curation_rest_bad_request(request_type=curate_service.GetCurationRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4890,17 +4901,19 @@ def test_get_curation_rest_interceptors(null_interceptor): ) client = ApiHubCurateClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_get_curation" - ) as post, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_get_curation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "pre_get_curation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_get_curation" + ) as post, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_get_curation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "pre_get_curation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4953,8 +4966,9 @@ def test_list_curations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5017,17 +5031,19 @@ def test_list_curations_rest_interceptors(null_interceptor): ) client = ApiHubCurateClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_list_curations" - ) as post, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_list_curations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "pre_list_curations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_list_curations" + ) as post, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_list_curations_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "pre_list_curations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5087,8 +5103,9 @@ def test_update_curation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5255,17 +5272,19 @@ def test_update_curation_rest_interceptors(null_interceptor): ) client = ApiHubCurateClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_update_curation" - ) as post, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "post_update_curation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "pre_update_curation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_update_curation" + ) as post, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "post_update_curation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "pre_update_curation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5318,8 +5337,9 @@ def test_delete_curation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5376,13 +5396,13 @@ def test_delete_curation_rest_interceptors(null_interceptor): ) client = ApiHubCurateClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubCurateRestInterceptor, "pre_delete_curation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubCurateRestInterceptor, "pre_delete_curation" + ) as pre, + ): pre.assert_not_called() pb_message = curate_service.DeleteCurationRequest.pb( curate_service.DeleteCurationRequest() @@ -5427,8 +5447,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5487,8 +5508,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5549,8 +5571,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5611,8 +5634,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5673,8 +5697,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5735,8 +5760,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5954,11 +5980,14 @@ def test_api_hub_curate_base_transport(): def test_api_hub_curate_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.api_hub_curate.transports.ApiHubCurateTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_curate.transports.ApiHubCurateTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubCurateTransport( @@ -5975,9 +6004,12 @@ def test_api_hub_curate_base_transport_with_credentials_file(): def test_api_hub_curate_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.api_hub_curate.transports.ApiHubCurateTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_curate.transports.ApiHubCurateTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubCurateTransport() @@ -6049,11 +6081,12 @@ def test_api_hub_curate_transport_auth_gdch_credentials(transport_class): def test_api_hub_curate_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6648,6 +6681,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ApiHubCurateClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ApiHubCurateAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ApiHubCurateClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6787,6 +6852,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ApiHubCurateClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ApiHubCurateAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ApiHubCurateClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6932,6 +7029,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiHubCurateClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiHubCurateAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ApiHubCurateClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7077,6 +7208,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ApiHubCurateClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ApiHubCurateAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ApiHubCurateClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7222,6 +7387,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ApiHubCurateClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ApiHubCurateAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ApiHubCurateClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7363,6 +7562,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ApiHubCurateClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ApiHubCurateAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ApiHubCurateClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_dependencies.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_dependencies.py index 2150f2f0ac16..8476c6e9d3cb 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_dependencies.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_dependencies.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiHubDependenciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): ApiHubDependenciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ApiHubDependenciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1326,11 +1331,13 @@ def test_api_hub_dependencies_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4692,8 +4699,9 @@ def test_create_dependency_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4845,18 +4853,20 @@ def test_create_dependency_rest_interceptors(null_interceptor): ) client = ApiHubDependenciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "post_create_dependency" - ) as post, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, - "post_create_dependency_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "pre_create_dependency" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "post_create_dependency" + ) as post, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, + "post_create_dependency_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "pre_create_dependency" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4909,8 +4919,9 @@ def test_get_dependency_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4979,18 +4990,20 @@ def test_get_dependency_rest_interceptors(null_interceptor): ) client = ApiHubDependenciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "post_get_dependency" - ) as post, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, - "post_get_dependency_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "pre_get_dependency" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "post_get_dependency" + ) as post, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, + "post_get_dependency_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "pre_get_dependency" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5047,8 +5060,9 @@ def test_update_dependency_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5204,18 +5218,20 @@ def test_update_dependency_rest_interceptors(null_interceptor): ) client = ApiHubDependenciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "post_update_dependency" - ) as post, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, - "post_update_dependency_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "pre_update_dependency" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "post_update_dependency" + ) as post, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, + "post_update_dependency_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "pre_update_dependency" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5268,8 +5284,9 @@ def test_delete_dependency_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5326,13 +5343,13 @@ def test_delete_dependency_rest_interceptors(null_interceptor): ) client = ApiHubDependenciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "pre_delete_dependency" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "pre_delete_dependency" + ) as pre, + ): pre.assert_not_called() pb_message = apihub_service.DeleteDependencyRequest.pb( apihub_service.DeleteDependencyRequest() @@ -5377,8 +5394,9 @@ def test_list_dependencies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5441,18 +5459,20 @@ def test_list_dependencies_rest_interceptors(null_interceptor): ) client = ApiHubDependenciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "post_list_dependencies" - ) as post, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, - "post_list_dependencies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDependenciesRestInterceptor, "pre_list_dependencies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "post_list_dependencies" + ) as post, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, + "post_list_dependencies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDependenciesRestInterceptor, "pre_list_dependencies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5510,8 +5530,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5570,8 +5591,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5632,8 +5654,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5694,8 +5717,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5756,8 +5780,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5818,8 +5843,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6045,11 +6071,14 @@ def test_api_hub_dependencies_base_transport(): def test_api_hub_dependencies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.api_hub_dependencies.transports.ApiHubDependenciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_dependencies.transports.ApiHubDependenciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubDependenciesTransport( @@ -6066,9 +6095,12 @@ def test_api_hub_dependencies_base_transport_with_credentials_file(): def test_api_hub_dependencies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.api_hub_dependencies.transports.ApiHubDependenciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_dependencies.transports.ApiHubDependenciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubDependenciesTransport() @@ -6140,11 +6172,12 @@ def test_api_hub_dependencies_transport_auth_gdch_credentials(transport_class): def test_api_hub_dependencies_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6749,6 +6782,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ApiHubDependenciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ApiHubDependenciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ApiHubDependenciesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6888,6 +6953,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ApiHubDependenciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ApiHubDependenciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ApiHubDependenciesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7033,6 +7130,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiHubDependenciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiHubDependenciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ApiHubDependenciesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7178,6 +7309,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ApiHubDependenciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ApiHubDependenciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ApiHubDependenciesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7323,6 +7488,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ApiHubDependenciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ApiHubDependenciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ApiHubDependenciesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7464,6 +7663,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ApiHubDependenciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ApiHubDependenciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ApiHubDependenciesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_discovery.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_discovery.py index a0b5217c528b..0b72d46ad7c9 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_discovery.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_discovery.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiHubDiscoveryClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( ApiHubDiscoveryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ApiHubDiscoveryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1307,11 +1312,13 @@ def test_api_hub_discovery_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4456,8 +4463,9 @@ def test_list_discovered_api_observations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4522,20 +4530,22 @@ def test_list_discovered_api_observations_rest_interceptors(null_interceptor): ) client = ApiHubDiscoveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, - "post_list_discovered_api_observations", - ) as post, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, - "post_list_discovered_api_observations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, - "pre_list_discovered_api_observations", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_list_discovered_api_observations", + ) as post, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_list_discovered_api_observations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "pre_list_discovered_api_observations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4595,8 +4605,9 @@ def test_get_discovered_api_observation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4681,18 +4692,22 @@ def test_get_discovered_api_observation_rest_interceptors(null_interceptor): ) client = ApiHubDiscoveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, "post_get_discovered_api_observation" - ) as post, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, - "post_get_discovered_api_observation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, "pre_get_discovered_api_observation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_get_discovered_api_observation", + ) as post, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_get_discovered_api_observation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "pre_get_discovered_api_observation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4752,8 +4767,9 @@ def test_list_discovered_api_operations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4820,18 +4836,22 @@ def test_list_discovered_api_operations_rest_interceptors(null_interceptor): ) client = ApiHubDiscoveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, "post_list_discovered_api_operations" - ) as post, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, - "post_list_discovered_api_operations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, "pre_list_discovered_api_operations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_list_discovered_api_operations", + ) as post, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_list_discovered_api_operations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "pre_list_discovered_api_operations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4891,8 +4911,9 @@ def test_get_discovered_api_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4964,18 +4985,22 @@ def test_get_discovered_api_operation_rest_interceptors(null_interceptor): ) client = ApiHubDiscoveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, "post_get_discovered_api_operation" - ) as post, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, - "post_get_discovered_api_operation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubDiscoveryRestInterceptor, "pre_get_discovered_api_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_get_discovered_api_operation", + ) as post, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "post_get_discovered_api_operation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubDiscoveryRestInterceptor, + "pre_get_discovered_api_operation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5033,8 +5058,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5093,8 +5119,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5155,8 +5182,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5217,8 +5245,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5279,8 +5308,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5341,8 +5371,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5547,11 +5578,14 @@ def test_api_hub_discovery_base_transport(): def test_api_hub_discovery_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.api_hub_discovery.transports.ApiHubDiscoveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_discovery.transports.ApiHubDiscoveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubDiscoveryTransport( @@ -5568,9 +5602,12 @@ def test_api_hub_discovery_base_transport_with_credentials_file(): def test_api_hub_discovery_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.api_hub_discovery.transports.ApiHubDiscoveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_discovery.transports.ApiHubDiscoveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubDiscoveryTransport() @@ -5642,11 +5679,12 @@ def test_api_hub_discovery_transport_auth_gdch_credentials(transport_class): def test_api_hub_discovery_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6282,6 +6320,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ApiHubDiscoveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ApiHubDiscoveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ApiHubDiscoveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6421,6 +6491,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ApiHubDiscoveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ApiHubDiscoveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ApiHubDiscoveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6566,6 +6668,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiHubDiscoveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiHubDiscoveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ApiHubDiscoveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6711,6 +6847,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ApiHubDiscoveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ApiHubDiscoveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ApiHubDiscoveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6856,6 +7026,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ApiHubDiscoveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ApiHubDiscoveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ApiHubDiscoveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6997,6 +7201,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ApiHubDiscoveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ApiHubDiscoveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ApiHubDiscoveryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_plugin.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_plugin.py index 0f1292a57ed2..6009c9719dca 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_plugin.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_api_hub_plugin.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApiHubPluginClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ApiHubPluginClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ApiHubPluginClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1266,11 +1271,13 @@ def test_api_hub_plugin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10261,8 +10268,9 @@ def test_get_plugin_rest_bad_request(request_type=plugin_service.GetPluginReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10337,17 +10345,19 @@ def test_get_plugin_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_get_plugin" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_get_plugin_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_get_plugin" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_get_plugin" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_get_plugin_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_get_plugin" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10400,8 +10410,9 @@ def test_enable_plugin_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10476,17 +10487,19 @@ def test_enable_plugin_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_enable_plugin" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_enable_plugin_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_enable_plugin" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_enable_plugin" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_enable_plugin_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_enable_plugin" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10539,8 +10552,9 @@ def test_disable_plugin_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10615,17 +10629,19 @@ def test_disable_plugin_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_disable_plugin" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_disable_plugin_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_disable_plugin" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_disable_plugin" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_disable_plugin_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_disable_plugin" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10678,8 +10694,9 @@ def test_create_plugin_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10881,17 +10898,19 @@ def test_create_plugin_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_create_plugin" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_create_plugin_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_create_plugin" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_create_plugin" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_create_plugin_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_create_plugin" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10942,8 +10961,9 @@ def test_list_plugins_rest_bad_request(request_type=plugin_service.ListPluginsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11006,17 +11026,19 @@ def test_list_plugins_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_list_plugins" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_list_plugins_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_list_plugins" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_list_plugins" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_list_plugins_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_list_plugins" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11071,8 +11093,9 @@ def test_delete_plugin_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11129,19 +11152,20 @@ def test_delete_plugin_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_delete_plugin" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_delete_plugin_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_delete_plugin" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_delete_plugin" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_delete_plugin_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_delete_plugin" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11194,8 +11218,9 @@ def test_create_plugin_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11376,20 +11401,21 @@ def test_create_plugin_instance_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_create_plugin_instance" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_create_plugin_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_create_plugin_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_create_plugin_instance" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_create_plugin_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_create_plugin_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11444,8 +11470,9 @@ def test_execute_plugin_instance_action_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11504,20 +11531,22 @@ def test_execute_plugin_instance_action_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_execute_plugin_instance_action" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_execute_plugin_instance_action_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_execute_plugin_instance_action" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_execute_plugin_instance_action", + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_execute_plugin_instance_action_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_execute_plugin_instance_action" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11572,8 +11601,9 @@ def test_get_plugin_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11646,17 +11676,20 @@ def test_get_plugin_instance_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_get_plugin_instance" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_get_plugin_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_get_plugin_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_get_plugin_instance" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_get_plugin_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_get_plugin_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11711,8 +11744,9 @@ def test_list_plugin_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11775,18 +11809,20 @@ def test_list_plugin_instances_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_list_plugin_instances" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_list_plugin_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_list_plugin_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_list_plugin_instances" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_list_plugin_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_list_plugin_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11846,8 +11882,9 @@ def test_enable_plugin_instance_action_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11906,20 +11943,21 @@ def test_enable_plugin_instance_action_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_enable_plugin_instance_action" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_enable_plugin_instance_action_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_enable_plugin_instance_action" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_enable_plugin_instance_action" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_enable_plugin_instance_action_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_enable_plugin_instance_action" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11974,8 +12012,9 @@ def test_disable_plugin_instance_action_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12034,20 +12073,22 @@ def test_disable_plugin_instance_action_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_disable_plugin_instance_action" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_disable_plugin_instance_action_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_disable_plugin_instance_action" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_disable_plugin_instance_action", + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_disable_plugin_instance_action_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_disable_plugin_instance_action" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12104,8 +12145,9 @@ def test_update_plugin_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12304,18 +12346,20 @@ def test_update_plugin_instance_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_update_plugin_instance" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_update_plugin_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_update_plugin_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_update_plugin_instance" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_update_plugin_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_update_plugin_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12372,8 +12416,9 @@ def test_delete_plugin_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12432,20 +12477,21 @@ def test_delete_plugin_instance_rest_interceptors(null_interceptor): ) client = ApiHubPluginClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApiHubPluginRestInterceptor, "post_delete_plugin_instance" - ) as post, mock.patch.object( - transports.ApiHubPluginRestInterceptor, - "post_delete_plugin_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ApiHubPluginRestInterceptor, "pre_delete_plugin_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "post_delete_plugin_instance" + ) as post, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, + "post_delete_plugin_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApiHubPluginRestInterceptor, "pre_delete_plugin_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12498,8 +12544,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12558,8 +12605,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12620,8 +12668,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12682,8 +12731,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12744,8 +12794,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12806,8 +12857,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13252,11 +13304,14 @@ def test_api_hub_plugin_base_transport(): def test_api_hub_plugin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.api_hub_plugin.transports.ApiHubPluginTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_plugin.transports.ApiHubPluginTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubPluginTransport( @@ -13273,9 +13328,12 @@ def test_api_hub_plugin_base_transport_with_credentials_file(): def test_api_hub_plugin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.api_hub_plugin.transports.ApiHubPluginTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.api_hub_plugin.transports.ApiHubPluginTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApiHubPluginTransport() @@ -13347,11 +13405,12 @@ def test_api_hub_plugin_transport_auth_gdch_credentials(transport_class): def test_api_hub_plugin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -14056,6 +14115,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ApiHubPluginClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ApiHubPluginAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ApiHubPluginClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14195,6 +14286,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ApiHubPluginClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ApiHubPluginAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ApiHubPluginClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14340,6 +14463,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ApiHubPluginClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ApiHubPluginAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ApiHubPluginClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14485,6 +14642,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ApiHubPluginClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ApiHubPluginAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ApiHubPluginClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14630,6 +14821,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ApiHubPluginClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ApiHubPluginAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ApiHubPluginClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14771,6 +14996,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ApiHubPluginClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ApiHubPluginAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ApiHubPluginClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_host_project_registration_service.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_host_project_registration_service.py index 1e9ed4153961..d69c56ced3d6 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_host_project_registration_service.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_host_project_registration_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert HostProjectRegistrationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): HostProjectRegistrationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + HostProjectRegistrationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1408,11 +1413,13 @@ def test_host_project_registration_service_client_create_channel_credentials_fil ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3767,8 +3774,9 @@ def test_create_host_project_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3915,20 +3923,22 @@ def test_create_host_project_registration_rest_interceptors(null_interceptor): ) client = HostProjectRegistrationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "post_create_host_project_registration", - ) as post, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "post_create_host_project_registration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "pre_create_host_project_registration", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "post_create_host_project_registration", + ) as post, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "post_create_host_project_registration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "pre_create_host_project_registration", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3994,8 +4004,9 @@ def test_get_host_project_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4066,20 +4077,22 @@ def test_get_host_project_registration_rest_interceptors(null_interceptor): ) client = HostProjectRegistrationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "post_get_host_project_registration", - ) as post, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "post_get_host_project_registration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "pre_get_host_project_registration", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "post_get_host_project_registration", + ) as post, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "post_get_host_project_registration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "pre_get_host_project_registration", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4141,8 +4154,9 @@ def test_list_host_project_registrations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4211,20 +4225,22 @@ def test_list_host_project_registrations_rest_interceptors(null_interceptor): ) client = HostProjectRegistrationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "post_list_host_project_registrations", - ) as post, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "post_list_host_project_registrations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HostProjectRegistrationServiceRestInterceptor, - "pre_list_host_project_registrations", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "post_list_host_project_registrations", + ) as post, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "post_list_host_project_registrations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HostProjectRegistrationServiceRestInterceptor, + "pre_list_host_project_registrations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4288,8 +4304,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4348,8 +4365,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4410,8 +4428,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4472,8 +4491,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4534,8 +4554,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4596,8 +4617,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4785,11 +4807,14 @@ def test_host_project_registration_service_base_transport(): def test_host_project_registration_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.host_project_registration_service.transports.HostProjectRegistrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.host_project_registration_service.transports.HostProjectRegistrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HostProjectRegistrationServiceTransport( @@ -4806,9 +4831,12 @@ def test_host_project_registration_service_base_transport_with_credentials_file( def test_host_project_registration_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.host_project_registration_service.transports.HostProjectRegistrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.host_project_registration_service.transports.HostProjectRegistrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HostProjectRegistrationServiceTransport() @@ -4887,11 +4915,12 @@ def test_host_project_registration_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5478,6 +5507,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = HostProjectRegistrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = HostProjectRegistrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = HostProjectRegistrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5617,6 +5678,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = HostProjectRegistrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = HostProjectRegistrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = HostProjectRegistrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5762,6 +5855,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = HostProjectRegistrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = HostProjectRegistrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = HostProjectRegistrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5907,6 +6034,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = HostProjectRegistrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = HostProjectRegistrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = HostProjectRegistrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6052,6 +6213,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = HostProjectRegistrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = HostProjectRegistrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = HostProjectRegistrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6197,6 +6392,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = HostProjectRegistrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = HostProjectRegistrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = HostProjectRegistrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_linting_service.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_linting_service.py index 904f1c68d9c4..62aa6c52292e 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_linting_service.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_linting_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LintingServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( LintingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LintingServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1282,11 +1287,13 @@ def test_linting_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3569,8 +3576,9 @@ def test_get_style_guide_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3637,17 +3645,20 @@ def test_get_style_guide_rest_interceptors(null_interceptor): ) client = LintingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LintingServiceRestInterceptor, "post_get_style_guide" - ) as post, mock.patch.object( - transports.LintingServiceRestInterceptor, "post_get_style_guide_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LintingServiceRestInterceptor, "pre_get_style_guide" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LintingServiceRestInterceptor, "post_get_style_guide" + ) as post, + mock.patch.object( + transports.LintingServiceRestInterceptor, + "post_get_style_guide_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LintingServiceRestInterceptor, "pre_get_style_guide" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3704,8 +3715,9 @@ def test_update_style_guide_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3846,18 +3858,20 @@ def test_update_style_guide_rest_interceptors(null_interceptor): ) client = LintingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LintingServiceRestInterceptor, "post_update_style_guide" - ) as post, mock.patch.object( - transports.LintingServiceRestInterceptor, - "post_update_style_guide_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LintingServiceRestInterceptor, "pre_update_style_guide" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LintingServiceRestInterceptor, "post_update_style_guide" + ) as post, + mock.patch.object( + transports.LintingServiceRestInterceptor, + "post_update_style_guide_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LintingServiceRestInterceptor, "pre_update_style_guide" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3912,8 +3926,9 @@ def test_get_style_guide_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3980,18 +3995,20 @@ def test_get_style_guide_contents_rest_interceptors(null_interceptor): ) client = LintingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LintingServiceRestInterceptor, "post_get_style_guide_contents" - ) as post, mock.patch.object( - transports.LintingServiceRestInterceptor, - "post_get_style_guide_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LintingServiceRestInterceptor, "pre_get_style_guide_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LintingServiceRestInterceptor, "post_get_style_guide_contents" + ) as post, + mock.patch.object( + transports.LintingServiceRestInterceptor, + "post_get_style_guide_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LintingServiceRestInterceptor, "pre_get_style_guide_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4046,8 +4063,9 @@ def test_lint_spec_rest_bad_request(request_type=linting_service.LintSpecRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4106,13 +4124,13 @@ def test_lint_spec_rest_interceptors(null_interceptor): ) client = LintingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LintingServiceRestInterceptor, "pre_lint_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LintingServiceRestInterceptor, "pre_lint_spec" + ) as pre, + ): pre.assert_not_called() pb_message = linting_service.LintSpecRequest.pb( linting_service.LintSpecRequest() @@ -4157,8 +4175,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4217,8 +4236,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4279,8 +4299,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4341,8 +4362,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4403,8 +4425,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4465,8 +4488,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4667,11 +4691,14 @@ def test_linting_service_base_transport(): def test_linting_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.linting_service.transports.LintingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.linting_service.transports.LintingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LintingServiceTransport( @@ -4688,9 +4715,12 @@ def test_linting_service_base_transport_with_credentials_file(): def test_linting_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.linting_service.transports.LintingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.linting_service.transports.LintingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LintingServiceTransport() @@ -4762,11 +4792,12 @@ def test_linting_service_transport_auth_gdch_credentials(transport_class): def test_linting_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5372,6 +5403,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = LintingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = LintingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = LintingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5511,6 +5574,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = LintingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LintingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = LintingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5656,6 +5751,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = LintingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LintingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = LintingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5801,6 +5930,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = LintingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LintingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = LintingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5946,6 +6109,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = LintingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = LintingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = LintingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6087,6 +6284,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = LintingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = LintingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = LintingServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_provisioning.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_provisioning.py index e715738129bd..7847e19adc33 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_provisioning.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_provisioning.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProvisioningClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ProvisioningClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ProvisioningClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1264,11 +1269,13 @@ def test_provisioning_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3792,8 +3799,9 @@ def test_create_api_hub_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3934,20 +3942,21 @@ def test_create_api_hub_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProvisioningRestInterceptor, "post_create_api_hub_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, - "post_create_api_hub_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_create_api_hub_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_create_api_hub_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, + "post_create_api_hub_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_create_api_hub_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4002,8 +4011,9 @@ def test_delete_api_hub_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4062,20 +4072,21 @@ def test_delete_api_hub_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProvisioningRestInterceptor, "post_delete_api_hub_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, - "post_delete_api_hub_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_delete_api_hub_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_delete_api_hub_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, + "post_delete_api_hub_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_delete_api_hub_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4130,8 +4141,9 @@ def test_get_api_hub_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4202,18 +4214,20 @@ def test_get_api_hub_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProvisioningRestInterceptor, "post_get_api_hub_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, - "post_get_api_hub_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_get_api_hub_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_get_api_hub_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, + "post_get_api_hub_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_get_api_hub_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4268,8 +4282,9 @@ def test_lookup_api_hub_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4331,18 +4346,20 @@ def test_lookup_api_hub_instance_rest_interceptors(null_interceptor): ) client = ProvisioningClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProvisioningRestInterceptor, "post_lookup_api_hub_instance" - ) as post, mock.patch.object( - transports.ProvisioningRestInterceptor, - "post_lookup_api_hub_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProvisioningRestInterceptor, "pre_lookup_api_hub_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProvisioningRestInterceptor, "post_lookup_api_hub_instance" + ) as post, + mock.patch.object( + transports.ProvisioningRestInterceptor, + "post_lookup_api_hub_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProvisioningRestInterceptor, "pre_lookup_api_hub_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4400,8 +4417,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4460,8 +4478,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4522,8 +4541,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4584,8 +4604,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4646,8 +4667,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4708,8 +4730,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4936,11 +4959,14 @@ def test_provisioning_base_transport(): def test_provisioning_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProvisioningTransport( @@ -4957,9 +4983,12 @@ def test_provisioning_base_transport_with_credentials_file(): def test_provisioning_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.provisioning.transports.ProvisioningTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProvisioningTransport() @@ -5031,11 +5060,12 @@ def test_provisioning_transport_auth_gdch_credentials(transport_class): def test_provisioning_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5632,6 +5662,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5771,6 +5833,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5916,6 +6010,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6061,6 +6189,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6206,6 +6368,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6347,6 +6543,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ProvisioningClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ProvisioningAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ProvisioningClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_runtime_project_attachment_service.py b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_runtime_project_attachment_service.py index be3b48285a8d..439ac9d7802c 100644 --- a/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_runtime_project_attachment_service.py +++ b/packages/google-cloud-apihub/tests/unit/gapic/apihub_v1/test_runtime_project_attachment_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( RuntimeProjectAttachmentServiceClient._get_default_mtls_endpoint(None) is None @@ -152,6 +153,12 @@ def test__get_default_mtls_endpoint(): RuntimeProjectAttachmentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RuntimeProjectAttachmentServiceClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1415,11 +1422,13 @@ def test_runtime_project_attachment_service_client_create_channel_credentials_fi ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4981,8 +4990,9 @@ def test_create_runtime_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5129,20 +5139,22 @@ def test_create_runtime_project_attachment_rest_interceptors(null_interceptor): ) client = RuntimeProjectAttachmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_create_runtime_project_attachment", - ) as post, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_create_runtime_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "pre_create_runtime_project_attachment", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_create_runtime_project_attachment", + ) as post, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_create_runtime_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "pre_create_runtime_project_attachment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5208,8 +5220,9 @@ def test_get_runtime_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5280,20 +5293,22 @@ def test_get_runtime_project_attachment_rest_interceptors(null_interceptor): ) client = RuntimeProjectAttachmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_get_runtime_project_attachment", - ) as post, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_get_runtime_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "pre_get_runtime_project_attachment", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_get_runtime_project_attachment", + ) as post, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_get_runtime_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "pre_get_runtime_project_attachment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5359,8 +5374,9 @@ def test_list_runtime_project_attachments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5429,20 +5445,22 @@ def test_list_runtime_project_attachments_rest_interceptors(null_interceptor): ) client = RuntimeProjectAttachmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_list_runtime_project_attachments", - ) as post, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_list_runtime_project_attachments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "pre_list_runtime_project_attachments", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_list_runtime_project_attachments", + ) as post, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_list_runtime_project_attachments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "pre_list_runtime_project_attachments", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5506,8 +5524,9 @@ def test_delete_runtime_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5566,14 +5585,14 @@ def test_delete_runtime_project_attachment_rest_interceptors(null_interceptor): ) client = RuntimeProjectAttachmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "pre_delete_runtime_project_attachment", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "pre_delete_runtime_project_attachment", + ) as pre, + ): pre.assert_not_called() pb_message = runtime_project_attachment_service.DeleteRuntimeProjectAttachmentRequest.pb( runtime_project_attachment_service.DeleteRuntimeProjectAttachmentRequest() @@ -5620,8 +5639,9 @@ def test_lookup_runtime_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5688,20 +5708,22 @@ def test_lookup_runtime_project_attachment_rest_interceptors(null_interceptor): ) client = RuntimeProjectAttachmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_lookup_runtime_project_attachment", - ) as post, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "post_lookup_runtime_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RuntimeProjectAttachmentServiceRestInterceptor, - "pre_lookup_runtime_project_attachment", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_lookup_runtime_project_attachment", + ) as post, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "post_lookup_runtime_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuntimeProjectAttachmentServiceRestInterceptor, + "pre_lookup_runtime_project_attachment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5763,8 +5785,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5823,8 +5846,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5885,8 +5909,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5947,8 +5972,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6009,8 +6035,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6071,8 +6098,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6310,11 +6338,14 @@ def test_runtime_project_attachment_service_base_transport(): def test_runtime_project_attachment_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apihub_v1.services.runtime_project_attachment_service.transports.RuntimeProjectAttachmentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apihub_v1.services.runtime_project_attachment_service.transports.RuntimeProjectAttachmentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RuntimeProjectAttachmentServiceTransport( @@ -6331,9 +6362,12 @@ def test_runtime_project_attachment_service_base_transport_with_credentials_file def test_runtime_project_attachment_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apihub_v1.services.runtime_project_attachment_service.transports.RuntimeProjectAttachmentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apihub_v1.services.runtime_project_attachment_service.transports.RuntimeProjectAttachmentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RuntimeProjectAttachmentServiceTransport() @@ -6412,11 +6446,12 @@ def test_runtime_project_attachment_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7013,6 +7048,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = RuntimeProjectAttachmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = RuntimeProjectAttachmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = RuntimeProjectAttachmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7152,6 +7219,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RuntimeProjectAttachmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RuntimeProjectAttachmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RuntimeProjectAttachmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7297,6 +7396,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RuntimeProjectAttachmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RuntimeProjectAttachmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RuntimeProjectAttachmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7442,6 +7575,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RuntimeProjectAttachmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RuntimeProjectAttachmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = RuntimeProjectAttachmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7587,6 +7754,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = RuntimeProjectAttachmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = RuntimeProjectAttachmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = RuntimeProjectAttachmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7732,6 +7933,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = RuntimeProjectAttachmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = RuntimeProjectAttachmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = RuntimeProjectAttachmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/async_client.py b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/async_client.py index 1016b4cdcbe3..a49e8d1855c8 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/async_client.py +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> CloudApiRegistryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -772,7 +772,7 @@ async def sample_list_mcp_tools(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -798,8 +798,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -808,7 +812,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -816,7 +820,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -827,7 +831,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -853,8 +857,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -863,7 +871,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -871,7 +879,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/client.py b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/client.py index 04b11833fb6a..5abea8fb79e4 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/client.py +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/client.py @@ -114,7 +114,7 @@ class CloudApiRegistryClient(metaclass=CloudApiRegistryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = CloudApiRegistryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1230,7 +1234,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1256,8 +1260,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1266,7 +1274,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1275,7 +1283,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1289,7 +1297,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1315,8 +1323,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1325,7 +1337,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1334,7 +1346,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/README.rst b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/README.rst index 86079e5f79da..a30823e66e29 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/README.rst +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudApiRegistryTransport` is the ABC for all transports. -- public child `CloudApiRegistryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudApiRegistryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudApiRegistryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudApiRegistryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudApiRegistryTransport`` is the ABC for all transports. + +- public child ``CloudApiRegistryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudApiRegistryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudApiRegistryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudApiRegistryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/base.py b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/base.py index 95c5f584ddfc..8fe4a9d5ff29 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/base.py +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc.py b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc.py index 9dbe224634f9..3d592c790efd 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc.py +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc_asyncio.py b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc_asyncio.py index 47fbd4b38298..7c95fa5c6902 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc_asyncio.py +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/rest.py b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/rest.py index bcbd78517896..5f767e16eebb 100644 --- a/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/rest.py +++ b/packages/google-cloud-apiregistry/google/cloud/apiregistry_v1beta/services/cloud_api_registry/transports/rest.py @@ -409,6 +409,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudApiRegistryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apiregistry/noxfile.py b/packages/google-cloud-apiregistry/noxfile.py index 069229636bf1..2d81c85fcb62 100644 --- a/packages/google-cloud-apiregistry/noxfile.py +++ b/packages/google-cloud-apiregistry/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-apiregistry/setup.py b/packages/google-cloud-apiregistry/setup.py index 1c8fa6843163..7be53b6b3b09 100644 --- a/packages/google-cloud-apiregistry/setup.py +++ b/packages/google-cloud-apiregistry/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-apiregistry" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-apiregistry/testing/constraints-3.7.txt b/packages/google-cloud-apiregistry/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-apiregistry/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-apiregistry/testing/constraints-3.8.txt b/packages/google-cloud-apiregistry/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-apiregistry/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-apiregistry/testing/constraints-3.9.txt b/packages/google-cloud-apiregistry/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-apiregistry/testing/constraints-3.9.txt +++ b/packages/google-cloud-apiregistry/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-apiregistry/tests/unit/gapic/apiregistry_v1beta/test_cloud_api_registry.py b/packages/google-cloud-apiregistry/tests/unit/gapic/apiregistry_v1beta/test_cloud_api_registry.py index afaf2ca4afae..ee7f56067b34 100644 --- a/packages/google-cloud-apiregistry/tests/unit/gapic/apiregistry_v1beta/test_cloud_api_registry.py +++ b/packages/google-cloud-apiregistry/tests/unit/gapic/apiregistry_v1beta/test_cloud_api_registry.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudApiRegistryClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): CloudApiRegistryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudApiRegistryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1312,11 +1317,13 @@ def test_cloud_api_registry_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4273,8 +4280,9 @@ def test_get_mcp_server_rest_bad_request(request_type=service.GetMcpServerReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4345,17 +4353,20 @@ def test_get_mcp_server_rest_interceptors(null_interceptor): ) client = CloudApiRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_get_mcp_server" - ) as post, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_get_mcp_server_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "pre_get_mcp_server" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "post_get_mcp_server" + ) as post, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, + "post_get_mcp_server_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "pre_get_mcp_server" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4404,8 +4415,9 @@ def test_list_mcp_servers_rest_bad_request(request_type=service.ListMcpServersRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4470,18 +4482,20 @@ def test_list_mcp_servers_rest_interceptors(null_interceptor): ) client = CloudApiRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_list_mcp_servers" - ) as post, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, - "post_list_mcp_servers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "pre_list_mcp_servers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "post_list_mcp_servers" + ) as post, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, + "post_list_mcp_servers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "pre_list_mcp_servers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4534,8 +4548,9 @@ def test_get_mcp_tool_rest_bad_request(request_type=service.GetMcpToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4606,17 +4621,20 @@ def test_get_mcp_tool_rest_interceptors(null_interceptor): ) client = CloudApiRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_get_mcp_tool" - ) as post, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_get_mcp_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "pre_get_mcp_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "post_get_mcp_tool" + ) as post, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, + "post_get_mcp_tool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "pre_get_mcp_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4665,8 +4683,9 @@ def test_list_mcp_tools_rest_bad_request(request_type=service.ListMcpToolsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4731,17 +4750,20 @@ def test_list_mcp_tools_rest_interceptors(null_interceptor): ) client = CloudApiRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_list_mcp_tools" - ) as post, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "post_list_mcp_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudApiRegistryRestInterceptor, "pre_list_mcp_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "post_list_mcp_tools" + ) as post, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, + "post_list_mcp_tools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudApiRegistryRestInterceptor, "pre_list_mcp_tools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4794,8 +4816,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4854,8 +4877,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5048,11 +5072,14 @@ def test_cloud_api_registry_base_transport(): def test_cloud_api_registry_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apiregistry_v1beta.services.cloud_api_registry.transports.CloudApiRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apiregistry_v1beta.services.cloud_api_registry.transports.CloudApiRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudApiRegistryTransport( @@ -5069,9 +5096,12 @@ def test_cloud_api_registry_base_transport_with_credentials_file(): def test_cloud_api_registry_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apiregistry_v1beta.services.cloud_api_registry.transports.CloudApiRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apiregistry_v1beta.services.cloud_api_registry.transports.CloudApiRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudApiRegistryTransport() @@ -5143,11 +5173,12 @@ def test_cloud_api_registry_transport_auth_gdch_credentials(transport_class): def test_cloud_api_registry_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5764,6 +5795,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudApiRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudApiRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CloudApiRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5905,6 +5970,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CloudApiRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudApiRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CloudApiRegistryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/async_client.py index 2f51c395f087..03897c64d51b 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> ApplicationsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/client.py index 72136a3afc1c..e465dfa98ded 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/client.py @@ -113,7 +113,7 @@ class ApplicationsClient(metaclass=ApplicationsClientMeta): """Manages App Engine applications.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -416,7 +420,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -513,7 +517,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ApplicationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/README.rst index 4889bf686941..940d9e7d0394 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ApplicationsTransport` is the ABC for all transports. -- public child `ApplicationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ApplicationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseApplicationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ApplicationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ApplicationsTransport`` is the ABC for all transports. + +- public child ``ApplicationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ApplicationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseApplicationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ApplicationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/base.py index 42b58a4dd0c2..7116aa74b470 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc.py index 83e2e6661b26..ebcfda1f9eae 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc_asyncio.py index a2995e8361da..61f061808359 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/rest.py index ed43c201899a..aae0f8cdd1ac 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/applications/transports/rest.py @@ -370,6 +370,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ApplicationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/async_client.py index f9cbc59e3738..33aa7ab79b4e 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> AuthorizedCertificatesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/client.py index f3e78b39b64d..5c485ed46faf 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/client.py @@ -114,7 +114,7 @@ class AuthorizedCertificatesClient(metaclass=AuthorizedCertificatesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -616,7 +620,7 @@ def __init__( self._universe_domain = AuthorizedCertificatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/README.rst index c97e75b3796e..7c4dd6ba18f7 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AuthorizedCertificatesTransport` is the ABC for all transports. -- public child `AuthorizedCertificatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AuthorizedCertificatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAuthorizedCertificatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AuthorizedCertificatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AuthorizedCertificatesTransport`` is the ABC for all transports. + +- public child ``AuthorizedCertificatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AuthorizedCertificatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAuthorizedCertificatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AuthorizedCertificatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/base.py index 14f359bf23c6..3a5c58397898 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc.py index f89120186996..34ba66ac9c36 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc_asyncio.py index 0af5c558e76e..19dc9f9d1190 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/rest.py index 81230a5827a8..fd809dec8e8f 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_certificates/transports/rest.py @@ -404,6 +404,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AuthorizedCertificatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/async_client.py index fdaefb63d6e6..7bd342a8159d 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> AuthorizedDomainsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/client.py index ce6aedd58404..80a0f3a015bc 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/client.py @@ -112,7 +112,7 @@ class AuthorizedDomainsClient(metaclass=AuthorizedDomainsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -415,7 +419,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -612,7 +616,7 @@ def __init__( self._universe_domain = AuthorizedDomainsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/README.rst index 0a9888e4c216..d28fc4395000 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AuthorizedDomainsTransport` is the ABC for all transports. -- public child `AuthorizedDomainsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AuthorizedDomainsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAuthorizedDomainsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AuthorizedDomainsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AuthorizedDomainsTransport`` is the ABC for all transports. + +- public child ``AuthorizedDomainsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AuthorizedDomainsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAuthorizedDomainsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AuthorizedDomainsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/base.py index d09dadb0a9bd..a595f79ee9b0 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc.py index c76625483ecf..df5d36348009 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc_asyncio.py index 018c382272bb..2f4e4e1eb814 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/rest.py index d29250992bd6..4a6b856af5de 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/authorized_domains/transports/rest.py @@ -205,6 +205,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AuthorizedDomainsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/async_client.py index 695a0865d581..cd82e09d1d09 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> DomainMappingsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/client.py index e4f946f4e1b2..608be4f1cd1f 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/client.py @@ -114,7 +114,7 @@ class DomainMappingsClient(metaclass=DomainMappingsClientMeta): """Manages domains serving an application.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -514,7 +518,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = DomainMappingsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/README.rst index 788f4b4d49ac..d6884e9f0b48 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DomainMappingsTransport` is the ABC for all transports. -- public child `DomainMappingsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DomainMappingsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDomainMappingsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DomainMappingsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DomainMappingsTransport`` is the ABC for all transports. + +- public child ``DomainMappingsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DomainMappingsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDomainMappingsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DomainMappingsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/base.py index 6035be42c379..d0299424d17d 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc.py index 5094f07f29e3..b0d0f28dfc37 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc_asyncio.py index d8b390ea0fec..155cd335095f 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/rest.py index 5a19d0fb8cf3..5b260cbbfbb5 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/domain_mappings/transports/rest.py @@ -428,6 +428,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DomainMappingsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/async_client.py index 30c155c47cfe..47f48d8e7eaa 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> FirewallTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/client.py index e3a1898d6e24..f5d34eaa3db4 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/client.py @@ -121,7 +121,7 @@ class FirewallClient(metaclass=FirewallClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -424,7 +428,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -521,7 +525,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = FirewallClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/README.rst index c02afbd3e2be..4a773a62cf9f 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirewallTransport` is the ABC for all transports. -- public child `FirewallGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirewallGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirewallRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirewallRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirewallTransport`` is the ABC for all transports. + +- public child ``FirewallGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirewallGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirewallRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirewallRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/base.py index 4117fd4b8c7c..5ee4dd21e0fe 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc.py index 8ac35be68eb6..71575e26de4c 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc_asyncio.py index 4f6e9ac426d7..3b0c99b0badd 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/rest.py index 4a8f900ca0f3..0f7132cbc30e 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/firewall/transports/rest.py @@ -461,6 +461,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirewallRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/async_client.py index b8687acb13cf..c1408bd4af94 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> InstancesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/client.py index 63b71f0b2121..dd8dcf7abbc1 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/client.py @@ -115,7 +115,7 @@ class InstancesClient(metaclass=InstancesClientMeta): """Manages instances of a version.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = InstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/README.rst index 452ca471f507..2834efc80854 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstancesTransport` is the ABC for all transports. -- public child `InstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstancesTransport`` is the ABC for all transports. + +- public child ``InstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/base.py index fd3c50c66890..b8ea5eedc54f 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc.py index 692f0b7ef416..3a73e966dddb 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc_asyncio.py index cb3461fe03a8..ee06672ebfcf 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/rest.py index 80c6efb3cc3c..737bf7af7795 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/instances/transports/rest.py @@ -364,6 +364,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/async_client.py index c4af09d9019a..4dc052b77cb9 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/async_client.py @@ -180,7 +180,7 @@ def transport(self) -> ServicesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/client.py index 48f17675d6a0..73268ed2eb72 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/client.py @@ -114,7 +114,7 @@ class ServicesClient(metaclass=ServicesClientMeta): """Manages services of an application.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -514,7 +518,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = ServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/README.rst index ac1c48dcd4e6..404631fa9895 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServicesTransport` is the ABC for all transports. -- public child `ServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServicesTransport`` is the ABC for all transports. + +- public child ``ServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/base.py index e1e560d131af..2734b02b8c40 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc.py index fb326a494a35..a63be0ab1961 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc_asyncio.py index e1e96c558e77..73d623c2262a 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/rest.py index 9b02f4edff39..eba8a6c033dd 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/services/transports/rest.py @@ -360,6 +360,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/async_client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/async_client.py index e877a1d89347..e510a479e80b 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/async_client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/async_client.py @@ -182,7 +182,7 @@ def transport(self) -> VersionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/client.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/client.py index a27269e84cc8..32604d284fda 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/client.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/client.py @@ -116,7 +116,7 @@ class VersionsClient(metaclass=VersionsClientMeta): """Manages versions of a service.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -419,7 +423,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -612,7 +616,7 @@ def __init__( self._universe_domain = VersionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/README.rst b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/README.rst index ac30fdf3d846..f820acfcbfa3 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/README.rst +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VersionsTransport` is the ABC for all transports. -- public child `VersionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VersionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVersionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VersionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VersionsTransport`` is the ABC for all transports. + +- public child ``VersionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VersionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVersionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VersionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/base.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/base.py index 28c3046bf5ac..8b41166837e9 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/base.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc.py index 4afb2cfe3e0e..3827b011dccc 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc_asyncio.py index 92da4c13961e..3bda6fad7032 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/rest.py b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/rest.py index c234841ba071..05f527a5ae33 100644 --- a/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/rest.py +++ b/packages/google-cloud-appengine-admin/google/cloud/appengine_admin_v1/services/versions/transports/rest.py @@ -414,6 +414,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VersionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-appengine-admin/noxfile.py b/packages/google-cloud-appengine-admin/noxfile.py index d199bcafa5b5..af9d5ff18b22 100644 --- a/packages/google-cloud-appengine-admin/noxfile.py +++ b/packages/google-cloud-appengine-admin/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-appengine-admin/setup.py b/packages/google-cloud-appengine-admin/setup.py index bbcf4ddd9b76..abe4466b15a3 100644 --- a/packages/google-cloud-appengine-admin/setup.py +++ b/packages/google-cloud-appengine-admin/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-appengine-admin" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-appengine-admin/testing/constraints-3.7.txt b/packages/google-cloud-appengine-admin/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-appengine-admin/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-appengine-admin/testing/constraints-3.8.txt b/packages/google-cloud-appengine-admin/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-appengine-admin/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-appengine-admin/testing/constraints-3.9.txt b/packages/google-cloud-appengine-admin/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-appengine-admin/testing/constraints-3.9.txt +++ b/packages/google-cloud-appengine-admin/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_applications.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_applications.py index 172419108c10..2f15206cbc0b 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_applications.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_applications.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ApplicationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ApplicationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ApplicationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1264,11 +1269,13 @@ def test_applications_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2937,8 +2944,9 @@ def test_get_application_rest_bad_request(request_type=appengine.GetApplicationR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3023,17 +3031,19 @@ def test_get_application_rest_interceptors(null_interceptor): ) client = ApplicationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ApplicationsRestInterceptor, "post_get_application" - ) as post, mock.patch.object( - transports.ApplicationsRestInterceptor, "post_get_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApplicationsRestInterceptor, "pre_get_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ApplicationsRestInterceptor, "post_get_application" + ) as post, + mock.patch.object( + transports.ApplicationsRestInterceptor, "post_get_application_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ApplicationsRestInterceptor, "pre_get_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3086,8 +3096,9 @@ def test_create_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3238,19 +3249,21 @@ def test_create_application_rest_interceptors(null_interceptor): ) client = ApplicationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApplicationsRestInterceptor, "post_create_application" - ) as post, mock.patch.object( - transports.ApplicationsRestInterceptor, "post_create_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApplicationsRestInterceptor, "pre_create_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApplicationsRestInterceptor, "post_create_application" + ) as post, + mock.patch.object( + transports.ApplicationsRestInterceptor, + "post_create_application_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApplicationsRestInterceptor, "pre_create_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3303,8 +3316,9 @@ def test_update_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3455,19 +3469,21 @@ def test_update_application_rest_interceptors(null_interceptor): ) client = ApplicationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApplicationsRestInterceptor, "post_update_application" - ) as post, mock.patch.object( - transports.ApplicationsRestInterceptor, "post_update_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApplicationsRestInterceptor, "pre_update_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApplicationsRestInterceptor, "post_update_application" + ) as post, + mock.patch.object( + transports.ApplicationsRestInterceptor, + "post_update_application_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApplicationsRestInterceptor, "pre_update_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3520,8 +3536,9 @@ def test_repair_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3578,19 +3595,21 @@ def test_repair_application_rest_interceptors(null_interceptor): ) client = ApplicationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ApplicationsRestInterceptor, "post_repair_application" - ) as post, mock.patch.object( - transports.ApplicationsRestInterceptor, "post_repair_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ApplicationsRestInterceptor, "pre_repair_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ApplicationsRestInterceptor, "post_repair_application" + ) as post, + mock.patch.object( + transports.ApplicationsRestInterceptor, + "post_repair_application_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ApplicationsRestInterceptor, "pre_repair_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3803,11 +3822,14 @@ def test_applications_base_transport(): def test_applications_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.applications.transports.ApplicationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.applications.transports.ApplicationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApplicationsTransport( @@ -3828,9 +3850,12 @@ def test_applications_base_transport_with_credentials_file(): def test_applications_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.applications.transports.ApplicationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.applications.transports.ApplicationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ApplicationsTransport() @@ -3910,11 +3935,12 @@ def test_applications_transport_auth_gdch_credentials(transport_class): def test_applications_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_certificates.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_certificates.py index ddbdc84e58ce..2b74bd6c38df 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_certificates.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_certificates.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AuthorizedCertificatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): AuthorizedCertificatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AuthorizedCertificatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1346,11 +1351,13 @@ def test_authorized_certificates_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3594,8 +3601,9 @@ def test_list_authorized_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3658,20 +3666,22 @@ def test_list_authorized_certificates_rest_interceptors(null_interceptor): ) client = AuthorizedCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_list_authorized_certificates", - ) as post, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_list_authorized_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "pre_list_authorized_certificates", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_list_authorized_certificates", + ) as post, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_list_authorized_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "pre_list_authorized_certificates", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3729,8 +3739,9 @@ def test_get_authorized_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3803,20 +3814,22 @@ def test_get_authorized_certificate_rest_interceptors(null_interceptor): ) client = AuthorizedCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_get_authorized_certificate", - ) as post, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_get_authorized_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "pre_get_authorized_certificate", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_get_authorized_certificate", + ) as post, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_get_authorized_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "pre_get_authorized_certificate", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3871,8 +3884,9 @@ def test_create_authorized_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4029,20 +4043,22 @@ def test_create_authorized_certificate_rest_interceptors(null_interceptor): ) client = AuthorizedCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_create_authorized_certificate", - ) as post, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_create_authorized_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "pre_create_authorized_certificate", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_create_authorized_certificate", + ) as post, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_create_authorized_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "pre_create_authorized_certificate", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4097,8 +4113,9 @@ def test_update_authorized_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4255,20 +4272,22 @@ def test_update_authorized_certificate_rest_interceptors(null_interceptor): ) client = AuthorizedCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_update_authorized_certificate", - ) as post, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "post_update_authorized_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "pre_update_authorized_certificate", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_update_authorized_certificate", + ) as post, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "post_update_authorized_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "pre_update_authorized_certificate", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4323,8 +4342,9 @@ def test_delete_authorized_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4381,14 +4401,14 @@ def test_delete_authorized_certificate_rest_interceptors(null_interceptor): ) client = AuthorizedCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuthorizedCertificatesRestInterceptor, - "pre_delete_authorized_certificate", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuthorizedCertificatesRestInterceptor, + "pre_delete_authorized_certificate", + ) as pre, + ): pre.assert_not_called() pb_message = appengine.DeleteAuthorizedCertificateRequest.pb( appengine.DeleteAuthorizedCertificateRequest() @@ -4596,11 +4616,14 @@ def test_authorized_certificates_base_transport(): def test_authorized_certificates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.authorized_certificates.transports.AuthorizedCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.authorized_certificates.transports.AuthorizedCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuthorizedCertificatesTransport( @@ -4621,9 +4644,12 @@ def test_authorized_certificates_base_transport_with_credentials_file(): def test_authorized_certificates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.authorized_certificates.transports.AuthorizedCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.authorized_certificates.transports.AuthorizedCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuthorizedCertificatesTransport() @@ -4705,11 +4731,12 @@ def test_authorized_certificates_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_domains.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_domains.py index c13e9d1ea087..b81019fd88da 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_domains.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_authorized_domains.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AuthorizedDomainsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): AuthorizedDomainsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AuthorizedDomainsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1318,11 +1323,13 @@ def test_authorized_domains_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2102,8 +2109,9 @@ def test_list_authorized_domains_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2166,18 +2174,20 @@ def test_list_authorized_domains_rest_interceptors(null_interceptor): ) client = AuthorizedDomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuthorizedDomainsRestInterceptor, "post_list_authorized_domains" - ) as post, mock.patch.object( - transports.AuthorizedDomainsRestInterceptor, - "post_list_authorized_domains_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuthorizedDomainsRestInterceptor, "pre_list_authorized_domains" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuthorizedDomainsRestInterceptor, "post_list_authorized_domains" + ) as post, + mock.patch.object( + transports.AuthorizedDomainsRestInterceptor, + "post_list_authorized_domains_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuthorizedDomainsRestInterceptor, "pre_list_authorized_domains" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2304,11 +2314,14 @@ def test_authorized_domains_base_transport(): def test_authorized_domains_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.authorized_domains.transports.AuthorizedDomainsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.authorized_domains.transports.AuthorizedDomainsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuthorizedDomainsTransport( @@ -2329,9 +2342,12 @@ def test_authorized_domains_base_transport_with_credentials_file(): def test_authorized_domains_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.authorized_domains.transports.AuthorizedDomainsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.authorized_domains.transports.AuthorizedDomainsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuthorizedDomainsTransport() @@ -2411,11 +2427,12 @@ def test_authorized_domains_transport_auth_gdch_credentials(transport_class): def test_authorized_domains_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_domain_mappings.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_domain_mappings.py index 645c0ded6cde..84750f0fdb62 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_domain_mappings.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_domain_mappings.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DomainMappingsClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): assert ( DomainMappingsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DomainMappingsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1288,11 +1293,13 @@ def test_domain_mappings_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3487,8 +3494,9 @@ def test_list_domain_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3551,18 +3559,20 @@ def test_list_domain_mappings_rest_interceptors(null_interceptor): ) client = DomainMappingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainMappingsRestInterceptor, "post_list_domain_mappings" - ) as post, mock.patch.object( - transports.DomainMappingsRestInterceptor, - "post_list_domain_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainMappingsRestInterceptor, "pre_list_domain_mappings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "post_list_domain_mappings" + ) as post, + mock.patch.object( + transports.DomainMappingsRestInterceptor, + "post_list_domain_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "pre_list_domain_mappings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3620,8 +3630,9 @@ def test_get_domain_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3686,18 +3697,20 @@ def test_get_domain_mapping_rest_interceptors(null_interceptor): ) client = DomainMappingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainMappingsRestInterceptor, "post_get_domain_mapping" - ) as post, mock.patch.object( - transports.DomainMappingsRestInterceptor, - "post_get_domain_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainMappingsRestInterceptor, "pre_get_domain_mapping" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "post_get_domain_mapping" + ) as post, + mock.patch.object( + transports.DomainMappingsRestInterceptor, + "post_get_domain_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "pre_get_domain_mapping" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3752,8 +3765,9 @@ def test_create_domain_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3889,20 +3903,21 @@ def test_create_domain_mapping_rest_interceptors(null_interceptor): ) client = DomainMappingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainMappingsRestInterceptor, "post_create_domain_mapping" - ) as post, mock.patch.object( - transports.DomainMappingsRestInterceptor, - "post_create_domain_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainMappingsRestInterceptor, "pre_create_domain_mapping" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainMappingsRestInterceptor, "post_create_domain_mapping" + ) as post, + mock.patch.object( + transports.DomainMappingsRestInterceptor, + "post_create_domain_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "pre_create_domain_mapping" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3955,8 +3970,9 @@ def test_update_domain_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4092,20 +4108,21 @@ def test_update_domain_mapping_rest_interceptors(null_interceptor): ) client = DomainMappingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainMappingsRestInterceptor, "post_update_domain_mapping" - ) as post, mock.patch.object( - transports.DomainMappingsRestInterceptor, - "post_update_domain_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainMappingsRestInterceptor, "pre_update_domain_mapping" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainMappingsRestInterceptor, "post_update_domain_mapping" + ) as post, + mock.patch.object( + transports.DomainMappingsRestInterceptor, + "post_update_domain_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "pre_update_domain_mapping" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4158,8 +4175,9 @@ def test_delete_domain_mapping_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4216,20 +4234,21 @@ def test_delete_domain_mapping_rest_interceptors(null_interceptor): ) client = DomainMappingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainMappingsRestInterceptor, "post_delete_domain_mapping" - ) as post, mock.patch.object( - transports.DomainMappingsRestInterceptor, - "post_delete_domain_mapping_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainMappingsRestInterceptor, "pre_delete_domain_mapping" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainMappingsRestInterceptor, "post_delete_domain_mapping" + ) as post, + mock.patch.object( + transports.DomainMappingsRestInterceptor, + "post_delete_domain_mapping_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainMappingsRestInterceptor, "pre_delete_domain_mapping" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4467,11 +4486,14 @@ def test_domain_mappings_base_transport(): def test_domain_mappings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.domain_mappings.transports.DomainMappingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.domain_mappings.transports.DomainMappingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DomainMappingsTransport( @@ -4492,9 +4514,12 @@ def test_domain_mappings_base_transport_with_credentials_file(): def test_domain_mappings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.domain_mappings.transports.DomainMappingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.domain_mappings.transports.DomainMappingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DomainMappingsTransport() @@ -4574,11 +4599,12 @@ def test_domain_mappings_transport_auth_gdch_credentials(transport_class): def test_domain_mappings_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_firewall.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_firewall.py index 4980c60faf50..11f04e55981c 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_firewall.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_firewall.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirewallClient._get_default_mtls_endpoint(None) is None assert FirewallClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FirewallClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert FirewallClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1225,11 +1227,13 @@ def test_firewall_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3752,8 +3756,9 @@ def test_list_ingress_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3814,17 +3819,19 @@ def test_list_ingress_rules_rest_interceptors(null_interceptor): ) client = FirewallClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallRestInterceptor, "post_list_ingress_rules" - ) as post, mock.patch.object( - transports.FirewallRestInterceptor, "post_list_ingress_rules_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallRestInterceptor, "pre_list_ingress_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallRestInterceptor, "post_list_ingress_rules" + ) as post, + mock.patch.object( + transports.FirewallRestInterceptor, "post_list_ingress_rules_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallRestInterceptor, "pre_list_ingress_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3879,8 +3886,9 @@ def test_batch_update_ingress_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3938,18 +3946,20 @@ def test_batch_update_ingress_rules_rest_interceptors(null_interceptor): ) client = FirewallClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallRestInterceptor, "post_batch_update_ingress_rules" - ) as post, mock.patch.object( - transports.FirewallRestInterceptor, - "post_batch_update_ingress_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallRestInterceptor, "pre_batch_update_ingress_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallRestInterceptor, "post_batch_update_ingress_rules" + ) as post, + mock.patch.object( + transports.FirewallRestInterceptor, + "post_batch_update_ingress_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallRestInterceptor, "pre_batch_update_ingress_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4007,8 +4017,9 @@ def test_create_ingress_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4148,17 +4159,19 @@ def test_create_ingress_rule_rest_interceptors(null_interceptor): ) client = FirewallClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallRestInterceptor, "post_create_ingress_rule" - ) as post, mock.patch.object( - transports.FirewallRestInterceptor, "post_create_ingress_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallRestInterceptor, "pre_create_ingress_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallRestInterceptor, "post_create_ingress_rule" + ) as post, + mock.patch.object( + transports.FirewallRestInterceptor, "post_create_ingress_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallRestInterceptor, "pre_create_ingress_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4211,8 +4224,9 @@ def test_get_ingress_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4279,17 +4293,19 @@ def test_get_ingress_rule_rest_interceptors(null_interceptor): ) client = FirewallClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallRestInterceptor, "post_get_ingress_rule" - ) as post, mock.patch.object( - transports.FirewallRestInterceptor, "post_get_ingress_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallRestInterceptor, "pre_get_ingress_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallRestInterceptor, "post_get_ingress_rule" + ) as post, + mock.patch.object( + transports.FirewallRestInterceptor, "post_get_ingress_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallRestInterceptor, "pre_get_ingress_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4342,8 +4358,9 @@ def test_update_ingress_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4483,17 +4500,19 @@ def test_update_ingress_rule_rest_interceptors(null_interceptor): ) client = FirewallClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallRestInterceptor, "post_update_ingress_rule" - ) as post, mock.patch.object( - transports.FirewallRestInterceptor, "post_update_ingress_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallRestInterceptor, "pre_update_ingress_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallRestInterceptor, "post_update_ingress_rule" + ) as post, + mock.patch.object( + transports.FirewallRestInterceptor, "post_update_ingress_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallRestInterceptor, "pre_update_ingress_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4546,8 +4565,9 @@ def test_delete_ingress_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4602,13 +4622,13 @@ def test_delete_ingress_rule_rest_interceptors(null_interceptor): ) client = FirewallClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallRestInterceptor, "pre_delete_ingress_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallRestInterceptor, "pre_delete_ingress_rule" + ) as pre, + ): pre.assert_not_called() pb_message = appengine.DeleteIngressRuleRequest.pb( appengine.DeleteIngressRuleRequest() @@ -4837,11 +4857,14 @@ def test_firewall_base_transport(): def test_firewall_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.firewall.transports.FirewallTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.firewall.transports.FirewallTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallTransport( @@ -4862,9 +4885,12 @@ def test_firewall_base_transport_with_credentials_file(): def test_firewall_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.firewall.transports.FirewallTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.firewall.transports.FirewallTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallTransport() @@ -4944,11 +4970,12 @@ def test_firewall_transport_auth_gdch_credentials(transport_class): def test_firewall_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_instances.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_instances.py index fbec93a09895..8fa5ddcf6b9e 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_instances.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_instances.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstancesClient._get_default_mtls_endpoint(None) is None assert InstancesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -143,6 +144,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert InstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + InstancesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_instances_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3053,8 +3059,9 @@ def test_list_instances_rest_bad_request(request_type=appengine.ListInstancesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3115,17 +3122,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3178,8 +3187,9 @@ def test_get_instance_rest_bad_request(request_type=appengine.GetInstanceRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3272,17 +3282,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3333,8 +3345,9 @@ def test_delete_instance_rest_bad_request(request_type=appengine.DeleteInstanceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3391,19 +3404,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3456,8 +3470,9 @@ def test_debug_instance_rest_bad_request(request_type=appengine.DebugInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3514,19 +3529,20 @@ def test_debug_instance_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.InstancesRestInterceptor, "post_debug_instance" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_debug_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_debug_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.InstancesRestInterceptor, "post_debug_instance" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_debug_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_debug_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3731,11 +3747,14 @@ def test_instances_base_transport(): def test_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstancesTransport( @@ -3756,9 +3775,12 @@ def test_instances_base_transport_with_credentials_file(): def test_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstancesTransport() @@ -3838,11 +3860,12 @@ def test_instances_transport_auth_gdch_credentials(transport_class): def test_instances_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_services.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_services.py index 36446cb082f5..ff93fef99012 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_services.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_services.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServicesClient._get_default_mtls_endpoint(None) is None assert ServicesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -143,6 +144,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ServicesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1232,11 +1234,13 @@ def test_services_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2970,8 +2974,9 @@ def test_list_services_rest_bad_request(request_type=appengine.ListServicesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3032,17 +3037,19 @@ def test_list_services_rest_interceptors(null_interceptor): ) client = ServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServicesRestInterceptor, "post_list_services" - ) as post, mock.patch.object( - transports.ServicesRestInterceptor, "post_list_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServicesRestInterceptor, "pre_list_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServicesRestInterceptor, "post_list_services" + ) as post, + mock.patch.object( + transports.ServicesRestInterceptor, "post_list_services_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServicesRestInterceptor, "pre_list_services" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3093,8 +3100,9 @@ def test_get_service_rest_bad_request(request_type=appengine.GetServiceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3157,17 +3165,17 @@ def test_get_service_rest_interceptors(null_interceptor): ) client = ServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServicesRestInterceptor, "post_get_service" - ) as post, mock.patch.object( - transports.ServicesRestInterceptor, "post_get_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServicesRestInterceptor, "pre_get_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServicesRestInterceptor, "post_get_service" + ) as post, + mock.patch.object( + transports.ServicesRestInterceptor, "post_get_service_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ServicesRestInterceptor, "pre_get_service") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3216,8 +3224,9 @@ def test_update_service_rest_bad_request(request_type=appengine.UpdateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3346,19 +3355,20 @@ def test_update_service_rest_interceptors(null_interceptor): ) client = ServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ServicesRestInterceptor, "post_update_service" - ) as post, mock.patch.object( - transports.ServicesRestInterceptor, "post_update_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServicesRestInterceptor, "pre_update_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ServicesRestInterceptor, "post_update_service" + ) as post, + mock.patch.object( + transports.ServicesRestInterceptor, "post_update_service_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServicesRestInterceptor, "pre_update_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3407,8 +3417,9 @@ def test_delete_service_rest_bad_request(request_type=appengine.DeleteServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3463,19 +3474,20 @@ def test_delete_service_rest_interceptors(null_interceptor): ) client = ServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ServicesRestInterceptor, "post_delete_service" - ) as post, mock.patch.object( - transports.ServicesRestInterceptor, "post_delete_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServicesRestInterceptor, "pre_delete_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ServicesRestInterceptor, "post_delete_service" + ) as post, + mock.patch.object( + transports.ServicesRestInterceptor, "post_delete_service_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServicesRestInterceptor, "pre_delete_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3680,11 +3692,14 @@ def test_services_base_transport(): def test_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.services.transports.ServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.services.transports.ServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServicesTransport( @@ -3705,9 +3720,12 @@ def test_services_base_transport_with_credentials_file(): def test_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.services.transports.ServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.services.transports.ServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServicesTransport() @@ -3787,11 +3805,12 @@ def test_services_transport_auth_gdch_credentials(transport_class): def test_services_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_versions.py b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_versions.py index 8d4706935f52..c03e23c812a2 100644 --- a/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_versions.py +++ b/packages/google-cloud-appengine-admin/tests/unit/gapic/appengine_admin_v1/test_versions.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VersionsClient._get_default_mtls_endpoint(None) is None assert VersionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -145,6 +146,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert VersionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1234,11 +1236,13 @@ def test_versions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3392,8 +3396,9 @@ def test_list_versions_rest_bad_request(request_type=appengine.ListVersionsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3454,17 +3459,19 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3515,8 +3522,9 @@ def test_get_version_rest_bad_request(request_type=appengine.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3615,17 +3623,17 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VersionsRestInterceptor, "pre_get_version") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3674,8 +3682,9 @@ def test_create_version_rest_bad_request(request_type=appengine.CreateVersionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3960,19 +3969,20 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4021,8 +4031,9 @@ def test_update_version_rest_bad_request(request_type=appengine.UpdateVersionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4307,19 +4318,20 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4368,8 +4380,9 @@ def test_delete_version_rest_bad_request(request_type=appengine.DeleteVersionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4424,19 +4437,20 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_delete_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_delete_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_delete_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_delete_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4662,11 +4676,14 @@ def test_versions_base_transport(): def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.appengine_admin_v1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.appengine_admin_v1.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport( @@ -4687,9 +4704,12 @@ def test_versions_base_transport_with_credentials_file(): def test_versions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.appengine_admin_v1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.appengine_admin_v1.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport() @@ -4769,11 +4789,12 @@ def test_versions_transport_auth_gdch_credentials(transport_class): def test_versions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-appengine-logging/noxfile.py b/packages/google-cloud-appengine-logging/noxfile.py index 908ab6a63234..a5ea0f6fa493 100644 --- a/packages/google-cloud-appengine-logging/noxfile.py +++ b/packages/google-cloud-appengine-logging/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-appengine-logging/setup.py b/packages/google-cloud-appengine-logging/setup.py index e05462c39d07..158bec81f8d9 100644 --- a/packages/google-cloud-appengine-logging/setup.py +++ b/packages/google-cloud-appengine-logging/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-appengine-logging" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-appengine-logging/testing/constraints-3.7.txt b/packages/google-cloud-appengine-logging/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-appengine-logging/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-appengine-logging/testing/constraints-3.8.txt b/packages/google-cloud-appengine-logging/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-appengine-logging/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-appengine-logging/testing/constraints-3.9.txt b/packages/google-cloud-appengine-logging/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-appengine-logging/testing/constraints-3.9.txt +++ b/packages/google-cloud-appengine-logging/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/async_client.py b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/async_client.py index 389c94590ce3..b33c24f31eca 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/async_client.py +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/async_client.py @@ -218,7 +218,7 @@ def transport(self) -> AppHubTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3897,7 +3897,7 @@ async def sample_delete_application(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3923,8 +3923,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3933,7 +3937,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3941,7 +3945,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3952,7 +3956,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3978,8 +3982,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3988,7 +3996,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3996,7 +4004,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4007,7 +4015,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4037,8 +4045,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4047,7 +4059,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4055,7 +4067,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4063,7 +4075,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4092,8 +4104,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4102,7 +4118,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4110,7 +4126,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4118,7 +4134,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4210,8 +4226,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4220,7 +4240,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4228,7 +4250,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4239,7 +4261,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4332,8 +4354,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4342,7 +4368,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4350,7 +4378,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4361,7 +4389,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4392,8 +4420,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4404,7 +4436,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4412,7 +4446,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4423,7 +4457,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4449,8 +4483,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4459,7 +4497,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4467,7 +4505,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4478,7 +4516,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4504,8 +4542,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4514,7 +4556,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4522,7 +4564,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/client.py b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/client.py index f944bcabf1d4..bd298924471c 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/client.py +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/client.py @@ -134,7 +134,7 @@ class AppHubClient(metaclass=AppHubClientMeta): """The App Hub API allows you to manage App Hub resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -142,7 +142,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -152,6 +152,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -575,7 +579,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -672,7 +676,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -768,7 +772,7 @@ def __init__( self._universe_domain = AppHubClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4382,7 +4386,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4408,8 +4412,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4418,7 +4426,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4427,7 +4435,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4441,7 +4449,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4467,8 +4475,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4477,7 +4489,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4486,7 +4498,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4500,7 +4512,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4530,8 +4542,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4540,7 +4556,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4548,7 +4564,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4556,7 +4572,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4585,8 +4601,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4595,7 +4615,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4603,7 +4623,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4611,7 +4631,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4703,8 +4723,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4713,7 +4737,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4722,7 +4748,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4736,7 +4762,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4829,8 +4855,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4839,7 +4869,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4848,7 +4880,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4862,7 +4894,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4893,8 +4925,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4903,7 +4939,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4912,7 +4950,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4926,7 +4964,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4952,8 +4990,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4962,7 +5004,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4971,7 +5013,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4985,7 +5027,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5011,8 +5053,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5021,7 +5067,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5030,7 +5076,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/README.rst b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/README.rst index 33e37f466150..884f5d2a436c 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/README.rst +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AppHubTransport` is the ABC for all transports. -- public child `AppHubGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AppHubGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAppHubRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AppHubRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AppHubTransport`` is the ABC for all transports. + +- public child ``AppHubGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AppHubGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAppHubRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AppHubRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/base.py b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/base.py index d5e1ddf41aeb..6b0ae0b42b7a 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/base.py +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/base.py @@ -92,6 +92,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -141,6 +145,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc.py b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc.py index 1aeb0ef16606..452b18f71eb9 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc.py +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc.py @@ -66,7 +66,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc_asyncio.py b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc_asyncio.py index eb7d73610ee6..309b816f6d28 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc_asyncio.py +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/grpc_asyncio.py @@ -72,7 +72,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -107,7 +107,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/rest.py b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/rest.py index 2db7a0a84cde..2f31ba96893c 100644 --- a/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/rest.py +++ b/packages/google-cloud-apphub/google/cloud/apphub_v1/services/app_hub/transports/rest.py @@ -1925,6 +1925,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AppHubRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-apphub/noxfile.py b/packages/google-cloud-apphub/noxfile.py index 48380ec8844d..fae821368c3a 100644 --- a/packages/google-cloud-apphub/noxfile.py +++ b/packages/google-cloud-apphub/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-apphub/setup.py b/packages/google-cloud-apphub/setup.py index 6e9f9bb9ce88..f214db3886b0 100644 --- a/packages/google-cloud-apphub/setup.py +++ b/packages/google-cloud-apphub/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-apphub/testing/constraints-3.7.txt b/packages/google-cloud-apphub/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-apphub/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-apphub/testing/constraints-3.8.txt b/packages/google-cloud-apphub/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-apphub/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-apphub/testing/constraints-3.9.txt b/packages/google-cloud-apphub/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-apphub/testing/constraints-3.9.txt +++ b/packages/google-cloud-apphub/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-apphub/tests/unit/gapic/apphub_v1/test_app_hub.py b/packages/google-cloud-apphub/tests/unit/gapic/apphub_v1/test_app_hub.py index 145e0d989fd0..fcaf5f5ac9d9 100644 --- a/packages/google-cloud-apphub/tests/unit/gapic/apphub_v1/test_app_hub.py +++ b/packages/google-cloud-apphub/tests/unit/gapic/apphub_v1/test_app_hub.py @@ -146,6 +146,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AppHubClient._get_default_mtls_endpoint(None) is None assert AppHubClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -161,6 +162,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AppHubClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AppHubClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1239,11 +1241,13 @@ def test_app_hub_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -19050,8 +19054,9 @@ def test_lookup_service_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19111,18 +19116,20 @@ def test_lookup_service_project_attachment_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_lookup_service_project_attachment" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_lookup_service_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_lookup_service_project_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_lookup_service_project_attachment" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_lookup_service_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_lookup_service_project_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19180,8 +19187,9 @@ def test_list_service_project_attachments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19246,18 +19254,20 @@ def test_list_service_project_attachments_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_service_project_attachments" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_list_service_project_attachments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_list_service_project_attachments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_service_project_attachments" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_list_service_project_attachments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_list_service_project_attachments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19315,8 +19325,9 @@ def test_create_service_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19451,20 +19462,21 @@ def test_create_service_project_attachment_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_create_service_project_attachment" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_create_service_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_create_service_project_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_service_project_attachment" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_create_service_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_create_service_project_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19519,8 +19531,9 @@ def test_get_service_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19594,18 +19607,20 @@ def test_get_service_project_attachment_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_service_project_attachment" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_get_service_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_get_service_project_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_service_project_attachment" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_get_service_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_get_service_project_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19665,8 +19680,9 @@ def test_delete_service_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19723,20 +19739,21 @@ def test_delete_service_project_attachment_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_service_project_attachment" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_delete_service_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_delete_service_project_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_service_project_attachment" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_delete_service_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_delete_service_project_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19789,8 +19806,9 @@ def test_detach_service_project_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19850,18 +19868,20 @@ def test_detach_service_project_attachment_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_detach_service_project_attachment" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_detach_service_project_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_detach_service_project_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_detach_service_project_attachment" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_detach_service_project_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_detach_service_project_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19919,8 +19939,9 @@ def test_list_discovered_services_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19983,17 +20004,20 @@ def test_list_discovered_services_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_discovered_services" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_discovered_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_list_discovered_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_discovered_services" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_list_discovered_services_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_list_discovered_services" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20053,8 +20077,9 @@ def test_get_discovered_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20117,17 +20142,20 @@ def test_get_discovered_service_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_discovered_service" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_discovered_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_get_discovered_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_discovered_service" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_get_discovered_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_get_discovered_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20180,8 +20208,9 @@ def test_lookup_discovered_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20239,17 +20268,20 @@ def test_lookup_discovered_service_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_lookup_discovered_service" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_lookup_discovered_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_lookup_discovered_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_lookup_discovered_service" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_lookup_discovered_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_lookup_discovered_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20307,8 +20339,9 @@ def test_list_services_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20371,17 +20404,17 @@ def test_list_services_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_services" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_list_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_services" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_services_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AppHubRestInterceptor, "pre_list_services") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20439,8 +20472,9 @@ def test_create_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20587,19 +20621,20 @@ def test_create_service_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_create_service" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_create_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_create_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_service" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_service_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_create_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20652,8 +20687,9 @@ def test_get_service_rest_bad_request(request_type=apphub_service.GetServiceRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20726,17 +20762,15 @@ def test_get_service_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_service" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_get_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AppHubRestInterceptor, "post_get_service") as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_service_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AppHubRestInterceptor, "pre_get_service") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20793,8 +20827,9 @@ def test_update_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20945,19 +20980,20 @@ def test_update_service_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_update_service" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_update_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_update_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_update_service" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_update_service_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_update_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21012,8 +21048,9 @@ def test_delete_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21070,19 +21107,20 @@ def test_delete_service_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_service" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_delete_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_service" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_service_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_delete_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21135,8 +21173,9 @@ def test_list_discovered_workloads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21199,17 +21238,20 @@ def test_list_discovered_workloads_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_discovered_workloads" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_discovered_workloads_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_list_discovered_workloads" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_discovered_workloads" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_list_discovered_workloads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_list_discovered_workloads" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21269,8 +21311,9 @@ def test_get_discovered_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21333,17 +21376,20 @@ def test_get_discovered_workload_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_discovered_workload" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_discovered_workload_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_get_discovered_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_discovered_workload" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_get_discovered_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_get_discovered_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21398,8 +21444,9 @@ def test_lookup_discovered_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21457,18 +21504,20 @@ def test_lookup_discovered_workload_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_lookup_discovered_workload" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, - "post_lookup_discovered_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_lookup_discovered_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_lookup_discovered_workload" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, + "post_lookup_discovered_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_lookup_discovered_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21526,8 +21575,9 @@ def test_list_workloads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21590,17 +21640,19 @@ def test_list_workloads_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_workloads" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_workloads_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_list_workloads" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_workloads" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_workloads_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_list_workloads" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21658,8 +21710,9 @@ def test_create_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21806,19 +21859,20 @@ def test_create_workload_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_create_workload" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_create_workload_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_create_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_workload" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_workload_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_create_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21871,8 +21925,9 @@ def test_get_workload_rest_bad_request(request_type=apphub_service.GetWorkloadRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21945,17 +22000,17 @@ def test_get_workload_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_workload" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_workload_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_get_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_workload" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_workload_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AppHubRestInterceptor, "pre_get_workload") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22012,8 +22067,9 @@ def test_update_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22164,19 +22220,20 @@ def test_update_workload_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_update_workload" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_update_workload_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_update_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_update_workload" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_update_workload_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_update_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22231,8 +22288,9 @@ def test_delete_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22289,19 +22347,20 @@ def test_delete_workload_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_workload" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_workload_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_delete_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_workload" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_workload_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_delete_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22354,8 +22413,9 @@ def test_list_applications_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22418,17 +22478,19 @@ def test_list_applications_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_applications" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_list_applications_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_list_applications" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_applications" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_list_applications_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_list_applications" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22486,8 +22548,9 @@ def test_create_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22628,19 +22691,20 @@ def test_create_application_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_create_application" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_create_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_create_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_application" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_create_application_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_create_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22693,8 +22757,9 @@ def test_get_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22763,17 +22828,19 @@ def test_get_application_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_application" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_get_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_get_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_application" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_get_application_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_get_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22830,8 +22897,9 @@ def test_update_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22976,19 +23044,20 @@ def test_update_application_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_update_application" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_update_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_update_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_update_application" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_update_application_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_update_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23041,8 +23110,9 @@ def test_delete_application_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23097,19 +23167,20 @@ def test_delete_application_rest_interceptors(null_interceptor): ) client = AppHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_application" - ) as post, mock.patch.object( - transports.AppHubRestInterceptor, "post_delete_application_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AppHubRestInterceptor, "pre_delete_application" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_application" + ) as post, + mock.patch.object( + transports.AppHubRestInterceptor, "post_delete_application_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AppHubRestInterceptor, "pre_delete_application" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23162,8 +23233,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23222,8 +23294,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23284,8 +23357,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23348,8 +23422,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23412,8 +23487,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23476,8 +23552,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23538,8 +23615,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23600,8 +23678,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23662,8 +23741,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24400,11 +24480,14 @@ def test_app_hub_base_transport(): def test_app_hub_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.apphub_v1.services.app_hub.transports.AppHubTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.apphub_v1.services.app_hub.transports.AppHubTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppHubTransport( @@ -24421,9 +24504,12 @@ def test_app_hub_base_transport_with_credentials_file(): def test_app_hub_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.apphub_v1.services.app_hub.transports.AppHubTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.apphub_v1.services.app_hub.transports.AppHubTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppHubTransport() @@ -24495,11 +24581,12 @@ def test_app_hub_transport_auth_gdch_credentials(transport_class): def test_app_hub_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -25305,6 +25392,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AppHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25444,6 +25563,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AppHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25589,6 +25740,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AppHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25734,6 +25919,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AppHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25879,6 +26098,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AppHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26020,6 +26273,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AppHubClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26184,6 +26471,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AppHubClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26351,6 +26673,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AppHubClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26528,6 +26885,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AppHubClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AppHubAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AppHubClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/async_client.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/async_client.py index 2da068e323b6..1a35daf7159a 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/async_client.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/async_client.py @@ -279,7 +279,7 @@ def transport(self) -> ArtifactRegistryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -6396,7 +6396,7 @@ async def sample_export_artifact(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6422,8 +6422,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6432,7 +6436,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6440,7 +6444,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6451,7 +6455,7 @@ async def get_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6477,8 +6481,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6487,7 +6495,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6495,7 +6503,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6506,7 +6514,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6532,8 +6540,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6542,7 +6554,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6550,7 +6562,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/client.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/client.py index cc50a6f8c8dd..312f02a89395 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/client.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/client.py @@ -157,7 +157,7 @@ class ArtifactRegistryClient(metaclass=ArtifactRegistryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -165,7 +165,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -175,6 +175,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -832,7 +836,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -929,7 +933,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1027,7 +1031,7 @@ def __init__( self._universe_domain = ArtifactRegistryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -7009,7 +7013,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7035,8 +7039,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7045,7 +7053,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7054,7 +7062,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7068,7 +7076,7 @@ def get_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7094,8 +7102,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7104,7 +7116,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7113,7 +7125,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7127,7 +7139,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7153,8 +7165,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7163,7 +7179,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7172,7 +7188,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/README.rst b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/README.rst index d30fbe83290d..cd48330bf604 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/README.rst +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ArtifactRegistryTransport` is the ABC for all transports. -- public child `ArtifactRegistryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ArtifactRegistryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseArtifactRegistryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ArtifactRegistryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ArtifactRegistryTransport`` is the ABC for all transports. + +- public child ``ArtifactRegistryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ArtifactRegistryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseArtifactRegistryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ArtifactRegistryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/base.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/base.py index e179008f5ee6..7bb14d453de1 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/base.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/base.py @@ -110,6 +110,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -159,6 +163,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc.py index dfef683662c4..6b488da7c5e2 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc.py @@ -81,7 +81,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -116,7 +116,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -223,6 +223,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc_asyncio.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc_asyncio.py index 155d8ce8470c..0f53f5b86bcc 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc_asyncio.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/grpc_asyncio.py @@ -87,7 +87,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -122,7 +122,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -274,6 +274,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/rest.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/rest.py index eb5eb8577a65..aeaaad3533b5 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/rest.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1/services/artifact_registry/transports/rest.py @@ -2908,6 +2908,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ArtifactRegistryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/async_client.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/async_client.py index 7c103239ffc2..a26c332a43eb 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/async_client.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/async_client.py @@ -238,7 +238,7 @@ def transport(self) -> ArtifactRegistryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3282,7 +3282,7 @@ async def sample_update_project_settings(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3308,8 +3308,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3318,7 +3322,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3326,7 +3330,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3337,7 +3341,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3363,8 +3367,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3373,7 +3381,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3381,7 +3389,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/client.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/client.py index 945172688d34..9f5281f0d590 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/client.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/client.py @@ -144,7 +144,7 @@ class ArtifactRegistryClient(metaclass=ArtifactRegistryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -152,7 +152,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -162,6 +162,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -610,7 +614,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -707,7 +711,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -805,7 +809,7 @@ def __init__( self._universe_domain = ArtifactRegistryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3786,7 +3790,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3812,8 +3816,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3822,7 +3830,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3831,7 +3839,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3845,7 +3853,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3871,8 +3879,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3881,7 +3893,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3890,7 +3902,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/README.rst b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/README.rst index d30fbe83290d..cd48330bf604 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/README.rst +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ArtifactRegistryTransport` is the ABC for all transports. -- public child `ArtifactRegistryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ArtifactRegistryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseArtifactRegistryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ArtifactRegistryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ArtifactRegistryTransport`` is the ABC for all transports. + +- public child ``ArtifactRegistryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ArtifactRegistryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseArtifactRegistryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ArtifactRegistryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/base.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/base.py index fa0f8bad128d..2b50537a59b4 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/base.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/base.py @@ -99,6 +99,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -148,6 +152,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc.py index e0238c2a1ab2..d195e14ef3e3 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc.py @@ -70,7 +70,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -212,6 +212,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc_asyncio.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc_asyncio.py index 6e28de0f6086..95107b40999b 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc_asyncio.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/grpc_asyncio.py @@ -76,7 +76,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -111,7 +111,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -263,6 +263,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/rest.py b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/rest.py index 76bbbeb8cc36..27ea235dc466 100644 --- a/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/rest.py +++ b/packages/google-cloud-artifact-registry/google/cloud/artifactregistry_v1beta2/services/artifact_registry/transports/rest.py @@ -1539,6 +1539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ArtifactRegistryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-artifact-registry/noxfile.py b/packages/google-cloud-artifact-registry/noxfile.py index 6bce701df43c..51f138cfc7f1 100644 --- a/packages/google-cloud-artifact-registry/noxfile.py +++ b/packages/google-cloud-artifact-registry/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-artifact-registry/setup.py b/packages/google-cloud-artifact-registry/setup.py index 8f2f1c1fd50b..3325d17e403c 100644 --- a/packages/google-cloud-artifact-registry/setup.py +++ b/packages/google-cloud-artifact-registry/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-artifact-registry/testing/constraints-3.7.txt b/packages/google-cloud-artifact-registry/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-artifact-registry/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-artifact-registry/testing/constraints-3.8.txt b/packages/google-cloud-artifact-registry/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-artifact-registry/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-artifact-registry/testing/constraints-3.9.txt b/packages/google-cloud-artifact-registry/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-artifact-registry/testing/constraints-3.9.txt +++ b/packages/google-cloud-artifact-registry/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1/test_artifact_registry.py b/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1/test_artifact_registry.py index dfe8cc35b2d2..1eb6b82871ed 100644 --- a/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1/test_artifact_registry.py +++ b/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1/test_artifact_registry.py @@ -157,6 +157,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ArtifactRegistryClient._get_default_mtls_endpoint(None) is None assert ( @@ -179,6 +180,10 @@ def test__get_default_mtls_endpoint(): ArtifactRegistryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ArtifactRegistryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1348,11 +1353,13 @@ def test_artifact_registry_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -31118,8 +31125,9 @@ def test_list_docker_images_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31182,18 +31190,20 @@ def test_list_docker_images_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_docker_images" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_docker_images_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_docker_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_docker_images" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_docker_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_docker_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31248,8 +31258,9 @@ def test_get_docker_image_rest_bad_request(request_type=artifact.GetDockerImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31324,18 +31335,20 @@ def test_get_docker_image_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_docker_image" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_get_docker_image_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_docker_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_docker_image" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_docker_image_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_docker_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31386,8 +31399,9 @@ def test_list_maven_artifacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31450,18 +31464,20 @@ def test_list_maven_artifacts_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_maven_artifacts" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_maven_artifacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_maven_artifacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_maven_artifacts" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_maven_artifacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_maven_artifacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31521,8 +31537,9 @@ def test_get_maven_artifact_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31595,18 +31612,20 @@ def test_get_maven_artifact_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_maven_artifact" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_get_maven_artifact_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_maven_artifact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_maven_artifact" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_maven_artifact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_maven_artifact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31659,8 +31678,9 @@ def test_list_npm_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31723,18 +31743,20 @@ def test_list_npm_packages_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_npm_packages" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_npm_packages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_npm_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_npm_packages" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_npm_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_npm_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31789,8 +31811,9 @@ def test_get_npm_package_rest_bad_request(request_type=artifact.GetNpmPackageReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31861,17 +31884,20 @@ def test_get_npm_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_npm_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_npm_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_npm_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_npm_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_npm_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_npm_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31922,8 +31948,9 @@ def test_list_python_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31986,18 +32013,20 @@ def test_list_python_packages_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_python_packages" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_python_packages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_python_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_python_packages" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_python_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_python_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32057,8 +32086,9 @@ def test_get_python_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32129,18 +32159,20 @@ def test_get_python_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_python_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_get_python_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_python_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_python_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_python_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_python_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32193,8 +32225,9 @@ def test_import_apt_artifacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32251,20 +32284,21 @@ def test_import_apt_artifacts_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_import_apt_artifacts" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_import_apt_artifacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_import_apt_artifacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_import_apt_artifacts" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_import_apt_artifacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_import_apt_artifacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32317,8 +32351,9 @@ def test_import_yum_artifacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32375,20 +32410,21 @@ def test_import_yum_artifacts_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_import_yum_artifacts" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_import_yum_artifacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_import_yum_artifacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_import_yum_artifacts" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_import_yum_artifacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_import_yum_artifacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32441,8 +32477,9 @@ def test_list_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32505,18 +32542,20 @@ def test_list_repositories_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_repositories" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_repositories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_repositories" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_repositories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_repositories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32572,8 +32611,9 @@ def test_get_repository_rest_bad_request(request_type=repository.GetRepositoryRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32656,17 +32696,20 @@ def test_get_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32719,8 +32762,9 @@ def test_create_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32915,20 +32959,21 @@ def test_create_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_create_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_create_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_create_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_create_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32985,8 +33030,9 @@ def test_update_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33211,18 +33257,20 @@ def test_update_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_update_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33275,8 +33323,9 @@ def test_delete_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33333,20 +33382,21 @@ def test_delete_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_delete_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33397,8 +33447,9 @@ def test_list_packages_rest_bad_request(request_type=package.ListPackagesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33461,17 +33512,20 @@ def test_list_packages_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_packages" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_packages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_packages" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33524,8 +33578,9 @@ def test_get_package_rest_bad_request(request_type=package.GetPackageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33592,17 +33647,19 @@ def test_get_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_package_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33653,8 +33710,9 @@ def test_delete_package_rest_bad_request(request_type=package.DeletePackageReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33713,19 +33771,21 @@ def test_delete_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33776,8 +33836,9 @@ def test_list_versions_rest_bad_request(request_type=version.ListVersionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33842,17 +33903,20 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33905,8 +33969,9 @@ def test_get_version_rest_bad_request(request_type=version.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33973,17 +34038,19 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34034,8 +34101,9 @@ def test_delete_version_rest_bad_request(request_type=version.DeleteVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34094,19 +34162,21 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_version" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_version" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34159,8 +34229,9 @@ def test_batch_delete_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34219,20 +34290,21 @@ def test_batch_delete_versions_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_batch_delete_versions" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_batch_delete_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_batch_delete_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_batch_delete_versions" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_batch_delete_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_batch_delete_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34287,8 +34359,9 @@ def test_update_version_rest_bad_request(request_type=gda_version.UpdateVersionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34434,17 +34507,20 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34495,8 +34571,9 @@ def test_list_files_rest_bad_request(request_type=file.ListFilesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34559,17 +34636,19 @@ def test_list_files_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_files" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_files" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34620,8 +34699,9 @@ def test_get_file_rest_bad_request(request_type=file.GetFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34690,17 +34770,19 @@ def test_get_file_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_file" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_file" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34751,8 +34833,9 @@ def test_delete_file_rest_bad_request(request_type=file.DeleteFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34811,19 +34894,20 @@ def test_delete_file_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_file" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_file" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34876,8 +34960,9 @@ def test_update_file_rest_bad_request(request_type=gda_file.UpdateFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35025,17 +35110,19 @@ def test_update_file_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_file" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_file" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35086,8 +35173,9 @@ def test_list_tags_rest_bad_request(request_type=tag.ListTagsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35152,17 +35240,19 @@ def test_list_tags_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_tags" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_tags_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_tags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_tags" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_tags_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_tags" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35213,8 +35303,9 @@ def test_get_tag_rest_bad_request(request_type=tag.GetTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35281,17 +35372,19 @@ def test_get_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_tag" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_tag_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_tag" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_tag_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35342,8 +35435,9 @@ def test_create_tag_rest_bad_request(request_type=gda_tag.CreateTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35478,17 +35572,19 @@ def test_create_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_tag" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_tag_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_create_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_tag" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_tag_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_create_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35541,8 +35637,9 @@ def test_update_tag_rest_bad_request(request_type=gda_tag.UpdateTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35682,17 +35779,19 @@ def test_update_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_tag" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_tag_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_tag" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_tag_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35743,8 +35842,9 @@ def test_delete_tag_rest_bad_request(request_type=tag.DeleteTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35803,13 +35903,13 @@ def test_delete_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_tag" + ) as pre, + ): pre.assert_not_called() pb_message = tag.DeleteTagRequest.pb(tag.DeleteTagRequest()) transcode.return_value = { @@ -35850,8 +35950,9 @@ def test_create_rule_rest_bad_request(request_type=gda_rule.CreateRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35999,17 +36100,19 @@ def test_create_rule_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_rule" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_create_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_rule" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_create_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36058,8 +36161,9 @@ def test_list_rules_rest_bad_request(request_type=rule.ListRulesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36122,17 +36226,19 @@ def test_list_rules_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_rules" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_rules_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_rules" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_rules_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36183,8 +36289,9 @@ def test_get_rule_rest_bad_request(request_type=rule.GetRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36255,17 +36362,19 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36318,8 +36427,9 @@ def test_update_rule_rest_bad_request(request_type=gda_rule.UpdateRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36471,17 +36581,19 @@ def test_update_rule_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_rule" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_rule" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36532,8 +36644,9 @@ def test_delete_rule_rest_bad_request(request_type=rule.DeleteRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36592,13 +36705,13 @@ def test_delete_rule_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_rule" + ) as pre, + ): pre.assert_not_called() pb_message = rule.DeleteRuleRequest.pb(rule.DeleteRuleRequest()) transcode.return_value = { @@ -36643,8 +36756,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36708,17 +36822,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36771,8 +36888,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36836,17 +36954,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36899,8 +37020,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36962,18 +37084,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37029,8 +37153,9 @@ def test_get_project_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37100,18 +37225,20 @@ def test_get_project_settings_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_project_settings" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_get_project_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_project_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_project_settings" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_project_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_project_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37164,8 +37291,9 @@ def test_update_project_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37307,18 +37435,20 @@ def test_update_project_settings_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_project_settings" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_update_project_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_project_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_project_settings" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_project_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_project_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37371,8 +37501,9 @@ def test_get_vpcsc_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37437,18 +37568,20 @@ def test_get_vpcsc_config_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_vpcsc_config" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_get_vpcsc_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_vpcsc_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_vpcsc_config" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_vpcsc_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_vpcsc_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37503,8 +37636,9 @@ def test_update_vpcsc_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37642,18 +37776,20 @@ def test_update_vpcsc_config_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_vpcsc_config" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_update_vpcsc_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_vpcsc_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_vpcsc_config" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_vpcsc_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_vpcsc_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37710,8 +37846,9 @@ def test_update_package_rest_bad_request(request_type=gda_package.UpdatePackageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37854,17 +37991,20 @@ def test_update_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37917,8 +38057,9 @@ def test_list_attachments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37981,18 +38122,20 @@ def test_list_attachments_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_attachments" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_attachments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_attachments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_attachments" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_attachments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_attachments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38047,8 +38190,9 @@ def test_get_attachment_rest_bad_request(request_type=attachment.GetAttachmentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38123,17 +38267,20 @@ def test_get_attachment_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_attachment" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_attachment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_attachment" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38186,8 +38333,9 @@ def test_create_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38322,20 +38470,21 @@ def test_create_attachment_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_attachment" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_create_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_create_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_attachment" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_create_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_create_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38390,8 +38539,9 @@ def test_delete_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38450,20 +38600,21 @@ def test_delete_attachment_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_attachment" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_delete_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_attachment" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38516,8 +38667,9 @@ def test_export_artifact_rest_bad_request(request_type=export.ExportArtifactRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38576,19 +38728,21 @@ def test_export_artifact_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_export_artifact" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_export_artifact_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_export_artifact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_export_artifact" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_export_artifact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_export_artifact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38639,8 +38793,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38699,8 +38854,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38761,8 +38917,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39982,11 +40139,14 @@ def test_artifact_registry_base_transport(): def test_artifact_registry_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.artifactregistry_v1.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.artifactregistry_v1.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ArtifactRegistryTransport( @@ -40006,9 +40166,12 @@ def test_artifact_registry_base_transport_with_credentials_file(): def test_artifact_registry_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.artifactregistry_v1.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.artifactregistry_v1.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ArtifactRegistryTransport() @@ -40086,11 +40249,12 @@ def test_artifact_registry_transport_auth_gdch_credentials(transport_class): def test_artifact_registry_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -41286,6 +41450,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ArtifactRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ArtifactRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_locations(transport: str = "grpc"): client = ArtifactRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41431,6 +41629,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ArtifactRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ArtifactRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ArtifactRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41572,6 +41804,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ArtifactRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ArtifactRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ArtifactRegistryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1beta2/test_artifact_registry.py b/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1beta2/test_artifact_registry.py index 1ad461e03d98..986d4fd9c69c 100644 --- a/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1beta2/test_artifact_registry.py +++ b/packages/google-cloud-artifact-registry/tests/unit/gapic/artifactregistry_v1beta2/test_artifact_registry.py @@ -145,6 +145,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ArtifactRegistryClient._get_default_mtls_endpoint(None) is None assert ( @@ -167,6 +168,10 @@ def test__get_default_mtls_endpoint(): ArtifactRegistryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ArtifactRegistryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1336,11 +1341,13 @@ def test_artifact_registry_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -14944,8 +14951,9 @@ def test_import_apt_artifacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15002,20 +15010,21 @@ def test_import_apt_artifacts_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_import_apt_artifacts" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_import_apt_artifacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_import_apt_artifacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_import_apt_artifacts" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_import_apt_artifacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_import_apt_artifacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15068,8 +15077,9 @@ def test_import_yum_artifacts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15126,20 +15136,21 @@ def test_import_yum_artifacts_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_import_yum_artifacts" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_import_yum_artifacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_import_yum_artifacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_import_yum_artifacts" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_import_yum_artifacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_import_yum_artifacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15192,8 +15203,9 @@ def test_list_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15256,18 +15268,20 @@ def test_list_repositories_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_repositories" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_list_repositories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_repositories" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_repositories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_repositories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15323,8 +15337,9 @@ def test_get_repository_rest_bad_request(request_type=repository.GetRepositoryRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15393,17 +15408,20 @@ def test_get_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15456,8 +15474,9 @@ def test_create_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15591,20 +15610,21 @@ def test_create_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_create_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_create_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_create_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_create_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15661,8 +15681,9 @@ def test_update_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15812,18 +15833,20 @@ def test_update_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_update_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15876,8 +15899,9 @@ def test_delete_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15934,20 +15958,21 @@ def test_delete_repository_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_repository" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_delete_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_repository" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15998,8 +16023,9 @@ def test_list_packages_rest_bad_request(request_type=package.ListPackagesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16062,17 +16088,20 @@ def test_list_packages_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_packages" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_packages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_packages" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16125,8 +16154,9 @@ def test_get_package_rest_bad_request(request_type=package.GetPackageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16193,17 +16223,19 @@ def test_get_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_package_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16254,8 +16286,9 @@ def test_delete_package_rest_bad_request(request_type=package.DeletePackageReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16314,19 +16347,21 @@ def test_delete_package_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_package" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_package" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16377,8 +16412,9 @@ def test_list_versions_rest_bad_request(request_type=version.ListVersionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16443,17 +16479,20 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_list_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16506,8 +16545,9 @@ def test_get_version_rest_bad_request(request_type=version.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16574,17 +16614,19 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16635,8 +16677,9 @@ def test_delete_version_rest_bad_request(request_type=version.DeleteVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16695,19 +16738,21 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_version" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_delete_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_delete_version" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_delete_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16756,8 +16801,9 @@ def test_list_files_rest_bad_request(request_type=file.ListFilesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16820,17 +16866,19 @@ def test_list_files_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_files" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_files" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16881,8 +16929,9 @@ def test_get_file_rest_bad_request(request_type=file.GetFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16951,17 +17000,19 @@ def test_get_file_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_file" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_file" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_file_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17012,8 +17063,9 @@ def test_list_tags_rest_bad_request(request_type=tag.ListTagsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17078,17 +17130,19 @@ def test_list_tags_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_tags" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_list_tags_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_list_tags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_tags" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_list_tags_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_list_tags" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17139,8 +17193,9 @@ def test_get_tag_rest_bad_request(request_type=tag.GetTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17207,17 +17262,19 @@ def test_get_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_tag" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_tag_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_tag" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_tag_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17268,8 +17325,9 @@ def test_create_tag_rest_bad_request(request_type=gda_tag.CreateTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17404,17 +17462,19 @@ def test_create_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_tag" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_create_tag_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_create_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_tag" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_create_tag_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_create_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17467,8 +17527,9 @@ def test_update_tag_rest_bad_request(request_type=gda_tag.UpdateTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17608,17 +17669,19 @@ def test_update_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_tag" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_tag_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_tag" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_tag_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_tag" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17669,8 +17732,9 @@ def test_delete_tag_rest_bad_request(request_type=tag.DeleteTagRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17729,13 +17793,13 @@ def test_delete_tag_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_delete_tag" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_delete_tag" + ) as pre, + ): pre.assert_not_called() pb_message = tag.DeleteTagRequest.pb(tag.DeleteTagRequest()) transcode.return_value = { @@ -17780,8 +17844,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17845,17 +17910,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17908,8 +17976,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17973,17 +18042,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18036,8 +18108,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18099,18 +18172,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18166,8 +18241,9 @@ def test_get_project_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18235,18 +18311,20 @@ def test_get_project_settings_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_get_project_settings" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_get_project_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_get_project_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_get_project_settings" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_get_project_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_get_project_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18299,8 +18377,9 @@ def test_update_project_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18439,18 +18518,20 @@ def test_update_project_settings_rest_interceptors(null_interceptor): ) client = ArtifactRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "post_update_project_settings" - ) as post, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, - "post_update_project_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ArtifactRegistryRestInterceptor, "pre_update_project_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "post_update_project_settings" + ) as post, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, + "post_update_project_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ArtifactRegistryRestInterceptor, "pre_update_project_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18503,8 +18584,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18563,8 +18645,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -19238,11 +19321,14 @@ def test_artifact_registry_base_transport(): def test_artifact_registry_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.artifactregistry_v1beta2.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.artifactregistry_v1beta2.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ArtifactRegistryTransport( @@ -19262,9 +19348,12 @@ def test_artifact_registry_base_transport_with_credentials_file(): def test_artifact_registry_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.artifactregistry_v1beta2.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.artifactregistry_v1beta2.services.artifact_registry.transports.ArtifactRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ArtifactRegistryTransport() @@ -19342,11 +19431,12 @@ def test_artifact_registry_transport_auth_gdch_credentials(transport_class): def test_artifact_registry_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -20205,6 +20295,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ArtifactRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ArtifactRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ArtifactRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20346,6 +20470,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ArtifactRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ArtifactRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ArtifactRegistryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/async_client.py b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/async_client.py index 1c2b0d2d35e2..c0fa1b310438 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> AssetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3393,7 +3393,7 @@ async def sample_analyze_org_policy_governed_assets(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3419,8 +3419,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3429,7 +3433,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3437,7 +3441,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/client.py b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/client.py index 2814645640b6..66cfdadc04bf 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/client.py @@ -117,7 +117,7 @@ class AssetServiceClient(metaclass=AssetServiceClientMeta): """Asset service definition.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -544,7 +548,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -641,7 +645,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -737,7 +741,7 @@ def __init__( self._universe_domain = AssetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3873,7 +3877,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3899,8 +3903,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3909,7 +3917,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3918,7 +3926,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/README.rst b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/README.rst index f0467812ea79..a1349efa0636 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/README.rst +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssetServiceTransport` is the ABC for all transports. -- public child `AssetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssetServiceTransport`` is the ABC for all transports. + +- public child ``AssetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/base.py b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/base.py index c3826a96437a..1a3e9c167a1b 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/base.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py index 7c7e10a8342f..b58699d73466 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py index 9b59dfa7cfd8..3f4c3e4a916c 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/rest.py b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/rest.py index f0d585eb84e5..a4111fe00ba1 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/rest.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1/services/asset_service/transports/rest.py @@ -1413,6 +1413,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py index e7d6fbd776f5..443b5db170f5 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/async_client.py @@ -181,7 +181,7 @@ def transport(self) -> AssetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/client.py b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/client.py index f1bd3462d456..23a06b445d2c 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/client.py @@ -111,7 +111,7 @@ class AssetServiceClient(metaclass=AssetServiceClientMeta): """Asset service definition.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -414,7 +418,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -511,7 +515,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = AssetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/README.rst b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/README.rst index f0467812ea79..a1349efa0636 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/README.rst +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssetServiceTransport` is the ABC for all transports. -- public child `AssetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssetServiceTransport`` is the ABC for all transports. + +- public child ``AssetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py index 4aa7f5eb2218..7e5de15cf039 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py index 405253354d25..5963f282760c 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py index 3f90e3808b0e..0a0ca91cf27a 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/rest.py b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/rest.py index e12c8535d5c1..b59dc28d2d63 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/rest.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p1beta1/services/asset_service/transports/rest.py @@ -265,6 +265,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py index c58ac95ab706..9635cdf2500e 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/async_client.py @@ -182,7 +182,7 @@ def transport(self) -> AssetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -875,7 +875,7 @@ async def sample_delete_feed(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -901,8 +901,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -911,7 +915,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -919,7 +923,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/client.py b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/client.py index 8aa79db182a2..bd57f6dc566e 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/client.py @@ -110,7 +110,7 @@ class AssetServiceClient(metaclass=AssetServiceClientMeta): """Asset service definition.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -430,7 +434,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -527,7 +531,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( self._universe_domain = AssetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1301,7 +1305,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1327,8 +1331,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1337,7 +1345,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1346,7 +1354,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/README.rst b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/README.rst index f0467812ea79..a1349efa0636 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/README.rst +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssetServiceTransport` is the ABC for all transports. -- public child `AssetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssetServiceTransport`` is the ABC for all transports. + +- public child ``AssetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py index abd76ca51760..a8045c073758 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py index c2d683faedf7..6113a8facedf 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py index c0f1fbdf4bf5..d8297e5c99ae 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/rest.py b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/rest.py index 4205a2f9b850..4c5a46d47cec 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/rest.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p2beta1/services/asset_service/transports/rest.py @@ -406,6 +406,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py index aacbfdad5993..495cf81c2533 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> AssetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/client.py b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/client.py index c0a8e80e8c68..9716463a26a3 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/client.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/client.py @@ -111,7 +111,7 @@ class AssetServiceClient(metaclass=AssetServiceClientMeta): """Asset service definition.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -480,7 +484,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -577,7 +581,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -673,7 +677,7 @@ def __init__( self._universe_domain = AssetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/README.rst b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/README.rst index f0467812ea79..a1349efa0636 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/README.rst +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssetServiceTransport` is the ABC for all transports. -- public child `AssetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssetServiceTransport`` is the ABC for all transports. + +- public child ``AssetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py index ba975f3cabfe..fdc2c8a8f634 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py index 35d8a1eae0c2..025b1a43cc11 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py index c44a3cfe9a66..cbca7d2c2352 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/rest.py b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/rest.py index 9b89535fd329..4e9defbfa0b7 100644 --- a/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/rest.py +++ b/packages/google-cloud-asset/google/cloud/asset_v1p5beta1/services/asset_service/transports/rest.py @@ -204,6 +204,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-asset/noxfile.py b/packages/google-cloud-asset/noxfile.py index 8eebcf7c34ef..2d11d680fae2 100644 --- a/packages/google-cloud-asset/noxfile.py +++ b/packages/google-cloud-asset/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-asset/setup.py b/packages/google-cloud-asset/setup.py index d7feef616eb3..0c1270814cbb 100644 --- a/packages/google-cloud-asset/setup.py +++ b/packages/google-cloud-asset/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -48,7 +48,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "google-cloud-access-context-manager >= 0.1.2, <1.0.0", "google-cloud-os-config >= 1.0.0, <2.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", @@ -83,8 +83,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -96,7 +94,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-asset/testing/constraints-3.7.txt b/packages/google-cloud-asset/testing/constraints-3.7.txt deleted file mode 100644 index 31eb1e3b2e67..000000000000 --- a/packages/google-cloud-asset/testing/constraints-3.7.txt +++ /dev/null @@ -1,18 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-cloud-org-policy==0.1.2 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -google-cloud-access-context-manager==0.1.2 -google-cloud-os-config==1.0.0 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-asset/testing/constraints-3.8.txt b/packages/google-cloud-asset/testing/constraints-3.8.txt deleted file mode 100644 index c5602c5029bf..000000000000 --- a/packages/google-cloud-asset/testing/constraints-3.8.txt +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-cloud-access-context-manager -google-cloud-os-config -grpc-google-iam-v1 diff --git a/packages/google-cloud-asset/testing/constraints-3.9.txt b/packages/google-cloud-asset/testing/constraints-3.9.txt index c5602c5029bf..f252d87f5f08 100644 --- a/packages/google-cloud-asset/testing/constraints-3.9.txt +++ b/packages/google-cloud-asset/testing/constraints-3.9.txt @@ -1,13 +1,17 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-cloud-access-context-manager -google-cloud-os-config -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-cloud-org-policy==0.1.2 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +google-cloud-access-context-manager==0.1.2 +google-cloud-os-config==1.0.0 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-asset/tests/unit/gapic/asset_v1/test_asset_service.py b/packages/google-cloud-asset/tests/unit/gapic/asset_v1/test_asset_service.py index 34fd788bb562..add96e33c80a 100644 --- a/packages/google-cloud-asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/packages/google-cloud-asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AssetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1267,11 +1272,13 @@ def test_asset_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -15858,8 +15865,9 @@ def test_export_assets_rest_bad_request(request_type=asset_service.ExportAssetsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15916,19 +15924,20 @@ def test_export_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AssetServiceRestInterceptor, "post_export_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_export_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_export_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_export_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_export_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_export_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15979,8 +15988,9 @@ def test_list_assets_rest_bad_request(request_type=asset_service.ListAssetsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16043,17 +16053,19 @@ def test_list_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16108,8 +16120,9 @@ def test_batch_get_assets_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16169,18 +16182,20 @@ def test_batch_get_assets_history_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_batch_get_assets_history" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_batch_get_assets_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_batch_get_assets_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_batch_get_assets_history" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_batch_get_assets_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_batch_get_assets_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16236,8 +16251,9 @@ def test_create_feed_rest_bad_request(request_type=asset_service.CreateFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16308,17 +16324,19 @@ def test_create_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_create_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_create_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16369,8 +16387,9 @@ def test_get_feed_rest_bad_request(request_type=asset_service.GetFeedRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16441,17 +16460,19 @@ def test_get_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_get_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_get_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16500,8 +16521,9 @@ def test_list_feeds_rest_bad_request(request_type=asset_service.ListFeedsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16561,17 +16583,19 @@ def test_list_feeds_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_feeds" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_feeds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_feeds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_feeds" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_feeds_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_feeds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16622,8 +16646,9 @@ def test_update_feed_rest_bad_request(request_type=asset_service.UpdateFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16694,17 +16719,19 @@ def test_update_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_update_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_update_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16755,8 +16782,9 @@ def test_delete_feed_rest_bad_request(request_type=asset_service.DeleteFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16813,13 +16841,13 @@ def test_delete_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_delete_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_delete_feed" + ) as pre, + ): pre.assert_not_called() pb_message = asset_service.DeleteFeedRequest.pb( asset_service.DeleteFeedRequest() @@ -16864,8 +16892,9 @@ def test_search_all_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16928,18 +16957,20 @@ def test_search_all_resources_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_search_all_resources" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_search_all_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_search_all_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_search_all_resources" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_search_all_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_search_all_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16997,8 +17028,9 @@ def test_search_all_iam_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17061,18 +17093,20 @@ def test_search_all_iam_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_search_all_iam_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_search_all_iam_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_search_all_iam_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_search_all_iam_policies" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_search_all_iam_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_search_all_iam_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17130,8 +17164,9 @@ def test_analyze_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17194,17 +17229,20 @@ def test_analyze_iam_policy_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_iam_policy" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_iam_policy" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17262,8 +17300,9 @@ def test_analyze_iam_policy_longrunning_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17320,20 +17359,22 @@ def test_analyze_iam_policy_longrunning_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_iam_policy_longrunning" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_iam_policy_longrunning_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy_longrunning" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_iam_policy_longrunning", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_iam_policy_longrunning_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_iam_policy_longrunning" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17384,8 +17425,9 @@ def test_analyze_move_rest_bad_request(request_type=asset_service.AnalyzeMoveReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17445,17 +17487,19 @@ def test_analyze_move_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_move" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_move" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_move_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_move" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17508,8 +17552,9 @@ def test_query_assets_rest_bad_request(request_type=asset_service.QueryAssetsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17574,17 +17619,19 @@ def test_query_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_query_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_query_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_query_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_query_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_query_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_query_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17639,8 +17686,9 @@ def test_create_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17805,17 +17853,20 @@ def test_create_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_saved_query" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_saved_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_create_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_saved_query" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_create_saved_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_create_saved_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17868,8 +17919,9 @@ def test_get_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17938,17 +17990,19 @@ def test_get_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_saved_query" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_saved_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_get_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_saved_query" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_saved_query_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_get_saved_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18001,8 +18055,9 @@ def test_list_saved_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18065,17 +18120,20 @@ def test_list_saved_queries_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_saved_queries" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_saved_queries_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_saved_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_saved_queries" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_list_saved_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_saved_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18133,8 +18191,9 @@ def test_update_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18299,17 +18358,20 @@ def test_update_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_saved_query" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_saved_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_update_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_saved_query" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_update_saved_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_update_saved_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18362,8 +18424,9 @@ def test_delete_saved_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18420,13 +18483,13 @@ def test_delete_saved_query_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_delete_saved_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_delete_saved_query" + ) as pre, + ): pre.assert_not_called() pb_message = asset_service.DeleteSavedQueryRequest.pb( asset_service.DeleteSavedQueryRequest() @@ -18471,8 +18534,9 @@ def test_batch_get_effective_iam_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18534,18 +18598,22 @@ def test_batch_get_effective_iam_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_batch_get_effective_iam_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_batch_get_effective_iam_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_batch_get_effective_iam_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_batch_get_effective_iam_policies", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_batch_get_effective_iam_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "pre_batch_get_effective_iam_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18603,8 +18671,9 @@ def test_analyze_org_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18667,18 +18736,20 @@ def test_analyze_org_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_analyze_org_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_org_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_analyze_org_policies" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_analyze_org_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18736,8 +18807,9 @@ def test_analyze_org_policy_governed_containers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18802,20 +18874,22 @@ def test_analyze_org_policy_governed_containers_rest_interceptors(null_intercept ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_containers", - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_containers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, - "pre_analyze_org_policy_governed_containers", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_containers", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_containers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "pre_analyze_org_policy_governed_containers", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18873,8 +18947,9 @@ def test_analyze_org_policy_governed_assets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18939,19 +19014,22 @@ def test_analyze_org_policy_governed_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_assets", - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_analyze_org_policy_governed_assets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_analyze_org_policy_governed_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_assets", + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_analyze_org_policy_governed_assets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "pre_analyze_org_policy_governed_assets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19011,8 +19089,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -19651,11 +19730,14 @@ def test_asset_service_base_transport(): def test_asset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport( @@ -19672,9 +19754,12 @@ def test_asset_service_base_transport_with_credentials_file(): def test_asset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.asset_v1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport() @@ -19746,11 +19831,12 @@ def test_asset_service_transport_auth_gdch_credentials(transport_class): def test_asset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -20539,6 +20625,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AssetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-asset/tests/unit/gapic/asset_v1p1beta1/test_asset_service.py b/packages/google-cloud-asset/tests/unit/gapic/asset_v1p1beta1/test_asset_service.py index bdce557cc99b..b2427cfef025 100644 --- a/packages/google-cloud-asset/tests/unit/gapic/asset_v1p1beta1/test_asset_service.py +++ b/packages/google-cloud-asset/tests/unit/gapic/asset_v1p1beta1/test_asset_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AssetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1258,11 +1263,13 @@ def test_asset_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3188,8 +3195,9 @@ def test_search_all_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3252,18 +3260,20 @@ def test_search_all_resources_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_search_all_resources" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_search_all_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_search_all_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_search_all_resources" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_search_all_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_search_all_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3321,8 +3331,9 @@ def test_search_all_iam_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3385,18 +3396,20 @@ def test_search_all_iam_policies_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_search_all_iam_policies" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, - "post_search_all_iam_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_search_all_iam_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_search_all_iam_policies" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, + "post_search_all_iam_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_search_all_iam_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3548,11 +3561,14 @@ def test_asset_service_base_transport(): def test_asset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.asset_v1p1beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.asset_v1p1beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport( @@ -3569,9 +3585,12 @@ def test_asset_service_base_transport_with_credentials_file(): def test_asset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.asset_v1p1beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.asset_v1p1beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport() @@ -3643,11 +3662,12 @@ def test_asset_service_transport_auth_gdch_credentials(transport_class): def test_asset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-asset/tests/unit/gapic/asset_v1p2beta1/test_asset_service.py b/packages/google-cloud-asset/tests/unit/gapic/asset_v1p2beta1/test_asset_service.py index 4cddea785765..e11fc60b0f25 100644 --- a/packages/google-cloud-asset/tests/unit/gapic/asset_v1p2beta1/test_asset_service.py +++ b/packages/google-cloud-asset/tests/unit/gapic/asset_v1p2beta1/test_asset_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AssetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1258,11 +1263,13 @@ def test_asset_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4161,8 +4168,9 @@ def test_create_feed_rest_bad_request(request_type=asset_service.CreateFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4231,17 +4239,19 @@ def test_create_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_create_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_create_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_create_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_create_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4292,8 +4302,9 @@ def test_get_feed_rest_bad_request(request_type=asset_service.GetFeedRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4362,17 +4373,19 @@ def test_get_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_get_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_get_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_get_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_get_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4421,8 +4434,9 @@ def test_list_feeds_rest_bad_request(request_type=asset_service.ListFeedsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4482,17 +4496,19 @@ def test_list_feeds_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_feeds" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_feeds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_feeds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_feeds" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_feeds_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_feeds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4543,8 +4559,9 @@ def test_update_feed_rest_bad_request(request_type=asset_service.UpdateFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4613,17 +4630,19 @@ def test_update_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_feed" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_update_feed_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_update_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_feed" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_update_feed_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_update_feed" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4674,8 +4693,9 @@ def test_delete_feed_rest_bad_request(request_type=asset_service.DeleteFeedReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4732,13 +4752,13 @@ def test_delete_feed_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_delete_feed" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_delete_feed" + ) as pre, + ): pre.assert_not_called() pb_message = asset_service.DeleteFeedRequest.pb( asset_service.DeleteFeedRequest() @@ -4785,8 +4805,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4999,11 +5020,14 @@ def test_asset_service_base_transport(): def test_asset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.asset_v1p2beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.asset_v1p2beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport( @@ -5020,9 +5044,12 @@ def test_asset_service_base_transport_with_credentials_file(): def test_asset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.asset_v1p2beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.asset_v1p2beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport() @@ -5094,11 +5121,12 @@ def test_asset_service_transport_auth_gdch_credentials(transport_class): def test_asset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5665,6 +5693,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AssetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-asset/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py b/packages/google-cloud-asset/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py index 8e934c31a73f..ba3040327f6d 100644 --- a/packages/google-cloud-asset/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py +++ b/packages/google-cloud-asset/tests/unit/gapic/asset_v1p5beta1/test_asset_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AssetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1259,11 +1264,13 @@ def test_asset_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2244,8 +2251,9 @@ def test_list_assets_rest_bad_request(request_type=asset_service.ListAssetsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2308,17 +2316,19 @@ def test_list_assets_rest_interceptors(null_interceptor): ) client = AssetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_assets" - ) as post, mock.patch.object( - transports.AssetServiceRestInterceptor, "post_list_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssetServiceRestInterceptor, "pre_list_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_assets" + ) as post, + mock.patch.object( + transports.AssetServiceRestInterceptor, "post_list_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AssetServiceRestInterceptor, "pre_list_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2440,11 +2450,14 @@ def test_asset_service_base_transport(): def test_asset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.asset_v1p5beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.asset_v1p5beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport( @@ -2461,9 +2474,12 @@ def test_asset_service_base_transport_with_credentials_file(): def test_asset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.asset_v1p5beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.asset_v1p5beta1.services.asset_service.transports.AssetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssetServiceTransport() @@ -2535,11 +2551,12 @@ def test_asset_service_transport_auth_gdch_credentials(transport_class): def test_asset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/async_client.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/async_client.py index 8baac4655d89..95c0fdd27b9d 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/async_client.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> AssuredWorkloadsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1348,7 +1348,7 @@ async def sample_acknowledge_violation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1374,8 +1374,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1384,7 +1388,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1392,7 +1396,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1403,7 +1407,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1429,8 +1433,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1439,7 +1447,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1447,7 +1455,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/client.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/client.py index 65d5b389d99f..ee7f00b87e79 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/client.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/client.py @@ -115,7 +115,7 @@ class AssuredWorkloadsServiceClient(metaclass=AssuredWorkloadsServiceClientMeta) """Service to manage AssuredWorkloads.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -563,7 +567,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = AssuredWorkloadsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1781,7 +1785,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1807,8 +1811,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1817,7 +1825,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1826,7 +1834,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1840,7 +1848,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1866,8 +1874,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1876,7 +1888,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1885,7 +1897,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/README.rst b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/README.rst index 30f56618bd12..c00895ea738a 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/README.rst +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssuredWorkloadsServiceTransport` is the ABC for all transports. -- public child `AssuredWorkloadsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssuredWorkloadsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssuredWorkloadsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssuredWorkloadsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssuredWorkloadsServiceTransport`` is the ABC for all transports. + +- public child ``AssuredWorkloadsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssuredWorkloadsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssuredWorkloadsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssuredWorkloadsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/base.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/base.py index 0b03e2b254ac..4c594b17fcc1 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/base.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc.py index 90fe2aa81eb6..d335d2dc511c 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc_asyncio.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc_asyncio.py index f7432214209c..838f003b085e 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/rest.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/rest.py index 6ab9d1084389..81769f2d87d0 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/rest.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1/services/assured_workloads_service/transports/rest.py @@ -525,6 +525,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssuredWorkloadsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py index 22ad7369fbaf..f9fc41ea5f4a 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> AssuredWorkloadsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1143,7 +1143,7 @@ async def sample_list_workloads(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1169,8 +1169,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1179,7 +1183,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1187,7 +1191,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1198,7 +1202,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1224,8 +1228,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1234,7 +1242,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1242,7 +1250,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py index fdb7526b2c61..5ef05db39992 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/client.py @@ -117,7 +117,7 @@ class AssuredWorkloadsServiceClient(metaclass=AssuredWorkloadsServiceClientMeta) """Service to manage AssuredWorkloads.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = AssuredWorkloadsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1561,7 +1565,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1587,8 +1591,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1597,7 +1605,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1606,7 +1614,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1620,7 +1628,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1646,8 +1654,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1656,7 +1668,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1665,7 +1677,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/README.rst b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/README.rst index 30f56618bd12..c00895ea738a 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/README.rst +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssuredWorkloadsServiceTransport` is the ABC for all transports. -- public child `AssuredWorkloadsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssuredWorkloadsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssuredWorkloadsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssuredWorkloadsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssuredWorkloadsServiceTransport`` is the ABC for all transports. + +- public child ``AssuredWorkloadsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssuredWorkloadsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssuredWorkloadsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssuredWorkloadsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py index 8d35013de49f..ffbd36f08055 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py index 2311822e3408..75d050e4a2ad 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py index 2664cde99f1f..217bc1bd6c61 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/rest.py b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/rest.py index abd6652ca99e..d5ad102822b7 100644 --- a/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/rest.py +++ b/packages/google-cloud-assured-workloads/google/cloud/assuredworkloads_v1beta1/services/assured_workloads_service/transports/rest.py @@ -363,6 +363,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssuredWorkloadsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-assured-workloads/noxfile.py b/packages/google-cloud-assured-workloads/noxfile.py index a56ab4e95efa..b2d5a533bb46 100644 --- a/packages/google-cloud-assured-workloads/noxfile.py +++ b/packages/google-cloud-assured-workloads/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-assured-workloads/setup.py b/packages/google-cloud-assured-workloads/setup.py index 22ad4166c53d..56df4f4a300b 100644 --- a/packages/google-cloud-assured-workloads/setup.py +++ b/packages/google-cloud-assured-workloads/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-assured-workloads" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-assured-workloads/testing/constraints-3.7.txt b/packages/google-cloud-assured-workloads/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-assured-workloads/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-assured-workloads/testing/constraints-3.8.txt b/packages/google-cloud-assured-workloads/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-assured-workloads/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-assured-workloads/testing/constraints-3.9.txt b/packages/google-cloud-assured-workloads/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-assured-workloads/testing/constraints-3.9.txt +++ b/packages/google-cloud-assured-workloads/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1/test_assured_workloads_service.py b/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1/test_assured_workloads_service.py index c2caf31d624a..efcd8b1869cd 100644 --- a/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1/test_assured_workloads_service.py +++ b/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1/test_assured_workloads_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssuredWorkloadsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): AssuredWorkloadsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AssuredWorkloadsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1354,11 +1359,13 @@ def test_assured_workloads_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6295,8 +6302,9 @@ def test_create_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6450,20 +6458,21 @@ def test_create_workload_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "post_create_workload" - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_create_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_create_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "post_create_workload" + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_create_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_create_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6520,8 +6529,9 @@ def test_update_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6710,18 +6720,20 @@ def test_update_workload_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "post_update_workload" - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_update_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_update_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "post_update_workload" + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_update_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_update_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6774,8 +6786,9 @@ def test_restrict_allowed_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6837,20 +6850,22 @@ def test_restrict_allowed_resources_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_restrict_allowed_resources", - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_restrict_allowed_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "pre_restrict_allowed_resources", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_restrict_allowed_resources", + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_restrict_allowed_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "pre_restrict_allowed_resources", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6908,8 +6923,9 @@ def test_delete_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6966,13 +6982,13 @@ def test_delete_workload_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_delete_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_delete_workload" + ) as pre, + ): pre.assert_not_called() pb_message = assuredworkloads.DeleteWorkloadRequest.pb( assuredworkloads.DeleteWorkloadRequest() @@ -7017,8 +7033,9 @@ def test_get_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7106,18 +7123,20 @@ def test_get_workload_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "post_get_workload" - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_get_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_get_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "post_get_workload" + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_get_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_get_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7170,8 +7189,9 @@ def test_list_workloads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7234,18 +7254,20 @@ def test_list_workloads_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "post_list_workloads" - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_list_workloads_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_list_workloads" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "post_list_workloads" + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_list_workloads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_list_workloads" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7341,8 +7363,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7405,8 +7428,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7730,11 +7754,14 @@ def test_assured_workloads_service_base_transport(): def test_assured_workloads_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.assuredworkloads_v1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.assuredworkloads_v1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssuredWorkloadsServiceTransport( @@ -7751,9 +7778,12 @@ def test_assured_workloads_service_base_transport_with_credentials_file(): def test_assured_workloads_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.assuredworkloads_v1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.assuredworkloads_v1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssuredWorkloadsServiceTransport() @@ -7827,11 +7857,12 @@ def test_assured_workloads_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8495,6 +8526,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AssuredWorkloadsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AssuredWorkloadsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AssuredWorkloadsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8640,6 +8705,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AssuredWorkloadsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AssuredWorkloadsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AssuredWorkloadsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py b/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py index 5b24dbfafa1b..9e00c4a87a1b 100644 --- a/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py +++ b/packages/google-cloud-assured-workloads/tests/unit/gapic/assuredworkloads_v1beta1/test_assured_workloads_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssuredWorkloadsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): AssuredWorkloadsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AssuredWorkloadsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1354,11 +1359,13 @@ def test_assured_workloads_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4739,8 +4746,9 @@ def test_create_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4899,20 +4907,21 @@ def test_create_workload_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "post_create_workload" - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_create_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_create_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "post_create_workload" + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_create_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_create_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4977,8 +4986,9 @@ def test_restrict_allowed_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5040,20 +5050,22 @@ def test_restrict_allowed_resources_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_restrict_allowed_resources", - ) as post, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "post_restrict_allowed_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, - "pre_restrict_allowed_resources", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_restrict_allowed_resources", + ) as post, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "post_restrict_allowed_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, + "pre_restrict_allowed_resources", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5111,8 +5123,9 @@ def test_delete_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5169,13 +5182,13 @@ def test_delete_workload_rest_interceptors(null_interceptor): ) client = AssuredWorkloadsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssuredWorkloadsServiceRestInterceptor, "pre_delete_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssuredWorkloadsServiceRestInterceptor, "pre_delete_workload" + ) as pre, + ): pre.assert_not_called() pb_message = assuredworkloads.DeleteWorkloadRequest.pb( assuredworkloads.DeleteWorkloadRequest() @@ -5258,8 +5271,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5322,8 +5336,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5605,11 +5620,14 @@ def test_assured_workloads_service_base_transport(): def test_assured_workloads_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssuredWorkloadsServiceTransport( @@ -5626,9 +5644,12 @@ def test_assured_workloads_service_base_transport_with_credentials_file(): def test_assured_workloads_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service.transports.AssuredWorkloadsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssuredWorkloadsServiceTransport() @@ -5702,11 +5723,12 @@ def test_assured_workloads_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6333,6 +6355,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AssuredWorkloadsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AssuredWorkloadsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AssuredWorkloadsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6478,6 +6534,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AssuredWorkloadsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AssuredWorkloadsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AssuredWorkloadsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/async_client.py b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/async_client.py index e5ac0c3f65fe..edad540a3b99 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/async_client.py +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> AuditManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1387,7 +1387,7 @@ async def sample_list_controls(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1413,8 +1413,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1423,7 +1427,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1431,7 +1435,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1442,7 +1446,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1468,8 +1472,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1478,7 +1486,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1486,7 +1494,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1497,7 +1505,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1527,8 +1535,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1537,7 +1549,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1545,7 +1557,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1553,7 +1565,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1582,8 +1594,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1592,7 +1608,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1600,7 +1616,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1608,7 +1624,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1634,8 +1650,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1644,7 +1664,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1652,7 +1672,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1663,7 +1683,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1689,8 +1709,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1699,7 +1723,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1707,7 +1731,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/client.py b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/client.py index 5f26f5173c7f..c0e3d5851533 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/client.py +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/client.py @@ -115,7 +115,7 @@ class AuditManagerClient(metaclass=AuditManagerClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -547,7 +551,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -644,7 +648,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -740,7 +744,7 @@ def __init__( self._universe_domain = AuditManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1900,7 +1904,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1926,8 +1930,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1936,7 +1944,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1945,7 +1953,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1959,7 +1967,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1985,8 +1993,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1995,7 +2007,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2004,7 +2016,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2018,7 +2030,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2048,8 +2060,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2058,7 +2074,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2066,7 +2082,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2074,7 +2090,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2103,8 +2119,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2113,7 +2133,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2121,7 +2141,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2129,7 +2149,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2155,8 +2175,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2165,7 +2189,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2174,7 +2198,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2188,7 +2212,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2214,8 +2238,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2224,7 +2252,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2233,7 +2261,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/README.rst b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/README.rst index 5d1011d8c90d..12be96284408 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/README.rst +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AuditManagerTransport` is the ABC for all transports. -- public child `AuditManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AuditManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAuditManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AuditManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AuditManagerTransport`` is the ABC for all transports. + +- public child ``AuditManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AuditManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAuditManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AuditManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/base.py b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/base.py index 214c9caab529..2555353e6a1b 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/base.py +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc.py b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc.py index e7f281f74d8b..f27e46a75d3a 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc.py +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc_asyncio.py b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc_asyncio.py index ef4d79603dda..e8690839f181 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/rest.py b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/rest.py index a1b39574358c..7dd4d9b76e7f 100644 --- a/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/rest.py +++ b/packages/google-cloud-auditmanager/google/cloud/auditmanager_v1/services/audit_manager/transports/rest.py @@ -753,6 +753,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AuditManagerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-auditmanager/noxfile.py b/packages/google-cloud-auditmanager/noxfile.py index 412af68838b3..5f59386b2beb 100644 --- a/packages/google-cloud-auditmanager/noxfile.py +++ b/packages/google-cloud-auditmanager/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-auditmanager/setup.py b/packages/google-cloud-auditmanager/setup.py index 9bb9bc40a203..0051664dbbbc 100644 --- a/packages/google-cloud-auditmanager/setup.py +++ b/packages/google-cloud-auditmanager/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-auditmanager" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-auditmanager/testing/constraints-3.7.txt b/packages/google-cloud-auditmanager/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-auditmanager/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-auditmanager/testing/constraints-3.8.txt b/packages/google-cloud-auditmanager/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-auditmanager/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-auditmanager/testing/constraints-3.9.txt b/packages/google-cloud-auditmanager/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-auditmanager/testing/constraints-3.9.txt +++ b/packages/google-cloud-auditmanager/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-auditmanager/tests/unit/gapic/auditmanager_v1/test_audit_manager.py b/packages/google-cloud-auditmanager/tests/unit/gapic/auditmanager_v1/test_audit_manager.py index 3989a99eba5e..e40119dca113 100644 --- a/packages/google-cloud-auditmanager/tests/unit/gapic/auditmanager_v1/test_audit_manager.py +++ b/packages/google-cloud-auditmanager/tests/unit/gapic/auditmanager_v1/test_audit_manager.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AuditManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AuditManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AuditManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1264,11 +1269,13 @@ def test_audit_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7046,8 +7053,9 @@ def test_enroll_resource_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7110,17 +7118,19 @@ def test_enroll_resource_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_enroll_resource" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_enroll_resource_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_enroll_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_enroll_resource" + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_enroll_resource_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_enroll_resource" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7173,8 +7183,9 @@ def test_generate_audit_scope_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7238,18 +7249,20 @@ def test_generate_audit_scope_report_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_generate_audit_scope_report" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, - "post_generate_audit_scope_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_generate_audit_scope_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_generate_audit_scope_report" + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_generate_audit_scope_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_generate_audit_scope_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7304,8 +7317,9 @@ def test_generate_audit_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7362,20 +7376,21 @@ def test_generate_audit_report_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AuditManagerRestInterceptor, "post_generate_audit_report" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, - "post_generate_audit_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_generate_audit_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_generate_audit_report" + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_generate_audit_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_generate_audit_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7428,8 +7443,9 @@ def test_list_audit_reports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7492,17 +7508,20 @@ def test_list_audit_reports_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_list_audit_reports" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_list_audit_reports_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_list_audit_reports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_list_audit_reports" + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_list_audit_reports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_list_audit_reports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7560,8 +7579,9 @@ def test_get_audit_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7639,17 +7659,20 @@ def test_get_audit_report_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_get_audit_report" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_get_audit_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_get_audit_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_get_audit_report" + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_get_audit_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_get_audit_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7704,8 +7727,9 @@ def test_get_resource_enrollment_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7779,18 +7803,21 @@ def test_get_resource_enrollment_status_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_get_resource_enrollment_status" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, - "post_get_resource_enrollment_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_get_resource_enrollment_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_get_resource_enrollment_status", + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_get_resource_enrollment_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_get_resource_enrollment_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7848,8 +7875,9 @@ def test_list_resource_enrollment_statuses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7914,18 +7942,22 @@ def test_list_resource_enrollment_statuses_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_list_resource_enrollment_statuses" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, - "post_list_resource_enrollment_statuses_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_list_resource_enrollment_statuses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_list_resource_enrollment_statuses", + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "post_list_resource_enrollment_statuses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, + "pre_list_resource_enrollment_statuses", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7983,8 +8015,9 @@ def test_list_controls_rest_bad_request(request_type=auditmanager.ListControlsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8049,17 +8082,19 @@ def test_list_controls_rest_interceptors(null_interceptor): ) client = AuditManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_list_controls" - ) as post, mock.patch.object( - transports.AuditManagerRestInterceptor, "post_list_controls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditManagerRestInterceptor, "pre_list_controls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_list_controls" + ) as post, + mock.patch.object( + transports.AuditManagerRestInterceptor, "post_list_controls_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AuditManagerRestInterceptor, "pre_list_controls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8114,8 +8149,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8174,8 +8210,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8236,8 +8273,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8298,8 +8336,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8360,8 +8399,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8422,8 +8462,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8736,11 +8777,14 @@ def test_audit_manager_base_transport(): def test_audit_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.auditmanager_v1.services.audit_manager.transports.AuditManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.auditmanager_v1.services.audit_manager.transports.AuditManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuditManagerTransport( @@ -8757,9 +8801,12 @@ def test_audit_manager_base_transport_with_credentials_file(): def test_audit_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.auditmanager_v1.services.audit_manager.transports.AuditManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.auditmanager_v1.services.audit_manager.transports.AuditManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuditManagerTransport() @@ -8831,11 +8878,12 @@ def test_audit_manager_transport_auth_gdch_credentials(transport_class): def test_audit_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9577,6 +9625,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AuditManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AuditManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AuditManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9716,6 +9796,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AuditManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AuditManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AuditManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9861,6 +9973,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AuditManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AuditManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AuditManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10006,6 +10152,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AuditManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AuditManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AuditManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10151,6 +10331,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AuditManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AuditManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AuditManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10292,6 +10506,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AuditManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AuditManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AuditManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/async_client.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/async_client.py index 49fb7e0d75bf..a1e1e4366cce 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/async_client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/async_client.py @@ -219,7 +219,7 @@ def transport(self) -> AutoMlTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/client.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/client.py index 677fe4964d6c..1d6708caf698 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/client.py @@ -147,7 +147,7 @@ class AutoMlClient(metaclass=AutoMlClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -155,7 +155,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -165,6 +165,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -542,7 +546,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -639,7 +643,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -735,7 +739,7 @@ def __init__( self._universe_domain = AutoMlClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/README.rst b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/README.rst index 23f3112ee6dd..113bf9360944 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/README.rst +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutoMlTransport` is the ABC for all transports. -- public child `AutoMlGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutoMlGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutoMlRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutoMlRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutoMlTransport`` is the ABC for all transports. + +- public child ``AutoMlGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutoMlGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutoMlRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutoMlRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/base.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/base.py index c9cb3efd7b4b..41ccfd129704 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/base.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc.py index 519e3d429798..9a37c4bfd001 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -207,6 +207,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py index 7906f12fbd92..fda6cb07b20f 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -258,6 +258,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/rest.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/rest.py index f8d997ef53a6..667d943ab348 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/rest.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/auto_ml/transports/rest.py @@ -1140,6 +1140,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutoMlRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/async_client.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/async_client.py index d1d6ff118f02..565550a1576d 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/async_client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> PredictionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/client.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/client.py index 91a1ba11e732..8046b4b8a7ec 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/client.py @@ -121,7 +121,7 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -446,7 +450,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -543,7 +547,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = PredictionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/README.rst b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/README.rst index 504aaca0a144..409d7c7b9f70 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/README.rst +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PredictionServiceTransport` is the ABC for all transports. -- public child `PredictionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PredictionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePredictionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PredictionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PredictionServiceTransport`` is the ABC for all transports. + +- public child ``PredictionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PredictionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePredictionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PredictionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/base.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/base.py index f1741e52ab9e..811e2f4329e3 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/base.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc.py index bba1dea2a238..12e41f8afe1f 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py index 82117c69796d..c10b4f7dd915 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/rest.py b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/rest.py index d70eb1dc1422..c29bb528e734 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/rest.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1/services/prediction_service/transports/rest.py @@ -263,6 +263,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PredictionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/async_client.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/async_client.py index d9ea016c12d1..bbc60a196714 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/async_client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/async_client.py @@ -231,7 +231,7 @@ def transport(self) -> AutoMlTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/client.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/client.py index a5369ac90190..f98b10ed1186 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/client.py @@ -155,7 +155,7 @@ class AutoMlClient(metaclass=AutoMlClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -163,7 +163,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -173,6 +173,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -600,7 +604,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -697,7 +701,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -793,7 +797,7 @@ def __init__( self._universe_domain = AutoMlClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/README.rst b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/README.rst index 23f3112ee6dd..113bf9360944 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/README.rst +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutoMlTransport` is the ABC for all transports. -- public child `AutoMlGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutoMlGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutoMlRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutoMlRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutoMlTransport`` is the ABC for all transports. + +- public child ``AutoMlGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutoMlGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutoMlRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutoMlRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py index ce1c05664a4e..45491768ec56 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/base.py @@ -92,6 +92,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -141,6 +145,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py index 565f764ca60d..8e2bb67e3176 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc.py @@ -66,7 +66,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -210,6 +210,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py index 67e2e92ddced..e0d9e25f08c0 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/grpc_asyncio.py @@ -72,7 +72,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -107,7 +107,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -261,6 +261,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/rest.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/rest.py index 75408d107828..f919bbadfe85 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/rest.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/auto_ml/transports/rest.py @@ -1473,6 +1473,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutoMlRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/async_client.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/async_client.py index 7cae58f6a893..1b7f0dc86888 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/async_client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> PredictionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/client.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/client.py index 9d1a32f09425..7656bca7ec1f 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/client.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/client.py @@ -121,7 +121,7 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -446,7 +450,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -543,7 +547,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = PredictionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/README.rst b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/README.rst index 504aaca0a144..409d7c7b9f70 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/README.rst +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PredictionServiceTransport` is the ABC for all transports. -- public child `PredictionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PredictionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePredictionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PredictionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PredictionServiceTransport`` is the ABC for all transports. + +- public child ``PredictionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PredictionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePredictionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PredictionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py index eeea7c02063b..58481bd6e64b 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py index fad7578f4d01..f1f36efecd48 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py index 6ba6e3e1c425..3fb17567774d 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/rest.py b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/rest.py index 92d5dadad104..a1729cd5e4cc 100644 --- a/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/rest.py +++ b/packages/google-cloud-automl/google/cloud/automl_v1beta1/services/prediction_service/transports/rest.py @@ -263,6 +263,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PredictionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-automl/noxfile.py b/packages/google-cloud-automl/noxfile.py index 76ec344aa9b2..51f8e3e9bfad 100644 --- a/packages/google-cloud-automl/noxfile.py +++ b/packages/google-cloud-automl/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -107,6 +106,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -298,7 +299,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -528,7 +532,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -623,7 +627,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-automl/setup.py b/packages/google-cloud-automl/setup.py index bb9e00f8924f..0181879ab948 100644 --- a/packages/google-cloud-automl/setup.py +++ b/packages/google-cloud-automl/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,11 +47,11 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = { "libcst": "libcst >= 0.2.5", - "pandas": ["pandas>=1.0.5"], + "pandas": ["pandas>=1.1.3"], "storage": ["google-cloud-storage >=1.18.0, <4.0.0"], } @@ -84,8 +84,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -97,7 +95,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-automl/testing/constraints-3.7.txt b/packages/google-cloud-automl/testing/constraints-3.7.txt deleted file mode 100644 index 7f4c319c0d27..000000000000 --- a/packages/google-cloud-automl/testing/constraints-3.7.txt +++ /dev/null @@ -1,17 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-cloud-storage==1.18.0 -libcst==0.2.5 -pandas==1.0.5 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-automl/testing/constraints-3.8.txt b/packages/google-cloud-automl/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-automl/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-automl/testing/constraints-3.9.txt b/packages/google-cloud-automl/testing/constraints-3.9.txt index 7599dea499ed..3efe38d86000 100644 --- a/packages/google-cloud-automl/testing/constraints-3.9.txt +++ b/packages/google-cloud-automl/testing/constraints-3.9.txt @@ -1,10 +1,16 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-cloud-storage==1.18.0 +libcst==0.2.5 +pandas==1.1.3 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_auto_ml.py b/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_auto_ml.py index 9cd5581d4379..85020d51d6c8 100644 --- a/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_auto_ml.py +++ b/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_auto_ml.py @@ -144,6 +144,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutoMlClient._get_default_mtls_endpoint(None) is None assert AutoMlClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -159,6 +160,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AutoMlClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AutoMlClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1237,11 +1239,13 @@ def test_auto_ml_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12638,8 +12642,9 @@ def test_create_dataset_rest_bad_request(request_type=service.CreateDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12779,19 +12784,20 @@ def test_create_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_create_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_dataset" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_create_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12840,8 +12846,9 @@ def test_get_dataset_rest_bad_request(request_type=service.GetDatasetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12910,17 +12917,15 @@ def test_get_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoMlRestInterceptor, "post_get_dataset") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_get_dataset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12969,8 +12974,9 @@ def test_list_datasets_rest_bad_request(request_type=service.ListDatasetsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13031,17 +13037,17 @@ def test_list_datasets_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_datasets" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_datasets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_datasets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_datasets" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_datasets_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_list_datasets") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13094,8 +13100,9 @@ def test_update_dataset_rest_bad_request(request_type=service.UpdateDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13251,17 +13258,19 @@ def test_update_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_update_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_dataset" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_update_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13310,8 +13319,9 @@ def test_delete_dataset_rest_bad_request(request_type=service.DeleteDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13366,19 +13376,20 @@ def test_delete_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_delete_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_dataset" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_delete_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13427,8 +13438,9 @@ def test_import_data_rest_bad_request(request_type=service.ImportDataRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13483,19 +13495,16 @@ def test_import_data_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_import_data" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_import_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_import_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AutoMlRestInterceptor, "post_import_data") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_import_data_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_import_data") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13544,8 +13553,9 @@ def test_export_data_rest_bad_request(request_type=service.ExportDataRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13600,19 +13610,16 @@ def test_export_data_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_data" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_export_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AutoMlRestInterceptor, "post_export_data") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_data_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_export_data") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13665,8 +13672,9 @@ def test_get_annotation_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13733,17 +13741,19 @@ def test_get_annotation_spec_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_annotation_spec" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_annotation_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_annotation_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_annotation_spec" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_annotation_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_get_annotation_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13796,8 +13806,9 @@ def test_create_model_rest_bad_request(request_type=service.CreateModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13954,19 +13965,18 @@ def test_create_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_create_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_create_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14015,8 +14025,9 @@ def test_get_model_rest_bad_request(request_type=service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14085,17 +14096,15 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoMlRestInterceptor, "post_get_model") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_get_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14144,8 +14153,9 @@ def test_list_models_rest_bad_request(request_type=service.ListModelsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14206,17 +14216,15 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoMlRestInterceptor, "post_list_models") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_list_models") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14265,8 +14273,9 @@ def test_delete_model_rest_bad_request(request_type=service.DeleteModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14321,19 +14330,18 @@ def test_delete_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_delete_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_delete_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14384,8 +14392,9 @@ def test_update_model_rest_bad_request(request_type=service.UpdateModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14558,17 +14567,17 @@ def test_update_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_update_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_update_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14617,8 +14626,9 @@ def test_deploy_model_rest_bad_request(request_type=service.DeployModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14673,19 +14683,18 @@ def test_deploy_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_deploy_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_deploy_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_deploy_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_deploy_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_deploy_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_deploy_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14734,8 +14743,9 @@ def test_undeploy_model_rest_bad_request(request_type=service.UndeployModelReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14790,19 +14800,20 @@ def test_undeploy_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_undeploy_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_undeploy_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_undeploy_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_undeploy_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_undeploy_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_undeploy_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14851,8 +14862,9 @@ def test_export_model_rest_bad_request(request_type=service.ExportModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14907,19 +14919,18 @@ def test_export_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_export_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_export_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14972,8 +14983,9 @@ def test_get_model_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15042,17 +15054,19 @@ def test_get_model_evaluation_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model_evaluation" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model_evaluation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_model_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_model_evaluation" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_model_evaluation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_get_model_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15107,8 +15121,9 @@ def test_list_model_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15169,17 +15184,20 @@ def test_list_model_evaluations_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_model_evaluations" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_model_evaluations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_model_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_model_evaluations" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, + "post_list_model_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_list_model_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15691,11 +15709,14 @@ def test_auto_ml_base_transport(): def test_auto_ml_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport( @@ -15712,9 +15733,12 @@ def test_auto_ml_base_transport_with_credentials_file(): def test_auto_ml_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.automl_v1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport() @@ -15786,11 +15810,12 @@ def test_auto_ml_transport_auth_gdch_credentials(transport_class): def test_auto_ml_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_prediction_service.py b/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_prediction_service.py index 1c40af9c7363..604b4a7e6d94 100644 --- a/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_prediction_service.py +++ b/packages/google-cloud-automl/tests/unit/gapic/automl_v1/test_prediction_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PredictionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): PredictionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PredictionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_prediction_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2722,8 +2729,9 @@ def test_predict_rest_bad_request(request_type=prediction_service.PredictRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2783,17 +2791,19 @@ def test_predict_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_predict" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_predict" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2848,8 +2858,9 @@ def test_batch_predict_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2906,19 +2917,21 @@ def test_batch_predict_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_batch_predict" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_batch_predict_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_batch_predict" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_batch_predict" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, + "post_batch_predict_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_batch_predict" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3083,11 +3096,14 @@ def test_prediction_service_base_transport(): def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( @@ -3104,9 +3120,12 @@ def test_prediction_service_base_transport_with_credentials_file(): def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.automl_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport() @@ -3178,11 +3197,12 @@ def test_prediction_service_transport_auth_gdch_credentials(transport_class): def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_auto_ml.py b/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_auto_ml.py index 2bdf970e04fd..17adbaf502f2 100644 --- a/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_auto_ml.py +++ b/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_auto_ml.py @@ -153,6 +153,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutoMlClient._get_default_mtls_endpoint(None) is None assert AutoMlClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -168,6 +169,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AutoMlClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AutoMlClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1246,11 +1248,13 @@ def test_auto_ml_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -16643,8 +16647,9 @@ def test_create_dataset_rest_bad_request(request_type=service.CreateDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16807,17 +16812,19 @@ def test_create_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_create_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_dataset" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_create_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16866,8 +16873,9 @@ def test_get_dataset_rest_bad_request(request_type=service.GetDatasetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16936,17 +16944,15 @@ def test_get_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoMlRestInterceptor, "post_get_dataset") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_get_dataset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16995,8 +17001,9 @@ def test_list_datasets_rest_bad_request(request_type=service.ListDatasetsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17057,17 +17064,17 @@ def test_list_datasets_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_datasets" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_datasets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_datasets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_datasets" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_datasets_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_list_datasets") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17120,8 +17127,9 @@ def test_update_dataset_rest_bad_request(request_type=service.UpdateDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17286,17 +17294,19 @@ def test_update_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_update_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_dataset" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_update_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17345,8 +17355,9 @@ def test_delete_dataset_rest_bad_request(request_type=service.DeleteDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17401,19 +17412,20 @@ def test_delete_dataset_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_dataset" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_delete_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_dataset" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_delete_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17462,8 +17474,9 @@ def test_import_data_rest_bad_request(request_type=service.ImportDataRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17518,19 +17531,16 @@ def test_import_data_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_import_data" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_import_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_import_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AutoMlRestInterceptor, "post_import_data") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_import_data_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_import_data") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17579,8 +17589,9 @@ def test_export_data_rest_bad_request(request_type=service.ExportDataRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17635,19 +17646,16 @@ def test_export_data_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_data" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_export_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AutoMlRestInterceptor, "post_export_data") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_data_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_export_data") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17700,8 +17708,9 @@ def test_get_annotation_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17768,17 +17777,19 @@ def test_get_annotation_spec_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_annotation_spec" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_annotation_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_annotation_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_annotation_spec" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_annotation_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_get_annotation_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17833,8 +17844,9 @@ def test_get_table_spec_rest_bad_request(request_type=service.GetTableSpecReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17907,17 +17919,19 @@ def test_get_table_spec_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_table_spec" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_table_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_table_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_table_spec" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_table_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_get_table_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17966,8 +17980,9 @@ def test_list_table_specs_rest_bad_request(request_type=service.ListTableSpecsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18028,17 +18043,19 @@ def test_list_table_specs_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_table_specs" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_table_specs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_table_specs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_table_specs" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_table_specs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_list_table_specs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18095,8 +18112,9 @@ def test_update_table_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18255,17 +18273,19 @@ def test_update_table_spec_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_table_spec" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_table_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_update_table_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_table_spec" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_table_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_update_table_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18316,8 +18336,9 @@ def test_get_column_spec_rest_bad_request(request_type=service.GetColumnSpecRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18384,17 +18405,19 @@ def test_get_column_spec_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_column_spec" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_column_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_column_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_column_spec" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_column_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_get_column_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18447,8 +18470,9 @@ def test_list_column_specs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18511,17 +18535,19 @@ def test_list_column_specs_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_column_specs" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_column_specs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_column_specs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_column_specs" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_column_specs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_list_column_specs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18578,8 +18604,9 @@ def test_update_column_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18753,17 +18780,19 @@ def test_update_column_spec_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_column_spec" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_update_column_spec_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_update_column_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_column_spec" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_update_column_spec_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_update_column_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18814,8 +18843,9 @@ def test_create_model_rest_bad_request(request_type=service.CreateModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19028,19 +19058,18 @@ def test_create_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_create_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_create_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_create_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_create_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19089,8 +19118,9 @@ def test_get_model_rest_bad_request(request_type=service.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19157,17 +19187,15 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoMlRestInterceptor, "post_get_model") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_get_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19216,8 +19244,9 @@ def test_list_models_rest_bad_request(request_type=service.ListModelsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19278,17 +19307,15 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoMlRestInterceptor, "post_list_models") as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_list_models") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19337,8 +19364,9 @@ def test_delete_model_rest_bad_request(request_type=service.DeleteModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19393,19 +19421,18 @@ def test_delete_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_delete_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_delete_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_delete_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_delete_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19454,8 +19481,9 @@ def test_deploy_model_rest_bad_request(request_type=service.DeployModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19510,19 +19538,18 @@ def test_deploy_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_deploy_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_deploy_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_deploy_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_deploy_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_deploy_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_deploy_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19571,8 +19598,9 @@ def test_undeploy_model_rest_bad_request(request_type=service.UndeployModelReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19627,19 +19655,20 @@ def test_undeploy_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_undeploy_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_undeploy_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_undeploy_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_undeploy_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_undeploy_model_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_undeploy_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19688,8 +19717,9 @@ def test_export_model_rest_bad_request(request_type=service.ExportModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19744,19 +19774,18 @@ def test_export_model_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_model" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_export_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_model" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoMlRestInterceptor, "pre_export_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19807,8 +19836,9 @@ def test_export_evaluated_examples_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19863,19 +19893,21 @@ def test_export_evaluated_examples_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_evaluated_examples" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_export_evaluated_examples_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_export_evaluated_examples" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutoMlRestInterceptor, "post_export_evaluated_examples" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, + "post_export_evaluated_examples_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_export_evaluated_examples" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19930,8 +19962,9 @@ def test_get_model_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20000,17 +20033,19 @@ def test_get_model_evaluation_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model_evaluation" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_get_model_evaluation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_get_model_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_model_evaluation" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_get_model_evaluation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_get_model_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20065,8 +20100,9 @@ def test_list_model_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20127,17 +20163,20 @@ def test_list_model_evaluations_rest_interceptors(null_interceptor): ) client = AutoMlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_model_evaluations" - ) as post, mock.patch.object( - transports.AutoMlRestInterceptor, "post_list_model_evaluations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoMlRestInterceptor, "pre_list_model_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoMlRestInterceptor, "post_list_model_evaluations" + ) as post, + mock.patch.object( + transports.AutoMlRestInterceptor, + "post_list_model_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoMlRestInterceptor, "pre_list_model_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20783,11 +20822,14 @@ def test_auto_ml_base_transport(): def test_auto_ml_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport( @@ -20804,9 +20846,12 @@ def test_auto_ml_base_transport_with_credentials_file(): def test_auto_ml_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.automl_v1beta1.services.auto_ml.transports.AutoMlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoMlTransport() @@ -20878,11 +20923,12 @@ def test_auto_ml_transport_auth_gdch_credentials(transport_class): def test_auto_ml_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_prediction_service.py b/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_prediction_service.py index f6b4f614702d..5761dae4fe1f 100644 --- a/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_prediction_service.py +++ b/packages/google-cloud-automl/tests/unit/gapic/automl_v1beta1/test_prediction_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PredictionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): PredictionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PredictionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1331,11 +1336,13 @@ def test_prediction_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2724,8 +2731,9 @@ def test_predict_rest_bad_request(request_type=prediction_service.PredictRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2785,17 +2793,19 @@ def test_predict_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_predict" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_predict_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_predict" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2850,8 +2860,9 @@ def test_batch_predict_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2908,19 +2919,21 @@ def test_batch_predict_rest_interceptors(null_interceptor): ) client = PredictionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_batch_predict" - ) as post, mock.patch.object( - transports.PredictionServiceRestInterceptor, "post_batch_predict_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PredictionServiceRestInterceptor, "pre_batch_predict" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PredictionServiceRestInterceptor, "post_batch_predict" + ) as post, + mock.patch.object( + transports.PredictionServiceRestInterceptor, + "post_batch_predict_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PredictionServiceRestInterceptor, "pre_batch_predict" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3085,11 +3098,14 @@ def test_prediction_service_base_transport(): def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( @@ -3106,9 +3122,12 @@ def test_prediction_service_base_transport_with_credentials_file(): def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.automl_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport() @@ -3180,11 +3199,12 @@ def test_prediction_service_transport_auth_gdch_credentials(transport_class): def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/async_client.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/async_client.py index 99ad992f38f3..9446254ffa63 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/async_client.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/async_client.py @@ -238,7 +238,7 @@ def transport(self) -> BackupDRTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5266,7 +5266,7 @@ async def sample_initialize_service(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5292,8 +5292,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5302,7 +5306,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5310,7 +5314,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5321,7 +5325,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5347,8 +5351,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5357,7 +5365,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5365,7 +5373,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5376,7 +5384,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5406,8 +5414,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5416,7 +5428,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5424,7 +5436,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5432,7 +5444,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5461,8 +5473,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5471,7 +5487,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5479,7 +5495,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5487,7 +5503,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5579,8 +5595,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5589,7 +5609,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5597,7 +5619,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5608,7 +5630,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5701,8 +5723,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5711,7 +5737,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5719,7 +5747,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5730,7 +5758,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5761,8 +5789,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5773,7 +5805,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5781,7 +5815,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5792,7 +5826,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5818,8 +5852,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5828,7 +5866,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5836,7 +5874,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5847,7 +5885,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5873,8 +5911,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5883,7 +5925,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5891,7 +5933,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/client.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/client.py index f42c939c1c81..aac05040f4a5 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/client.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/client.py @@ -134,7 +134,7 @@ class BackupDRClient(metaclass=BackupDRClientMeta): """The BackupDR Service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -142,7 +142,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -152,6 +152,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -736,7 +740,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -833,7 +837,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -929,7 +933,7 @@ def __init__( self._universe_domain = BackupDRClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5869,7 +5873,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5895,8 +5899,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5905,7 +5913,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5914,7 +5922,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5928,7 +5936,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5954,8 +5962,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5964,7 +5976,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5973,7 +5985,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5987,7 +5999,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6017,8 +6029,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6027,7 +6043,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6035,7 +6051,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6043,7 +6059,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6072,8 +6088,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6082,7 +6102,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6090,7 +6110,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6098,7 +6118,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6190,8 +6210,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6200,7 +6224,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6209,7 +6235,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6223,7 +6249,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6316,8 +6342,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6326,7 +6356,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6335,7 +6367,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6349,7 +6381,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6380,8 +6412,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6390,7 +6426,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6399,7 +6437,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6413,7 +6451,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6439,8 +6477,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6449,7 +6491,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6458,7 +6500,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6472,7 +6514,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6498,8 +6540,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6508,7 +6554,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6517,7 +6563,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/README.rst b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/README.rst index 036cdee4bde3..209e6400429c 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/README.rst +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackupDRTransport` is the ABC for all transports. -- public child `BackupDRGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackupDRGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackupDRRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackupDRRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackupDRTransport`` is the ABC for all transports. + +- public child ``BackupDRGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackupDRGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackupDRRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackupDRRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/base.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/base.py index 5c9e5c0a0fc9..e877cf30711e 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/base.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/base.py @@ -92,6 +92,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -141,6 +145,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc.py index df4cf7cfd250..619aec85c42b 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc.py @@ -66,7 +66,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc_asyncio.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc_asyncio.py index 3c9f1d0ff52e..2c1b003817c5 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc_asyncio.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/grpc_asyncio.py @@ -72,7 +72,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -107,7 +107,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/rest.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/rest.py index 2d8802ec5030..18d7298dff9a 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/rest.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr/transports/rest.py @@ -2492,6 +2492,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackupDRRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/async_client.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/async_client.py index 2f1c2898c82f..f445290c7102 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/async_client.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/async_client.py @@ -208,7 +208,7 @@ def transport(self) -> BackupDrProtectionSummaryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -453,7 +453,7 @@ async def sample_list_resource_backup_configs(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -479,8 +479,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -489,7 +493,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -497,7 +501,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -508,7 +512,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -534,8 +538,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -544,7 +552,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -552,7 +560,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -563,7 +571,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -593,8 +601,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -603,7 +615,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -611,7 +623,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -619,7 +631,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -648,8 +660,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -658,7 +674,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -666,7 +682,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -674,7 +690,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -766,8 +782,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -776,7 +796,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -784,7 +806,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -795,7 +817,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -888,8 +910,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -898,7 +924,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -906,7 +934,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -917,7 +945,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -948,8 +976,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -960,7 +992,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -968,7 +1002,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -979,7 +1013,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1005,8 +1039,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1015,7 +1053,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1023,7 +1061,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1034,7 +1072,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1060,8 +1098,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1070,7 +1112,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1078,7 +1120,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/client.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/client.py index 064a8487af0d..1b7d994ce3aa 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/client.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/client.py @@ -116,7 +116,7 @@ class BackupDrProtectionSummaryClient(metaclass=BackupDrProtectionSummaryClientM """The Protection Summary service.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -642,7 +646,7 @@ def __init__( self._universe_domain = BackupDrProtectionSummaryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -884,7 +888,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -910,8 +914,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -920,7 +928,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -929,7 +937,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -943,7 +951,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -969,8 +977,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -979,7 +991,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -988,7 +1000,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1002,7 +1014,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1032,8 +1044,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1042,7 +1058,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1050,7 +1066,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1058,7 +1074,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1087,8 +1103,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1097,7 +1117,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1105,7 +1125,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1113,7 +1133,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1205,8 +1225,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1215,7 +1239,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1224,7 +1250,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1238,7 +1264,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1331,8 +1357,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1341,7 +1371,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1350,7 +1382,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1396,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1395,8 +1427,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1405,7 +1441,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1414,7 +1452,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1428,7 +1466,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1454,8 +1492,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1464,7 +1506,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1473,7 +1515,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1487,7 +1529,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1513,8 +1555,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1523,7 +1569,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1532,7 +1578,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/README.rst b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/README.rst index 7ae8c4a8e36c..272fcea48f88 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/README.rst +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackupDrProtectionSummaryTransport` is the ABC for all transports. -- public child `BackupDrProtectionSummaryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackupDrProtectionSummaryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackupDrProtectionSummaryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackupDrProtectionSummaryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackupDrProtectionSummaryTransport`` is the ABC for all transports. + +- public child ``BackupDrProtectionSummaryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackupDrProtectionSummaryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackupDrProtectionSummaryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackupDrProtectionSummaryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/base.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/base.py index c6b3a6493f84..4df1b6bc6d8b 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/base.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc.py index 517ebfe9ec32..c005240d8bfb 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc_asyncio.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc_asyncio.py index 803f4b9ad8b5..8ae3be154ee8 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc_asyncio.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/rest.py b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/rest.py index f3c0a6984b67..6998300593e1 100644 --- a/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/rest.py +++ b/packages/google-cloud-backupdr/google/cloud/backupdr_v1/services/backup_dr_protection_summary/transports/rest.py @@ -431,6 +431,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackupDrProtectionSummaryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-backupdr/noxfile.py b/packages/google-cloud-backupdr/noxfile.py index 597b9f95a4af..daafed70afb3 100644 --- a/packages/google-cloud-backupdr/noxfile.py +++ b/packages/google-cloud-backupdr/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-backupdr/setup.py b/packages/google-cloud-backupdr/setup.py index 3a16698a5d71..088566b5c42f 100644 --- a/packages/google-cloud-backupdr/setup.py +++ b/packages/google-cloud-backupdr/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-backupdr/testing/constraints-3.7.txt b/packages/google-cloud-backupdr/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-backupdr/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-backupdr/testing/constraints-3.8.txt b/packages/google-cloud-backupdr/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-backupdr/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-backupdr/testing/constraints-3.9.txt b/packages/google-cloud-backupdr/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-backupdr/testing/constraints-3.9.txt +++ b/packages/google-cloud-backupdr/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr.py b/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr.py index 2a9e0aa992fc..575f89c54f7f 100644 --- a/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr.py +++ b/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr.py @@ -150,6 +150,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackupDRClient._get_default_mtls_endpoint(None) is None assert BackupDRClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -166,6 +167,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BackupDRClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert BackupDRClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1255,11 +1257,13 @@ def test_backup_dr_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -27037,8 +27041,9 @@ def test_list_management_servers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27101,17 +27106,20 @@ def test_list_management_servers_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_management_servers" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_management_servers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_management_servers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_management_servers" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_list_management_servers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_management_servers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27171,8 +27179,9 @@ def test_get_management_server_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27249,17 +27258,20 @@ def test_get_management_server_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_management_server" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_management_server_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_management_server" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_management_server" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_get_management_server_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_management_server" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27312,8 +27324,9 @@ def test_create_management_server_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27459,20 +27472,21 @@ def test_create_management_server_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_create_management_server" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_create_management_server_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_create_management_server" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_create_management_server" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_create_management_server_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_create_management_server" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27527,8 +27541,9 @@ def test_delete_management_server_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27585,20 +27600,21 @@ def test_delete_management_server_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_management_server" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_delete_management_server_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_delete_management_server" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_management_server" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_delete_management_server_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_delete_management_server" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27651,8 +27667,9 @@ def test_create_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27794,19 +27811,20 @@ def test_create_backup_vault_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_create_backup_vault" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_create_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_create_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_create_backup_vault" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_create_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_create_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27859,8 +27877,9 @@ def test_list_backup_vaults_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27923,17 +27942,19 @@ def test_list_backup_vaults_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backup_vaults" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backup_vaults_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_backup_vaults" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backup_vaults" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backup_vaults_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_backup_vaults" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27991,8 +28012,9 @@ def test_fetch_usable_backup_vaults_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28055,18 +28077,20 @@ def test_fetch_usable_backup_vaults_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_fetch_usable_backup_vaults" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_fetch_usable_backup_vaults_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_fetch_usable_backup_vaults" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_fetch_usable_backup_vaults" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_fetch_usable_backup_vaults_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_fetch_usable_backup_vaults" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28124,8 +28148,9 @@ def test_get_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28212,17 +28237,19 @@ def test_get_backup_vault_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_vault" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_vault" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28279,8 +28306,9 @@ def test_update_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28426,19 +28454,20 @@ def test_update_backup_vault_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup_vault" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_update_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup_vault" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_update_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28491,8 +28520,9 @@ def test_delete_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28547,19 +28577,20 @@ def test_delete_backup_vault_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup_vault" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_delete_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup_vault" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_delete_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28612,8 +28643,9 @@ def test_list_data_sources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28676,17 +28708,19 @@ def test_list_data_sources_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_data_sources" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_data_sources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_data_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_data_sources" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_data_sources_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_data_sources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28746,8 +28780,9 @@ def test_get_data_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28822,17 +28857,19 @@ def test_get_data_source_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_data_source" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_data_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_data_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_data_source" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_data_source_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_data_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28889,8 +28926,9 @@ def test_update_data_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29096,19 +29134,20 @@ def test_update_data_source_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_data_source" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_data_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_update_data_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_data_source" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_data_source_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_update_data_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29161,8 +29200,9 @@ def test_list_backups_rest_bad_request(request_type=backupvault.ListBackupsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29227,17 +29267,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29292,8 +29334,9 @@ def test_fetch_backups_for_resource_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29356,18 +29399,20 @@ def test_fetch_backups_for_resource_type_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_fetch_backups_for_resource_type" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_fetch_backups_for_resource_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_fetch_backups_for_resource_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_fetch_backups_for_resource_type" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_fetch_backups_for_resource_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_fetch_backups_for_resource_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29425,8 +29470,9 @@ def test_get_backup_rest_bad_request(request_type=backupvault.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29510,17 +29556,17 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackupDRRestInterceptor, "pre_get_backup") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29573,8 +29619,9 @@ def test_update_backup_rest_bad_request(request_type=backupvault.UpdateBackupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29878,19 +29925,20 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_update_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29943,8 +29991,9 @@ def test_delete_backup_rest_bad_request(request_type=backupvault.DeleteBackupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30001,19 +30050,20 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30066,8 +30116,9 @@ def test_restore_backup_rest_bad_request(request_type=backupvault.RestoreBackupR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30124,19 +30175,20 @@ def test_restore_backup_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_restore_backup" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_restore_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_restore_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_restore_backup" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_restore_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_restore_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30189,8 +30241,9 @@ def test_create_backup_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30350,19 +30403,20 @@ def test_create_backup_plan_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_create_backup_plan" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_create_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_create_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_create_backup_plan" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_create_backup_plan_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_create_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30419,8 +30473,9 @@ def test_update_backup_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30584,19 +30639,20 @@ def test_update_backup_plan_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup_plan" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_update_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup_plan" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup_plan_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_update_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30647,8 +30703,9 @@ def test_get_backup_plan_rest_bad_request(request_type=backupplan.GetBackupPlanR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30729,17 +30786,19 @@ def test_get_backup_plan_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_plan" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_plan" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_plan_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30792,8 +30851,9 @@ def test_list_backup_plans_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30856,17 +30916,19 @@ def test_list_backup_plans_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backup_plans" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backup_plans_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_backup_plans" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backup_plans" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backup_plans_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_backup_plans" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30921,8 +30983,9 @@ def test_delete_backup_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30977,19 +31040,20 @@ def test_delete_backup_plan_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup_plan" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_delete_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup_plan" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup_plan_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_delete_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31044,8 +31108,9 @@ def test_get_backup_plan_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31112,18 +31177,20 @@ def test_get_backup_plan_revision_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_plan_revision" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_get_backup_plan_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_backup_plan_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_plan_revision" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_get_backup_plan_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_backup_plan_revision" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31178,8 +31245,9 @@ def test_list_backup_plan_revisions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31242,18 +31310,20 @@ def test_list_backup_plan_revisions_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backup_plan_revisions" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_list_backup_plan_revisions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_backup_plan_revisions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backup_plan_revisions" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_list_backup_plan_revisions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_backup_plan_revisions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31311,8 +31381,9 @@ def test_create_backup_plan_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31470,20 +31541,21 @@ def test_create_backup_plan_association_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_create_backup_plan_association" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_create_backup_plan_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_create_backup_plan_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_create_backup_plan_association" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_create_backup_plan_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_create_backup_plan_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31540,8 +31612,9 @@ def test_update_backup_plan_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31703,20 +31776,21 @@ def test_update_backup_plan_association_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_update_backup_plan_association" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_update_backup_plan_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_update_backup_plan_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_update_backup_plan_association" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_update_backup_plan_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_update_backup_plan_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31771,8 +31845,9 @@ def test_get_backup_plan_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31849,18 +31924,20 @@ def test_get_backup_plan_association_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_backup_plan_association" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_get_backup_plan_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_backup_plan_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_backup_plan_association" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_get_backup_plan_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_backup_plan_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31918,8 +31995,9 @@ def test_list_backup_plan_associations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31984,18 +32062,20 @@ def test_list_backup_plan_associations_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_backup_plan_associations" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_list_backup_plan_associations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_backup_plan_associations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_backup_plan_associations" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_list_backup_plan_associations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_backup_plan_associations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32053,8 +32133,9 @@ def test_fetch_backup_plan_associations_for_resource_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32125,20 +32206,22 @@ def test_fetch_backup_plan_associations_for_resource_type_rest_interceptors( ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_fetch_backup_plan_associations_for_resource_type", - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_fetch_backup_plan_associations_for_resource_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, - "pre_fetch_backup_plan_associations_for_resource_type", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_fetch_backup_plan_associations_for_resource_type", + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_fetch_backup_plan_associations_for_resource_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, + "pre_fetch_backup_plan_associations_for_resource_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32202,8 +32285,9 @@ def test_delete_backup_plan_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32260,20 +32344,21 @@ def test_delete_backup_plan_association_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_delete_backup_plan_association" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_delete_backup_plan_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_delete_backup_plan_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_delete_backup_plan_association" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_delete_backup_plan_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_delete_backup_plan_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32328,8 +32413,9 @@ def test_trigger_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32386,19 +32472,20 @@ def test_trigger_backup_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_trigger_backup" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_trigger_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_trigger_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_trigger_backup" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_trigger_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_trigger_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32453,8 +32540,9 @@ def test_get_data_source_reference_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32527,18 +32615,20 @@ def test_get_data_source_reference_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_get_data_source_reference" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_get_data_source_reference_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_get_data_source_reference" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_get_data_source_reference" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_get_data_source_reference_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_get_data_source_reference" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32596,8 +32686,9 @@ def test_list_data_source_references_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32662,18 +32753,20 @@ def test_list_data_source_references_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, "post_list_data_source_references" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_list_data_source_references_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_list_data_source_references" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_list_data_source_references" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_list_data_source_references_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_list_data_source_references" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32731,8 +32824,9 @@ def test_fetch_data_source_references_for_resource_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32801,20 +32895,22 @@ def test_fetch_data_source_references_for_resource_type_rest_interceptors( ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_fetch_data_source_references_for_resource_type", - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, - "post_fetch_data_source_references_for_resource_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, - "pre_fetch_data_source_references_for_resource_type", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_fetch_data_source_references_for_resource_type", + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, + "post_fetch_data_source_references_for_resource_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, + "pre_fetch_data_source_references_for_resource_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32876,8 +32972,9 @@ def test_initialize_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32932,19 +33029,20 @@ def test_initialize_service_rest_interceptors(null_interceptor): ) client = BackupDRClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupDRRestInterceptor, "post_initialize_service" - ) as post, mock.patch.object( - transports.BackupDRRestInterceptor, "post_initialize_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupDRRestInterceptor, "pre_initialize_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupDRRestInterceptor, "post_initialize_service" + ) as post, + mock.patch.object( + transports.BackupDRRestInterceptor, "post_initialize_service_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupDRRestInterceptor, "pre_initialize_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32997,8 +33095,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33057,8 +33156,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33120,8 +33220,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33185,8 +33286,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33250,8 +33352,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33314,8 +33417,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33376,8 +33480,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33438,8 +33543,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33500,8 +33606,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34478,11 +34585,14 @@ def test_backup_dr_base_transport(): def test_backup_dr_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.backupdr_v1.services.backup_dr.transports.BackupDRTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.backupdr_v1.services.backup_dr.transports.BackupDRTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackupDRTransport( @@ -34499,9 +34609,12 @@ def test_backup_dr_base_transport_with_credentials_file(): def test_backup_dr_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.backupdr_v1.services.backup_dr.transports.BackupDRTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.backupdr_v1.services.backup_dr.transports.BackupDRTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackupDRTransport() @@ -34573,11 +34686,12 @@ def test_backup_dr_transport_auth_gdch_credentials(transport_class): def test_backup_dr_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -35619,6 +35733,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BackupDRClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -35758,6 +35904,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BackupDRClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -35903,6 +36081,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BackupDRClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36048,6 +36260,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BackupDRClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36193,6 +36439,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BackupDRClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36334,6 +36614,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BackupDRClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36498,6 +36812,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = BackupDRClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36665,6 +37014,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = BackupDRClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36842,6 +37226,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = BackupDRClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = BackupDRAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = BackupDRClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr_protection_summary.py b/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr_protection_summary.py index cad216b14248..b445e21c2ea1 100644 --- a/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr_protection_summary.py +++ b/packages/google-cloud-backupdr/tests/unit/gapic/backupdr_v1/test_backup_dr_protection_summary.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackupDrProtectionSummaryClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): BackupDrProtectionSummaryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BackupDrProtectionSummaryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1366,11 +1371,13 @@ def test_backup_dr_protection_summary_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2411,8 +2418,9 @@ def test_list_resource_backup_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2477,20 +2485,22 @@ def test_list_resource_backup_configs_rest_interceptors(null_interceptor): ) client = BackupDrProtectionSummaryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupDrProtectionSummaryRestInterceptor, - "post_list_resource_backup_configs", - ) as post, mock.patch.object( - transports.BackupDrProtectionSummaryRestInterceptor, - "post_list_resource_backup_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupDrProtectionSummaryRestInterceptor, - "pre_list_resource_backup_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupDrProtectionSummaryRestInterceptor, + "post_list_resource_backup_configs", + ) as post, + mock.patch.object( + transports.BackupDrProtectionSummaryRestInterceptor, + "post_list_resource_backup_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupDrProtectionSummaryRestInterceptor, + "pre_list_resource_backup_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2548,8 +2558,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2608,8 +2619,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2671,8 +2683,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2736,8 +2749,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2801,8 +2815,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2865,8 +2880,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2927,8 +2943,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2989,8 +3006,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3051,8 +3069,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3191,11 +3210,14 @@ def test_backup_dr_protection_summary_base_transport(): def test_backup_dr_protection_summary_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.backupdr_v1.services.backup_dr_protection_summary.transports.BackupDrProtectionSummaryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.backupdr_v1.services.backup_dr_protection_summary.transports.BackupDrProtectionSummaryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackupDrProtectionSummaryTransport( @@ -3212,9 +3234,12 @@ def test_backup_dr_protection_summary_base_transport_with_credentials_file(): def test_backup_dr_protection_summary_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.backupdr_v1.services.backup_dr_protection_summary.transports.BackupDrProtectionSummaryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.backupdr_v1.services.backup_dr_protection_summary.transports.BackupDrProtectionSummaryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackupDrProtectionSummaryTransport() @@ -3288,11 +3313,12 @@ def test_backup_dr_protection_summary_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3863,6 +3889,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BackupDrProtectionSummaryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4002,6 +4060,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BackupDrProtectionSummaryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4147,6 +4237,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BackupDrProtectionSummaryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4292,6 +4416,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BackupDrProtectionSummaryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4437,6 +4595,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BackupDrProtectionSummaryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4582,6 +4774,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BackupDrProtectionSummaryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4746,6 +4972,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = BackupDrProtectionSummaryClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4913,6 +5174,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = BackupDrProtectionSummaryClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5090,6 +5386,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = BackupDrProtectionSummaryClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = BackupDrProtectionSummaryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = BackupDrProtectionSummaryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/async_client.py b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/async_client.py index 0abd612cb99b..4c607aa34a6f 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/async_client.py +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/async_client.py @@ -282,7 +282,7 @@ def transport(self) -> BareMetalSolutionTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5829,7 +5829,7 @@ async def sample_list_os_images(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5855,8 +5855,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5865,7 +5869,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5873,7 +5877,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5884,7 +5888,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5910,8 +5914,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5920,7 +5928,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5928,7 +5936,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/client.py b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/client.py index 8d4db1088095..3431dd633891 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/client.py +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/client.py @@ -150,7 +150,7 @@ class BareMetalSolutionClient(metaclass=BareMetalSolutionClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -158,7 +158,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -168,6 +168,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -809,7 +813,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -906,7 +910,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1006,7 +1010,7 @@ def __init__( self._universe_domain = BareMetalSolutionClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6431,7 +6435,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6457,8 +6461,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6467,7 +6475,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6476,7 +6484,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6490,7 +6498,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6516,8 +6524,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6526,7 +6538,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6535,7 +6547,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/README.rst b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/README.rst index bdd872eef937..ef89dd84714f 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/README.rst +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BareMetalSolutionTransport` is the ABC for all transports. -- public child `BareMetalSolutionGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BareMetalSolutionGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBareMetalSolutionRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BareMetalSolutionRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BareMetalSolutionTransport`` is the ABC for all transports. + +- public child ``BareMetalSolutionGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BareMetalSolutionGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBareMetalSolutionRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BareMetalSolutionRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/base.py b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/base.py index 9a6dc18d16c9..f48bba567c58 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/base.py +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/base.py @@ -105,6 +105,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -154,6 +158,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc.py b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc.py index c06656bd6543..52a50f2dc6b4 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc.py +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc.py @@ -79,7 +79,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -114,7 +114,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -217,6 +217,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc_asyncio.py b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc_asyncio.py index bdbf31bf9182..70a1df058914 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc_asyncio.py +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/grpc_asyncio.py @@ -85,7 +85,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -120,7 +120,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -268,6 +268,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/rest.py b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/rest.py index 4f4016ccdc63..c2689c6ae558 100644 --- a/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/rest.py +++ b/packages/google-cloud-bare-metal-solution/google/cloud/bare_metal_solution_v2/services/bare_metal_solution/transports/rest.py @@ -2573,6 +2573,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BareMetalSolutionRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bare-metal-solution/noxfile.py b/packages/google-cloud-bare-metal-solution/noxfile.py index cfb29482e61d..31a1ffcb31c9 100644 --- a/packages/google-cloud-bare-metal-solution/noxfile.py +++ b/packages/google-cloud-bare-metal-solution/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bare-metal-solution/setup.py b/packages/google-cloud-bare-metal-solution/setup.py index b66fbfa072b5..5472508b7e74 100644 --- a/packages/google-cloud-bare-metal-solution/setup.py +++ b/packages/google-cloud-bare-metal-solution/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bare-metal-solution/testing/constraints-3.7.txt b/packages/google-cloud-bare-metal-solution/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bare-metal-solution/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bare-metal-solution/testing/constraints-3.8.txt b/packages/google-cloud-bare-metal-solution/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bare-metal-solution/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bare-metal-solution/testing/constraints-3.9.txt b/packages/google-cloud-bare-metal-solution/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bare-metal-solution/testing/constraints-3.9.txt +++ b/packages/google-cloud-bare-metal-solution/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bare-metal-solution/tests/unit/gapic/bare_metal_solution_v2/test_bare_metal_solution.py b/packages/google-cloud-bare-metal-solution/tests/unit/gapic/bare_metal_solution_v2/test_bare_metal_solution.py index 928e8c443e7f..06e1915174a4 100644 --- a/packages/google-cloud-bare-metal-solution/tests/unit/gapic/bare_metal_solution_v2/test_bare_metal_solution.py +++ b/packages/google-cloud-bare-metal-solution/tests/unit/gapic/bare_metal_solution_v2/test_bare_metal_solution.py @@ -153,6 +153,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BareMetalSolutionClient._get_default_mtls_endpoint(None) is None assert ( @@ -175,6 +176,10 @@ def test__get_default_mtls_endpoint(): BareMetalSolutionClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BareMetalSolutionClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_bare_metal_solution_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -29587,8 +29594,9 @@ def test_list_instances_rest_bad_request(request_type=instance.ListInstancesRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29653,17 +29661,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29714,8 +29725,9 @@ def test_get_instance_rest_bad_request(request_type=instance.GetInstanceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29800,17 +29812,20 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_get_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29863,8 +29878,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30119,20 +30135,21 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_update_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_update_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30183,8 +30200,9 @@ def test_rename_instance_rest_bad_request(request_type=instance.RenameInstanceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30269,18 +30287,20 @@ def test_rename_instance_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_rename_instance" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_rename_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_rename_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_rename_instance" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_rename_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_rename_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30329,8 +30349,9 @@ def test_reset_instance_rest_bad_request(request_type=instance.ResetInstanceRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30387,19 +30408,21 @@ def test_reset_instance_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_reset_instance" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_reset_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_reset_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_reset_instance" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_reset_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_reset_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30448,8 +30471,9 @@ def test_start_instance_rest_bad_request(request_type=instance.StartInstanceRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30506,19 +30530,21 @@ def test_start_instance_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_start_instance" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_start_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_start_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_start_instance" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_start_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_start_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30567,8 +30593,9 @@ def test_stop_instance_rest_bad_request(request_type=instance.StopInstanceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30625,19 +30652,21 @@ def test_stop_instance_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_stop_instance" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_stop_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_stop_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_stop_instance" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_stop_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_stop_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30688,8 +30717,9 @@ def test_enable_interactive_serial_console_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30746,22 +30776,23 @@ def test_enable_interactive_serial_console_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_enable_interactive_serial_console", - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_enable_interactive_serial_console_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "pre_enable_interactive_serial_console", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_enable_interactive_serial_console", + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_enable_interactive_serial_console_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "pre_enable_interactive_serial_console", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30814,8 +30845,9 @@ def test_disable_interactive_serial_console_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30872,22 +30904,23 @@ def test_disable_interactive_serial_console_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_disable_interactive_serial_console", - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_disable_interactive_serial_console_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "pre_disable_interactive_serial_console", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_disable_interactive_serial_console", + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_disable_interactive_serial_console_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "pre_disable_interactive_serial_console", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30938,8 +30971,9 @@ def test_detach_lun_rest_bad_request(request_type=gcb_instance.DetachLunRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30996,19 +31030,20 @@ def test_detach_lun_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_detach_lun" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_detach_lun_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_detach_lun" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_detach_lun" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_detach_lun_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_detach_lun" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31057,8 +31092,9 @@ def test_list_ssh_keys_rest_bad_request(request_type=ssh_key.ListSSHKeysRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31121,17 +31157,20 @@ def test_list_ssh_keys_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_ssh_keys" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_ssh_keys_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_ssh_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_ssh_keys" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_ssh_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_ssh_keys" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31182,8 +31221,9 @@ def test_create_ssh_key_rest_bad_request(request_type=gcb_ssh_key.CreateSSHKeyRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31316,17 +31356,20 @@ def test_create_ssh_key_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_create_ssh_key" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_create_ssh_key_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_create_ssh_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_create_ssh_key" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_create_ssh_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_create_ssh_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31377,8 +31420,9 @@ def test_delete_ssh_key_rest_bad_request(request_type=ssh_key.DeleteSSHKeyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31435,13 +31479,13 @@ def test_delete_ssh_key_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_delete_ssh_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_delete_ssh_key" + ) as pre, + ): pre.assert_not_called() pb_message = ssh_key.DeleteSSHKeyRequest.pb(ssh_key.DeleteSSHKeyRequest()) transcode.return_value = { @@ -31482,8 +31526,9 @@ def test_list_volumes_rest_bad_request(request_type=volume.ListVolumesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31548,17 +31593,20 @@ def test_list_volumes_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_volumes" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_volumes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_volumes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_volumes" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_volumes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_volumes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31607,8 +31655,9 @@ def test_get_volume_rest_bad_request(request_type=volume.GetVolumeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31717,17 +31766,19 @@ def test_get_volume_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_volume" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_volume" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_volume_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_volume" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31778,8 +31829,9 @@ def test_update_volume_rest_bad_request(request_type=gcb_volume.UpdateVolumeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31936,19 +31988,21 @@ def test_update_volume_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_volume" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_update_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_update_volume" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_update_volume_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_update_volume" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31997,8 +32051,9 @@ def test_rename_volume_rest_bad_request(request_type=volume.RenameVolumeRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32107,17 +32162,20 @@ def test_rename_volume_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_rename_volume" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_rename_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_rename_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_rename_volume" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_rename_volume_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_rename_volume" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32166,8 +32224,9 @@ def test_evict_volume_rest_bad_request(request_type=volume.EvictVolumeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32224,19 +32283,21 @@ def test_evict_volume_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_evict_volume" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_evict_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_evict_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_evict_volume" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_evict_volume_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_evict_volume" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32285,8 +32346,9 @@ def test_resize_volume_rest_bad_request(request_type=gcb_volume.ResizeVolumeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32343,19 +32405,21 @@ def test_resize_volume_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_resize_volume" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_resize_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_resize_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_resize_volume" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_resize_volume_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_resize_volume" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32404,8 +32468,9 @@ def test_list_networks_rest_bad_request(request_type=network.ListNetworksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32470,17 +32535,20 @@ def test_list_networks_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_networks" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_networks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_networks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_networks" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_networks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_networks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32533,8 +32601,9 @@ def test_list_network_usage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32594,18 +32663,20 @@ def test_list_network_usage_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_network_usage" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_list_network_usage_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_network_usage" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_network_usage" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_network_usage_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_network_usage" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32658,8 +32729,9 @@ def test_get_network_rest_bad_request(request_type=network.GetNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32744,17 +32816,20 @@ def test_get_network_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_network" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_network" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_get_network_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32805,8 +32880,9 @@ def test_update_network_rest_bad_request(request_type=gcb_network.UpdateNetworkR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32978,19 +33054,21 @@ def test_update_network_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_network" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_update_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_update_network" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_update_network_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_update_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33043,8 +33121,9 @@ def test_create_volume_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33192,18 +33271,20 @@ def test_create_volume_snapshot_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_create_volume_snapshot" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_create_volume_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_create_volume_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_create_volume_snapshot" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_create_volume_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_create_volume_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33260,8 +33341,9 @@ def test_restore_volume_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33320,20 +33402,21 @@ def test_restore_volume_snapshot_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_restore_volume_snapshot" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_restore_volume_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_restore_volume_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_restore_volume_snapshot" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_restore_volume_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_restore_volume_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33388,8 +33471,9 @@ def test_delete_volume_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33448,13 +33532,13 @@ def test_delete_volume_snapshot_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_delete_volume_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_delete_volume_snapshot" + ) as pre, + ): pre.assert_not_called() pb_message = volume_snapshot.DeleteVolumeSnapshotRequest.pb( volume_snapshot.DeleteVolumeSnapshotRequest() @@ -33501,8 +33585,9 @@ def test_get_volume_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33575,18 +33660,20 @@ def test_get_volume_snapshot_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_volume_snapshot" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_get_volume_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_volume_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_volume_snapshot" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_get_volume_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_volume_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33641,8 +33728,9 @@ def test_list_volume_snapshots_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33707,18 +33795,20 @@ def test_list_volume_snapshots_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_volume_snapshots" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_list_volume_snapshots_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_volume_snapshots" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_volume_snapshots" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_volume_snapshots_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_volume_snapshots" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33776,8 +33866,9 @@ def test_get_lun_rest_bad_request(request_type=lun.GetLunRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33862,17 +33953,19 @@ def test_get_lun_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_lun" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_lun_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_lun" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_lun" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_lun_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_lun" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33921,8 +34014,9 @@ def test_list_luns_rest_bad_request(request_type=lun.ListLunsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33987,17 +34081,19 @@ def test_list_luns_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_luns" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_luns_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_luns" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_luns" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_luns_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_luns" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34048,8 +34144,9 @@ def test_evict_lun_rest_bad_request(request_type=lun.EvictLunRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34108,19 +34205,20 @@ def test_evict_lun_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_evict_lun" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_evict_lun_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_evict_lun" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_evict_lun" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_evict_lun_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_evict_lun" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34169,8 +34267,9 @@ def test_get_nfs_share_rest_bad_request(request_type=nfs_share.GetNfsShareReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34245,17 +34344,20 @@ def test_get_nfs_share_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_nfs_share" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_nfs_share_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_nfs_share" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_nfs_share" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_get_nfs_share_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_nfs_share" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34304,8 +34406,9 @@ def test_list_nfs_shares_rest_bad_request(request_type=nfs_share.ListNfsSharesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34370,18 +34473,20 @@ def test_list_nfs_shares_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_nfs_shares" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_list_nfs_shares_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_nfs_shares" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_nfs_shares" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_nfs_shares_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_nfs_shares" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34436,8 +34541,9 @@ def test_update_nfs_share_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34585,20 +34691,21 @@ def test_update_nfs_share_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_nfs_share" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_update_nfs_share_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_update_nfs_share" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_update_nfs_share" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_update_nfs_share_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_update_nfs_share" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34651,8 +34758,9 @@ def test_create_nfs_share_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34798,20 +34906,21 @@ def test_create_nfs_share_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_create_nfs_share" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_create_nfs_share_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_create_nfs_share" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_create_nfs_share" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_create_nfs_share_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_create_nfs_share" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34864,8 +34973,9 @@ def test_rename_nfs_share_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34940,18 +35050,20 @@ def test_rename_nfs_share_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_rename_nfs_share" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_rename_nfs_share_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_rename_nfs_share" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_rename_nfs_share" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_rename_nfs_share_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_rename_nfs_share" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35004,8 +35116,9 @@ def test_delete_nfs_share_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35062,20 +35175,21 @@ def test_delete_nfs_share_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_delete_nfs_share" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_delete_nfs_share_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_delete_nfs_share" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_delete_nfs_share" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_delete_nfs_share_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_delete_nfs_share" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35128,8 +35242,9 @@ def test_list_provisioning_quotas_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35192,18 +35307,20 @@ def test_list_provisioning_quotas_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_provisioning_quotas" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_list_provisioning_quotas_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_provisioning_quotas" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_provisioning_quotas" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_provisioning_quotas_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_provisioning_quotas" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35261,8 +35378,9 @@ def test_submit_provisioning_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35322,18 +35440,22 @@ def test_submit_provisioning_config_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_submit_provisioning_config" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_submit_provisioning_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_submit_provisioning_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_submit_provisioning_config", + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_submit_provisioning_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "pre_submit_provisioning_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35393,8 +35515,9 @@ def test_get_provisioning_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35477,18 +35600,20 @@ def test_get_provisioning_config_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_get_provisioning_config" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_get_provisioning_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_get_provisioning_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_get_provisioning_config" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_get_provisioning_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_get_provisioning_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35543,8 +35668,9 @@ def test_create_provisioning_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35785,18 +35911,22 @@ def test_create_provisioning_config_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_create_provisioning_config" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_create_provisioning_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_create_provisioning_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_create_provisioning_config", + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_create_provisioning_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "pre_create_provisioning_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35855,8 +35985,9 @@ def test_update_provisioning_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36101,18 +36232,22 @@ def test_update_provisioning_config_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_update_provisioning_config" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, - "post_update_provisioning_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_update_provisioning_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_update_provisioning_config", + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_update_provisioning_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "pre_update_provisioning_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36165,8 +36300,9 @@ def test_rename_network_rest_bad_request(request_type=network.RenameNetworkReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36251,17 +36387,20 @@ def test_rename_network_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_rename_network" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_rename_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_rename_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_rename_network" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_rename_network_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_rename_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36310,8 +36449,9 @@ def test_list_os_images_rest_bad_request(request_type=osimage.ListOSImagesReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36374,17 +36514,20 @@ def test_list_os_images_rest_interceptors(null_interceptor): ) client = BareMetalSolutionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_os_images" - ) as post, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "post_list_os_images_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BareMetalSolutionRestInterceptor, "pre_list_os_images" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "post_list_os_images" + ) as post, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, + "post_list_os_images_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BareMetalSolutionRestInterceptor, "pre_list_os_images" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36437,8 +36580,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -36497,8 +36641,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -37579,11 +37724,14 @@ def test_bare_metal_solution_base_transport(): def test_bare_metal_solution_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bare_metal_solution_v2.services.bare_metal_solution.transports.BareMetalSolutionTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bare_metal_solution_v2.services.bare_metal_solution.transports.BareMetalSolutionTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BareMetalSolutionTransport( @@ -37600,9 +37748,12 @@ def test_bare_metal_solution_base_transport_with_credentials_file(): def test_bare_metal_solution_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bare_metal_solution_v2.services.bare_metal_solution.transports.BareMetalSolutionTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bare_metal_solution_v2.services.bare_metal_solution.transports.BareMetalSolutionTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BareMetalSolutionTransport() @@ -37674,11 +37825,12 @@ def test_bare_metal_solution_transport_auth_gdch_credentials(transport_class): def test_bare_metal_solution_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -38830,6 +38982,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BareMetalSolutionClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BareMetalSolutionAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BareMetalSolutionClient( credentials=ga_credentials.AnonymousCredentials(), @@ -38971,6 +39157,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BareMetalSolutionClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BareMetalSolutionAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = BareMetalSolutionClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/async_client.py b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/async_client.py index e010dbbf7d6d..6aea79b7ea89 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/async_client.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> BatchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1149,7 +1149,7 @@ async def sample_list_tasks(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1175,8 +1175,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1185,7 +1189,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1193,7 +1197,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1204,7 +1208,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1230,8 +1234,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1240,7 +1248,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1248,7 +1256,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1259,7 +1267,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1289,8 +1297,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1299,7 +1311,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1307,7 +1319,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1315,7 +1327,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1344,8 +1356,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1354,7 +1370,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1362,7 +1378,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1370,7 +1386,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1396,8 +1412,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1406,7 +1426,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1414,7 +1434,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1425,7 +1445,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1451,8 +1471,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1461,7 +1485,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1469,7 +1493,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/client.py b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/client.py index 5e7e2e959e9a..7731b880e944 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/client.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/client.py @@ -120,7 +120,7 @@ class BatchServiceClient(metaclass=BatchServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -495,7 +499,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -592,7 +596,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -688,7 +692,7 @@ def __init__( self._universe_domain = BatchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1622,7 +1626,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1648,8 +1652,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1658,7 +1666,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1667,7 +1675,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1681,7 +1689,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1707,8 +1715,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1717,7 +1729,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1726,7 +1738,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1740,7 +1752,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1770,8 +1782,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1780,7 +1796,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1788,7 +1804,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1796,7 +1812,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1825,8 +1841,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1835,7 +1855,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1843,7 +1863,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1851,7 +1871,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1877,8 +1897,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1887,7 +1911,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1896,7 +1920,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1910,7 +1934,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1936,8 +1960,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1946,7 +1974,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1955,7 +1983,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/README.rst b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/README.rst index c2f8f5a0e133..3a27c92402ab 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/README.rst +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BatchServiceTransport` is the ABC for all transports. -- public child `BatchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BatchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBatchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BatchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BatchServiceTransport`` is the ABC for all transports. + +- public child ``BatchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BatchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBatchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BatchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/base.py b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/base.py index 84287f55cb27..4f9231d89b58 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/base.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc.py b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc.py index 8f13e650bac7..282a56386d35 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc_asyncio.py b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc_asyncio.py index 92ec9ba09f7b..285a7f61d4d3 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/rest.py b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/rest.py index ffbf6c5e86ac..7ebde796880d 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/rest.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1/services/batch_service/transports/rest.py @@ -662,6 +662,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BatchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/async_client.py b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/async_client.py index 73c9fe543e94..f679027afd37 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/async_client.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> BatchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1952,7 +1952,7 @@ async def sample_update_resource_allowance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1978,8 +1978,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1988,7 +1992,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1996,7 +2000,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2007,7 +2011,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2033,8 +2037,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2043,7 +2051,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2051,7 +2059,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2062,7 +2070,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2092,8 +2100,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2102,7 +2114,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2110,7 +2122,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2118,7 +2130,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2147,8 +2159,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2157,7 +2173,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2165,7 +2181,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2173,7 +2189,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2199,8 +2215,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2209,7 +2229,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2217,7 +2237,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2228,7 +2248,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2254,8 +2274,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2264,7 +2288,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2272,7 +2296,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/client.py b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/client.py index 5623d76e1fa2..3abe53fa7b76 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/client.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/client.py @@ -130,7 +130,7 @@ class BatchServiceClient(metaclass=BatchServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -527,7 +531,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -624,7 +628,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -720,7 +724,7 @@ def __init__( self._universe_domain = BatchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2431,7 +2435,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2457,8 +2461,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2467,7 +2475,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2476,7 +2484,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2490,7 +2498,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2516,8 +2524,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2526,7 +2538,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2535,7 +2547,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2549,7 +2561,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2579,8 +2591,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2589,7 +2605,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2597,7 +2613,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2605,7 +2621,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2634,8 +2650,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2644,7 +2664,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2652,7 +2672,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2660,7 +2680,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2686,8 +2706,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2696,7 +2720,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2705,7 +2729,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2719,7 +2743,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2745,8 +2769,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2755,7 +2783,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2764,7 +2792,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/README.rst b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/README.rst index c2f8f5a0e133..3a27c92402ab 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/README.rst +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BatchServiceTransport` is the ABC for all transports. -- public child `BatchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BatchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBatchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BatchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BatchServiceTransport`` is the ABC for all transports. + +- public child ``BatchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BatchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBatchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BatchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/base.py b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/base.py index f2fa07d23472..84a66c94693f 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/base.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc.py b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc.py index 595616f40a50..3628d1c1cf8b 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc_asyncio.py b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc_asyncio.py index 05c5d268f4dd..f8c6bd9ef820 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/rest.py b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/rest.py index 222b275ed877..a3fbc7cea3d7 100644 --- a/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/rest.py +++ b/packages/google-cloud-batch/google/cloud/batch_v1alpha/services/batch_service/transports/rest.py @@ -1005,6 +1005,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BatchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-batch/noxfile.py b/packages/google-cloud-batch/noxfile.py index cb39b422a6de..fde850c65014 100644 --- a/packages/google-cloud-batch/noxfile.py +++ b/packages/google-cloud-batch/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-batch/setup.py b/packages/google-cloud-batch/setup.py index d823a38b0fe9..8451fbbe0247 100644 --- a/packages/google-cloud-batch/setup.py +++ b/packages/google-cloud-batch/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-batch" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-batch/testing/constraints-3.7.txt b/packages/google-cloud-batch/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-batch/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-batch/testing/constraints-3.8.txt b/packages/google-cloud-batch/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-batch/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-batch/testing/constraints-3.9.txt b/packages/google-cloud-batch/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-batch/testing/constraints-3.9.txt +++ b/packages/google-cloud-batch/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-batch/tests/unit/gapic/batch_v1/test_batch_service.py b/packages/google-cloud-batch/tests/unit/gapic/batch_v1/test_batch_service.py index f5291db13cc0..de7ae702f687 100644 --- a/packages/google-cloud-batch/tests/unit/gapic/batch_v1/test_batch_service.py +++ b/packages/google-cloud-batch/tests/unit/gapic/batch_v1/test_batch_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BatchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BatchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + BatchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1267,11 +1272,13 @@ def test_batch_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5696,8 +5703,9 @@ def test_create_job_rest_bad_request(request_type=batch.CreateJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5997,17 +6005,19 @@ def test_create_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_create_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_create_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_create_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_create_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_create_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_create_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6056,8 +6066,9 @@ def test_get_job_rest_bad_request(request_type=batch.GetJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6124,17 +6135,17 @@ def test_get_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_get_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_job_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BatchServiceRestInterceptor, "pre_get_job") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6183,8 +6194,9 @@ def test_delete_job_rest_bad_request(request_type=batch.DeleteJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6241,19 +6253,20 @@ def test_delete_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BatchServiceRestInterceptor, "post_delete_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_delete_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_delete_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_delete_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_delete_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_delete_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6302,8 +6315,9 @@ def test_cancel_job_rest_bad_request(request_type=batch.CancelJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6360,19 +6374,20 @@ def test_cancel_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BatchServiceRestInterceptor, "post_cancel_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_cancel_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_cancel_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_cancel_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_cancel_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_cancel_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6421,8 +6436,9 @@ def test_list_jobs_rest_bad_request(request_type=batch.ListJobsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6487,17 +6503,19 @@ def test_list_jobs_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_jobs" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_list_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_jobs" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_jobs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_list_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6548,8 +6566,9 @@ def test_get_task_rest_bad_request(request_type=batch.GetTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6614,17 +6633,19 @@ def test_get_task_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_task" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_get_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_task" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_get_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6675,8 +6696,9 @@ def test_list_tasks_rest_bad_request(request_type=batch.ListTasksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6743,17 +6765,19 @@ def test_list_tasks_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_tasks" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_tasks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_list_tasks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_tasks" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_tasks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_list_tasks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6804,8 +6828,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6864,8 +6889,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6926,8 +6952,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6988,8 +7015,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7050,8 +7078,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7112,8 +7141,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7395,11 +7425,14 @@ def test_batch_service_base_transport(): def test_batch_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.batch_v1.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.batch_v1.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BatchServiceTransport( @@ -7416,9 +7449,12 @@ def test_batch_service_base_transport_with_credentials_file(): def test_batch_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.batch_v1.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.batch_v1.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BatchServiceTransport() @@ -7490,11 +7526,12 @@ def test_batch_service_transport_auth_gdch_credentials(transport_class): def test_batch_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8159,6 +8196,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8298,6 +8367,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8443,6 +8544,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8588,6 +8723,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8733,6 +8902,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8874,6 +9077,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-batch/tests/unit/gapic/batch_v1alpha/test_batch_service.py b/packages/google-cloud-batch/tests/unit/gapic/batch_v1alpha/test_batch_service.py index 30aea12fd0fa..a99705a4084f 100644 --- a/packages/google-cloud-batch/tests/unit/gapic/batch_v1alpha/test_batch_service.py +++ b/packages/google-cloud-batch/tests/unit/gapic/batch_v1alpha/test_batch_service.py @@ -141,6 +141,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BatchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -159,6 +160,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BatchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + BatchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1279,11 +1284,13 @@ def test_batch_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9696,8 +9703,9 @@ def test_create_job_rest_bad_request(request_type=batch.CreateJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10033,17 +10041,19 @@ def test_create_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_create_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_create_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_create_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_create_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_create_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_create_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10092,8 +10102,9 @@ def test_get_job_rest_bad_request(request_type=batch.GetJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10162,17 +10173,17 @@ def test_get_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_get_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_job_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BatchServiceRestInterceptor, "pre_get_job") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10221,8 +10232,9 @@ def test_delete_job_rest_bad_request(request_type=batch.DeleteJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10279,19 +10291,20 @@ def test_delete_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BatchServiceRestInterceptor, "post_delete_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_delete_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_delete_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_delete_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_delete_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_delete_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10340,8 +10353,9 @@ def test_cancel_job_rest_bad_request(request_type=batch.CancelJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10398,19 +10412,20 @@ def test_cancel_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BatchServiceRestInterceptor, "post_cancel_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_cancel_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_cancel_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_cancel_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_cancel_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_cancel_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10459,8 +10474,9 @@ def test_update_job_rest_bad_request(request_type=batch.UpdateJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10796,17 +10812,19 @@ def test_update_job_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_update_job" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_update_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_update_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_update_job" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_update_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_update_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10855,8 +10873,9 @@ def test_list_jobs_rest_bad_request(request_type=batch.ListJobsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10921,17 +10940,19 @@ def test_list_jobs_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_jobs" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_list_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_jobs" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_jobs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_list_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10982,8 +11003,9 @@ def test_get_task_rest_bad_request(request_type=batch.GetTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11048,17 +11070,19 @@ def test_get_task_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_task" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_get_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_task" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_get_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11109,8 +11133,9 @@ def test_list_tasks_rest_bad_request(request_type=batch.ListTasksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11177,17 +11202,19 @@ def test_list_tasks_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_tasks" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_tasks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_list_tasks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_tasks" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_tasks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_list_tasks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11238,8 +11265,9 @@ def test_create_resource_allowance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11396,18 +11424,20 @@ def test_create_resource_allowance_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_create_resource_allowance" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, - "post_create_resource_allowance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_create_resource_allowance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_create_resource_allowance" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, + "post_create_resource_allowance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_create_resource_allowance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11467,8 +11497,9 @@ def test_get_resource_allowance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11535,18 +11566,20 @@ def test_get_resource_allowance_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_get_resource_allowance" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, - "post_get_resource_allowance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_get_resource_allowance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_get_resource_allowance" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, + "post_get_resource_allowance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_get_resource_allowance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11606,8 +11639,9 @@ def test_delete_resource_allowance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11666,20 +11700,21 @@ def test_delete_resource_allowance_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BatchServiceRestInterceptor, "post_delete_resource_allowance" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, - "post_delete_resource_allowance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_delete_resource_allowance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_delete_resource_allowance" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, + "post_delete_resource_allowance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_delete_resource_allowance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11732,8 +11767,9 @@ def test_list_resource_allowances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11798,18 +11834,20 @@ def test_list_resource_allowances_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_list_resource_allowances" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, - "post_list_resource_allowances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_list_resource_allowances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_list_resource_allowances" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, + "post_list_resource_allowances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_list_resource_allowances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11871,8 +11909,9 @@ def test_update_resource_allowance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12033,18 +12072,20 @@ def test_update_resource_allowance_rest_interceptors(null_interceptor): ) client = BatchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchServiceRestInterceptor, "post_update_resource_allowance" - ) as post, mock.patch.object( - transports.BatchServiceRestInterceptor, - "post_update_resource_allowance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BatchServiceRestInterceptor, "pre_update_resource_allowance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchServiceRestInterceptor, "post_update_resource_allowance" + ) as post, + mock.patch.object( + transports.BatchServiceRestInterceptor, + "post_update_resource_allowance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BatchServiceRestInterceptor, "pre_update_resource_allowance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12102,8 +12143,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12162,8 +12204,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12224,8 +12267,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12286,8 +12330,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12348,8 +12393,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12410,8 +12456,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12829,11 +12876,14 @@ def test_batch_service_base_transport(): def test_batch_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.batch_v1alpha.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.batch_v1alpha.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BatchServiceTransport( @@ -12850,9 +12900,12 @@ def test_batch_service_base_transport_with_credentials_file(): def test_batch_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.batch_v1alpha.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.batch_v1alpha.services.batch_service.transports.BatchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BatchServiceTransport() @@ -12924,11 +12977,12 @@ def test_batch_service_transport_auth_gdch_credentials(transport_class): def test_batch_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13639,6 +13693,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13778,6 +13864,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13923,6 +14041,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14068,6 +14220,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14213,6 +14399,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14354,6 +14574,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BatchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BatchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = BatchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/async_client.py b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/async_client.py index 868376907a47..6438ff0d8992 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/async_client.py +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/async_client.py @@ -227,7 +227,7 @@ def transport(self) -> AppConnectionsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1179,7 +1179,7 @@ async def sample_resolve_app_connections(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1205,8 +1205,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1215,7 +1219,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1223,7 +1227,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1234,7 +1238,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1260,8 +1264,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1270,7 +1278,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1278,7 +1286,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1289,7 +1297,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1319,8 +1327,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1329,7 +1341,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1337,7 +1349,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1345,7 +1357,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1374,8 +1386,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1384,7 +1400,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1392,7 +1408,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1400,7 +1416,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1492,8 +1508,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1502,7 +1522,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1510,7 +1532,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1521,7 +1543,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1614,8 +1636,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1624,7 +1650,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1632,7 +1660,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1643,7 +1671,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1674,8 +1702,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1686,7 +1718,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1694,7 +1728,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1705,7 +1739,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1731,8 +1765,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1741,7 +1779,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1749,7 +1787,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1760,7 +1798,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1786,8 +1824,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1796,7 +1838,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1804,7 +1846,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/client.py b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/client.py index 26eb8c6f6440..b95547cb3851 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/client.py +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/client.py @@ -137,7 +137,7 @@ class AppConnectionsServiceClient(metaclass=AppConnectionsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -145,7 +145,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -155,6 +155,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -508,7 +512,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -607,7 +611,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -707,7 +711,7 @@ def __init__( self._universe_domain = AppConnectionsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1639,7 +1643,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1665,8 +1669,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1675,7 +1683,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1684,7 +1692,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1698,7 +1706,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1724,8 +1732,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1734,7 +1746,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1743,7 +1755,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1757,7 +1769,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1787,8 +1799,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1797,7 +1813,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1805,7 +1821,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1813,7 +1829,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1842,8 +1858,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1852,7 +1872,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1860,7 +1880,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1868,7 +1888,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1960,8 +1980,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1970,7 +1994,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1979,7 +2005,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1993,7 +2019,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2086,8 +2112,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2096,7 +2126,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2105,7 +2137,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2119,7 +2151,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2150,8 +2182,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2160,7 +2196,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2169,7 +2207,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2183,7 +2221,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2209,8 +2247,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2219,7 +2261,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2228,7 +2270,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2242,7 +2284,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2268,8 +2310,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2278,7 +2324,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2287,7 +2333,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/README.rst b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/README.rst index 5e6e3e418c62..b9bec28bee67 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/README.rst +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AppConnectionsServiceTransport` is the ABC for all transports. -- public child `AppConnectionsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AppConnectionsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAppConnectionsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AppConnectionsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AppConnectionsServiceTransport`` is the ABC for all transports. + +- public child ``AppConnectionsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AppConnectionsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAppConnectionsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AppConnectionsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/base.py b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/base.py index fb96e37a108b..a24becdd7bd0 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/base.py +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc.py b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc.py index 961829ba523e..cbc2122acaa8 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc.py +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -203,6 +203,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc_asyncio.py b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc_asyncio.py index 2e5e0314b7b9..e9284125342a 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -254,6 +254,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/rest.py b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/rest.py index a0082f4281cc..814da82529ef 100644 --- a/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/rest.py +++ b/packages/google-cloud-beyondcorp-appconnections/google/cloud/beyondcorp_appconnections_v1/services/app_connections_service/transports/rest.py @@ -732,6 +732,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AppConnectionsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-beyondcorp-appconnections/noxfile.py b/packages/google-cloud-beyondcorp-appconnections/noxfile.py index 0d2cdcb2fbcd..5d04e2e37cc2 100644 --- a/packages/google-cloud-beyondcorp-appconnections/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnections/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-beyondcorp-appconnections/setup.py b/packages/google-cloud-beyondcorp-appconnections/setup.py index f9867faf267d..cdefc11f3000 100644 --- a/packages/google-cloud-beyondcorp-appconnections/setup.py +++ b/packages/google-cloud-beyondcorp-appconnections/setup.py @@ -43,7 +43,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -51,7 +51,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -84,8 +84,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -97,7 +95,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.7.txt b/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.8.txt b/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.9.txt b/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.9.txt +++ b/packages/google-cloud-beyondcorp-appconnections/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-appconnections/tests/unit/gapic/beyondcorp_appconnections_v1/test_app_connections_service.py b/packages/google-cloud-beyondcorp-appconnections/tests/unit/gapic/beyondcorp_appconnections_v1/test_app_connections_service.py index 513ed99f8df8..b7275c44ef60 100644 --- a/packages/google-cloud-beyondcorp-appconnections/tests/unit/gapic/beyondcorp_appconnections_v1/test_app_connections_service.py +++ b/packages/google-cloud-beyondcorp-appconnections/tests/unit/gapic/beyondcorp_appconnections_v1/test_app_connections_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AppConnectionsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): AppConnectionsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AppConnectionsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1356,11 +1361,13 @@ def test_app_connections_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5758,8 +5765,9 @@ def test_list_app_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5826,18 +5834,20 @@ def test_list_app_connections_rest_interceptors(null_interceptor): ) client = AppConnectionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "post_list_app_connections" - ) as post, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, - "post_list_app_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "pre_list_app_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "post_list_app_connections" + ) as post, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_list_app_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "pre_list_app_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5895,8 +5905,9 @@ def test_get_app_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5969,18 +5980,20 @@ def test_get_app_connection_rest_interceptors(null_interceptor): ) client = AppConnectionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "post_get_app_connection" - ) as post, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, - "post_get_app_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "pre_get_app_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "post_get_app_connection" + ) as post, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_get_app_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "pre_get_app_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6038,8 +6051,9 @@ def test_create_app_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6183,20 +6197,22 @@ def test_create_app_connection_rest_interceptors(null_interceptor): ) client = AppConnectionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "post_create_app_connection" - ) as post, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, - "post_create_app_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "pre_create_app_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_create_app_connection", + ) as post, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_create_app_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "pre_create_app_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6253,8 +6269,9 @@ def test_update_app_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6402,20 +6419,22 @@ def test_update_app_connection_rest_interceptors(null_interceptor): ) client = AppConnectionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "post_update_app_connection" - ) as post, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, - "post_update_app_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "pre_update_app_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_update_app_connection", + ) as post, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_update_app_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "pre_update_app_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6468,8 +6487,9 @@ def test_delete_app_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6526,20 +6546,22 @@ def test_delete_app_connection_rest_interceptors(null_interceptor): ) client = AppConnectionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "post_delete_app_connection" - ) as post, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, - "post_delete_app_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "pre_delete_app_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_delete_app_connection", + ) as post, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_delete_app_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, "pre_delete_app_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6592,8 +6614,9 @@ def test_resolve_app_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6660,18 +6683,22 @@ def test_resolve_app_connections_rest_interceptors(null_interceptor): ) client = AppConnectionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "post_resolve_app_connections" - ) as post, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, - "post_resolve_app_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectionsServiceRestInterceptor, "pre_resolve_app_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_resolve_app_connections", + ) as post, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "post_resolve_app_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectionsServiceRestInterceptor, + "pre_resolve_app_connections", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6729,8 +6756,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6789,8 +6817,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6852,8 +6881,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6917,8 +6947,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6982,8 +7013,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7046,8 +7078,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7108,8 +7141,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7170,8 +7204,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7232,8 +7267,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7509,11 +7545,14 @@ def test_app_connections_service_base_transport(): def test_app_connections_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.beyondcorp_appconnections_v1.services.app_connections_service.transports.AppConnectionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.beyondcorp_appconnections_v1.services.app_connections_service.transports.AppConnectionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppConnectionsServiceTransport( @@ -7530,9 +7569,12 @@ def test_app_connections_service_base_transport_with_credentials_file(): def test_app_connections_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.beyondcorp_appconnections_v1.services.app_connections_service.transports.AppConnectionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.beyondcorp_appconnections_v1.services.app_connections_service.transports.AppConnectionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppConnectionsServiceTransport() @@ -7606,11 +7648,12 @@ def test_app_connections_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8286,6 +8329,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AppConnectionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8425,6 +8500,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AppConnectionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8570,6 +8677,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AppConnectionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8715,6 +8856,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AppConnectionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8860,6 +9035,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AppConnectionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9003,6 +9212,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AppConnectionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9167,6 +9410,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AppConnectionsServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9334,6 +9612,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AppConnectionsServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9511,6 +9824,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AppConnectionsServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AppConnectionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AppConnectionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/async_client.py b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/async_client.py index f3643d6776ef..eb9b0633e7e5 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/async_client.py +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/async_client.py @@ -223,7 +223,7 @@ def transport(self) -> AppConnectorsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1183,7 +1183,7 @@ async def sample_report_status(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1209,8 +1209,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1219,7 +1223,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1227,7 +1231,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1238,7 +1242,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1264,8 +1268,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1274,7 +1282,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1282,7 +1290,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1293,7 +1301,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,8 +1331,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1333,7 +1345,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1341,7 +1353,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1349,7 +1361,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1378,8 +1390,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1388,7 +1404,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1396,7 +1412,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1404,7 +1420,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1496,8 +1512,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1506,7 +1526,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1514,7 +1536,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1525,7 +1547,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1618,8 +1640,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1628,7 +1654,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1636,7 +1664,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1647,7 +1675,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1678,8 +1706,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1690,7 +1722,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1698,7 +1732,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1709,7 +1743,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1735,8 +1769,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1745,7 +1783,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1753,7 +1791,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1764,7 +1802,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1790,8 +1828,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1800,7 +1842,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1808,7 +1850,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/client.py b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/client.py index 31af72863945..4e11bab74706 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/client.py +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/client.py @@ -143,7 +143,7 @@ class AppConnectorsServiceClient(metaclass=AppConnectorsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -151,7 +151,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -161,6 +161,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = AppConnectorsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1605,7 +1609,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1631,8 +1635,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1641,7 +1649,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1650,7 +1658,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1664,7 +1672,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1690,8 +1698,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1700,7 +1712,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1709,7 +1721,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1723,7 +1735,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1753,8 +1765,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1763,7 +1779,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1771,7 +1787,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1779,7 +1795,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1808,8 +1824,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1818,7 +1838,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1826,7 +1846,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1834,7 +1854,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1926,8 +1946,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1936,7 +1960,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1945,7 +1971,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1959,7 +1985,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2052,8 +2078,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2062,7 +2092,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2071,7 +2103,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2085,7 +2117,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2116,8 +2148,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2126,7 +2162,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2135,7 +2173,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2149,7 +2187,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2175,8 +2213,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2185,7 +2227,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2194,7 +2236,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2208,7 +2250,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2234,8 +2276,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2244,7 +2290,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2253,7 +2299,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/README.rst b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/README.rst index 511cfe7332a4..1007c51f26af 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/README.rst +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AppConnectorsServiceTransport` is the ABC for all transports. -- public child `AppConnectorsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AppConnectorsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAppConnectorsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AppConnectorsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AppConnectorsServiceTransport`` is the ABC for all transports. + +- public child ``AppConnectorsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AppConnectorsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAppConnectorsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AppConnectorsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/base.py b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/base.py index 56f172b7d625..809355384a19 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/base.py +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc.py b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc.py index 9113d86d1c2e..3721ccb81eba 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc.py +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -203,6 +203,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc_asyncio.py b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc_asyncio.py index 30403d375f84..e2281a4baa29 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -254,6 +254,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/rest.py b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/rest.py index 67c57658439d..e952e09fceda 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/rest.py +++ b/packages/google-cloud-beyondcorp-appconnectors/google/cloud/beyondcorp_appconnectors_v1/services/app_connectors_service/transports/rest.py @@ -729,6 +729,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AppConnectorsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py index 32782336dd62..ffe44a2eb272 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/noxfile.py +++ b/packages/google-cloud-beyondcorp-appconnectors/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-beyondcorp-appconnectors/setup.py b/packages/google-cloud-beyondcorp-appconnectors/setup.py index 159a734c99b1..049f586bf189 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/setup.py +++ b/packages/google-cloud-beyondcorp-appconnectors/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.7.txt b/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.8.txt b/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.9.txt b/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.9.txt +++ b/packages/google-cloud-beyondcorp-appconnectors/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-appconnectors/tests/unit/gapic/beyondcorp_appconnectors_v1/test_app_connectors_service.py b/packages/google-cloud-beyondcorp-appconnectors/tests/unit/gapic/beyondcorp_appconnectors_v1/test_app_connectors_service.py index 995469b76f84..c1023e70d2b6 100644 --- a/packages/google-cloud-beyondcorp-appconnectors/tests/unit/gapic/beyondcorp_appconnectors_v1/test_app_connectors_service.py +++ b/packages/google-cloud-beyondcorp-appconnectors/tests/unit/gapic/beyondcorp_appconnectors_v1/test_app_connectors_service.py @@ -140,6 +140,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AppConnectorsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -162,6 +163,10 @@ def test__get_default_mtls_endpoint(): AppConnectorsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AppConnectorsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1361,11 +1366,13 @@ def test_app_connectors_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5401,8 +5408,9 @@ def test_list_app_connectors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5467,18 +5475,20 @@ def test_list_app_connectors_rest_interceptors(null_interceptor): ) client = AppConnectorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "post_list_app_connectors" - ) as post, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, - "post_list_app_connectors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "pre_list_app_connectors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "post_list_app_connectors" + ) as post, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, + "post_list_app_connectors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "pre_list_app_connectors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5536,8 +5546,9 @@ def test_get_app_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5606,18 +5617,20 @@ def test_get_app_connector_rest_interceptors(null_interceptor): ) client = AppConnectorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "post_get_app_connector" - ) as post, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, - "post_get_app_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "pre_get_app_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "post_get_app_connector" + ) as post, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, + "post_get_app_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "pre_get_app_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5675,8 +5688,9 @@ def test_create_app_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5822,20 +5836,21 @@ def test_create_app_connector_rest_interceptors(null_interceptor): ) client = AppConnectorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "post_create_app_connector" - ) as post, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, - "post_create_app_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "pre_create_app_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "post_create_app_connector" + ) as post, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, + "post_create_app_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "pre_create_app_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5892,8 +5907,9 @@ def test_update_app_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6043,20 +6059,21 @@ def test_update_app_connector_rest_interceptors(null_interceptor): ) client = AppConnectorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "post_update_app_connector" - ) as post, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, - "post_update_app_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "pre_update_app_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "post_update_app_connector" + ) as post, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, + "post_update_app_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "pre_update_app_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6109,8 +6126,9 @@ def test_delete_app_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6167,20 +6185,21 @@ def test_delete_app_connector_rest_interceptors(null_interceptor): ) client = AppConnectorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "post_delete_app_connector" - ) as post, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, - "post_delete_app_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "pre_delete_app_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "post_delete_app_connector" + ) as post, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, + "post_delete_app_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "pre_delete_app_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6235,8 +6254,9 @@ def test_report_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6295,20 +6315,21 @@ def test_report_status_rest_interceptors(null_interceptor): ) client = AppConnectorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "post_report_status" - ) as post, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, - "post_report_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppConnectorsServiceRestInterceptor, "pre_report_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "post_report_status" + ) as post, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, + "post_report_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppConnectorsServiceRestInterceptor, "pre_report_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6361,8 +6382,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6421,8 +6443,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6484,8 +6507,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6549,8 +6573,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6614,8 +6639,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6678,8 +6704,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6740,8 +6767,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6802,8 +6830,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6864,8 +6893,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7139,11 +7169,14 @@ def test_app_connectors_service_base_transport(): def test_app_connectors_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.beyondcorp_appconnectors_v1.services.app_connectors_service.transports.AppConnectorsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.beyondcorp_appconnectors_v1.services.app_connectors_service.transports.AppConnectorsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppConnectorsServiceTransport( @@ -7160,9 +7193,12 @@ def test_app_connectors_service_base_transport_with_credentials_file(): def test_app_connectors_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.beyondcorp_appconnectors_v1.services.app_connectors_service.transports.AppConnectorsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.beyondcorp_appconnectors_v1.services.app_connectors_service.transports.AppConnectorsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppConnectorsServiceTransport() @@ -7234,11 +7270,12 @@ def test_app_connectors_service_transport_auth_gdch_credentials(transport_class) def test_app_connectors_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7856,6 +7893,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AppConnectorsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7995,6 +8064,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AppConnectorsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8140,6 +8241,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AppConnectorsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8285,6 +8420,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AppConnectorsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8430,6 +8599,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AppConnectorsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8573,6 +8776,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AppConnectorsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8737,6 +8974,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AppConnectorsServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8904,6 +9176,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AppConnectorsServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9081,6 +9388,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AppConnectorsServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AppConnectorsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AppConnectorsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/async_client.py b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/async_client.py index 43c64a3e2411..f79b91cf49ae 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/async_client.py +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/async_client.py @@ -214,7 +214,7 @@ def transport(self) -> AppGatewaysServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -873,7 +873,7 @@ async def sample_delete_app_gateway(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -899,8 +899,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -909,7 +913,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -917,7 +921,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -928,7 +932,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -954,8 +958,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -964,7 +972,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -972,7 +980,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -983,7 +991,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1013,8 +1021,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1023,7 +1035,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1031,7 +1043,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1039,7 +1051,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1068,8 +1080,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1078,7 +1094,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1086,7 +1102,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1094,7 +1110,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1186,8 +1202,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1196,7 +1216,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1204,7 +1226,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1215,7 +1237,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1330,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1344,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1326,7 +1354,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1337,7 +1365,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1368,8 +1396,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1380,7 +1412,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1388,7 +1422,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1399,7 +1433,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1425,8 +1459,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1435,7 +1473,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1443,7 +1481,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1454,7 +1492,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1480,8 +1518,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1490,7 +1532,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1498,7 +1540,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/client.py b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/client.py index cd6ac0dfd0cf..86628e6cc462 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/client.py +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/client.py @@ -134,7 +134,7 @@ class AppGatewaysServiceClient(metaclass=AppGatewaysServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -142,7 +142,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -152,6 +152,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -658,7 +662,7 @@ def __init__( self._universe_domain = AppGatewaysServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1303,7 +1307,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1329,8 +1333,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1339,7 +1347,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1348,7 +1356,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1362,7 +1370,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1388,8 +1396,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1398,7 +1410,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1407,7 +1419,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1421,7 +1433,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1451,8 +1463,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1461,7 +1477,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1469,7 +1485,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1477,7 +1493,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1506,8 +1522,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1516,7 +1536,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1524,7 +1544,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1532,7 +1552,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1624,8 +1644,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1634,7 +1658,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1643,7 +1669,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1657,7 +1683,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1750,8 +1776,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1760,7 +1790,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1769,7 +1801,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1783,7 +1815,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1814,8 +1846,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1824,7 +1860,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1833,7 +1871,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1847,7 +1885,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1873,8 +1911,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1883,7 +1925,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1892,7 +1934,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1906,7 +1948,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1932,8 +1974,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1942,7 +1988,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1951,7 +1997,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/README.rst b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/README.rst index cbce0485792f..9847e2b763d6 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/README.rst +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AppGatewaysServiceTransport` is the ABC for all transports. -- public child `AppGatewaysServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AppGatewaysServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAppGatewaysServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AppGatewaysServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AppGatewaysServiceTransport`` is the ABC for all transports. + +- public child ``AppGatewaysServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AppGatewaysServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAppGatewaysServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AppGatewaysServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/base.py b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/base.py index ab6ffc49d786..96cc50516896 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/base.py +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc.py b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc.py index a390116601fc..a45620c42e32 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc.py +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -203,6 +203,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc_asyncio.py b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc_asyncio.py index ed875c7936c8..a4ebf9eea724 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -254,6 +254,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/rest.py b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/rest.py index 65b9367c8f2b..1f74f1a4e7b4 100644 --- a/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/rest.py +++ b/packages/google-cloud-beyondcorp-appgateways/google/cloud/beyondcorp_appgateways_v1/services/app_gateways_service/transports/rest.py @@ -615,6 +615,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AppGatewaysServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-beyondcorp-appgateways/noxfile.py b/packages/google-cloud-beyondcorp-appgateways/noxfile.py index 8b6720a8bf1d..abc6cca51ea2 100644 --- a/packages/google-cloud-beyondcorp-appgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-appgateways/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-beyondcorp-appgateways/setup.py b/packages/google-cloud-beyondcorp-appgateways/setup.py index 285fef79ef34..ce759ece402b 100644 --- a/packages/google-cloud-beyondcorp-appgateways/setup.py +++ b/packages/google-cloud-beyondcorp-appgateways/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.7.txt b/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.8.txt b/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.9.txt b/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.9.txt +++ b/packages/google-cloud-beyondcorp-appgateways/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-appgateways/tests/unit/gapic/beyondcorp_appgateways_v1/test_app_gateways_service.py b/packages/google-cloud-beyondcorp-appgateways/tests/unit/gapic/beyondcorp_appgateways_v1/test_app_gateways_service.py index 1751f4095f9c..4172eb23590b 100644 --- a/packages/google-cloud-beyondcorp-appgateways/tests/unit/gapic/beyondcorp_appgateways_v1/test_app_gateways_service.py +++ b/packages/google-cloud-beyondcorp-appgateways/tests/unit/gapic/beyondcorp_appgateways_v1/test_app_gateways_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AppGatewaysServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): AppGatewaysServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AppGatewaysServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1335,11 +1340,13 @@ def test_app_gateways_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4176,8 +4183,9 @@ def test_list_app_gateways_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4242,18 +4250,20 @@ def test_list_app_gateways_rest_interceptors(null_interceptor): ) client = AppGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "post_list_app_gateways" - ) as post, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, - "post_list_app_gateways_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "pre_list_app_gateways" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "post_list_app_gateways" + ) as post, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, + "post_list_app_gateways_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "pre_list_app_gateways" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4311,8 +4321,9 @@ def test_get_app_gateway_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4389,18 +4400,20 @@ def test_get_app_gateway_rest_interceptors(null_interceptor): ) client = AppGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "post_get_app_gateway" - ) as post, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, - "post_get_app_gateway_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "pre_get_app_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "post_get_app_gateway" + ) as post, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, + "post_get_app_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "pre_get_app_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4455,8 +4468,9 @@ def test_create_app_gateway_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4593,20 +4607,21 @@ def test_create_app_gateway_rest_interceptors(null_interceptor): ) client = AppGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "post_create_app_gateway" - ) as post, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, - "post_create_app_gateway_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "pre_create_app_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "post_create_app_gateway" + ) as post, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, + "post_create_app_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "pre_create_app_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4659,8 +4674,9 @@ def test_delete_app_gateway_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4717,20 +4733,21 @@ def test_delete_app_gateway_rest_interceptors(null_interceptor): ) client = AppGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "post_delete_app_gateway" - ) as post, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, - "post_delete_app_gateway_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AppGatewaysServiceRestInterceptor, "pre_delete_app_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "post_delete_app_gateway" + ) as post, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, + "post_delete_app_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AppGatewaysServiceRestInterceptor, "pre_delete_app_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4783,8 +4800,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4843,8 +4861,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4906,8 +4925,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4971,8 +4991,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5036,8 +5057,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5100,8 +5122,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5162,8 +5185,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5224,8 +5248,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5286,8 +5311,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5515,11 +5541,14 @@ def test_app_gateways_service_base_transport(): def test_app_gateways_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.beyondcorp_appgateways_v1.services.app_gateways_service.transports.AppGatewaysServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.beyondcorp_appgateways_v1.services.app_gateways_service.transports.AppGatewaysServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppGatewaysServiceTransport( @@ -5536,9 +5565,12 @@ def test_app_gateways_service_base_transport_with_credentials_file(): def test_app_gateways_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.beyondcorp_appgateways_v1.services.app_gateways_service.transports.AppGatewaysServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.beyondcorp_appgateways_v1.services.app_gateways_service.transports.AppGatewaysServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AppGatewaysServiceTransport() @@ -5610,11 +5642,12 @@ def test_app_gateways_service_transport_auth_gdch_credentials(transport_class): def test_app_gateways_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6224,6 +6257,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AppGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6363,6 +6428,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AppGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6508,6 +6605,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AppGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6653,6 +6784,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AppGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6798,6 +6963,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AppGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6939,6 +7138,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AppGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7103,6 +7336,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AppGatewaysServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7270,6 +7538,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AppGatewaysServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7447,6 +7750,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AppGatewaysServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AppGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AppGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/async_client.py b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/async_client.py index e8c25111bb5f..7e8e5f75d2f7 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/async_client.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/async_client.py @@ -235,7 +235,7 @@ def transport(self) -> ClientConnectorServicesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1097,7 +1097,7 @@ async def sample_delete_client_connector_service(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1123,8 +1123,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1133,7 +1137,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1141,7 +1145,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1152,7 +1156,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1178,8 +1182,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1188,7 +1196,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1196,7 +1204,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1207,7 +1215,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1237,8 +1245,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1247,7 +1259,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1255,7 +1267,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1263,7 +1275,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1292,8 +1304,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1302,7 +1318,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1310,7 +1326,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1318,7 +1334,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1410,8 +1426,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1420,7 +1440,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1428,7 +1450,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1439,7 +1461,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1532,8 +1554,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1542,7 +1568,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1550,7 +1578,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1561,7 +1589,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1592,8 +1620,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1604,7 +1636,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1612,7 +1646,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1623,7 +1657,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1649,8 +1683,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1659,7 +1697,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1667,7 +1705,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1678,7 +1716,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1704,8 +1742,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1714,7 +1756,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1722,7 +1764,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/client.py b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/client.py index 35e7ff3d0563..74e22c89999d 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/client.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/client.py @@ -145,7 +145,7 @@ class ClientConnectorServicesServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -153,7 +153,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -163,6 +163,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -474,7 +478,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -573,7 +577,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -677,7 +681,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1536,7 +1540,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1562,8 +1566,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1572,7 +1580,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1581,7 +1589,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1595,7 +1603,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1621,8 +1629,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1631,7 +1643,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1640,7 +1652,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1654,7 +1666,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1684,8 +1696,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1694,7 +1710,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1702,7 +1718,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1710,7 +1726,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1739,8 +1755,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1749,7 +1769,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1757,7 +1777,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1765,7 +1785,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1857,8 +1877,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1867,7 +1891,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1876,7 +1902,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1890,7 +1916,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1983,8 +2009,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1993,7 +2023,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2002,7 +2034,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2016,7 +2048,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2047,8 +2079,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2057,7 +2093,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2066,7 +2104,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2080,7 +2118,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2106,8 +2144,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2116,7 +2158,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2125,7 +2167,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2139,7 +2181,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2165,8 +2207,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2175,7 +2221,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2184,7 +2230,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/README.rst b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/README.rst index e7210f9e9197..8b0e6430fc30 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/README.rst +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ClientConnectorServicesServiceTransport` is the ABC for all transports. -- public child `ClientConnectorServicesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ClientConnectorServicesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseClientConnectorServicesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ClientConnectorServicesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ClientConnectorServicesServiceTransport`` is the ABC for all transports. + +- public child ``ClientConnectorServicesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ClientConnectorServicesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseClientConnectorServicesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ClientConnectorServicesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/base.py b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/base.py index 7e63adbf46c7..866285da3c9a 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/base.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc.py b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc.py index 763334953597..8f48cba4d7f4 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -204,6 +204,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc_asyncio.py b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc_asyncio.py index c54e71824e48..0de8480b74ba 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -255,6 +255,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/rest.py b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/rest.py index f03117b3cf6e..081ec16761f2 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/rest.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/google/cloud/beyondcorp_clientconnectorservices_v1/services/client_connector_services_service/transports/rest.py @@ -675,6 +675,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ClientConnectorServicesServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py index 11fc3f1e3a00..7eb5367160f2 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/setup.py b/packages/google-cloud-beyondcorp-clientconnectorservices/setup.py index c171358b7a6e..65babd586e24 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/setup.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/setup.py @@ -43,7 +43,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -51,7 +51,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -84,8 +84,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -97,7 +95,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.7.txt b/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.8.txt b/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.9.txt b/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.9.txt +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-clientconnectorservices/tests/unit/gapic/beyondcorp_clientconnectorservices_v1/test_client_connector_services_service.py b/packages/google-cloud-beyondcorp-clientconnectorservices/tests/unit/gapic/beyondcorp_clientconnectorservices_v1/test_client_connector_services_service.py index 598c82d5ddec..54341d9127a8 100644 --- a/packages/google-cloud-beyondcorp-clientconnectorservices/tests/unit/gapic/beyondcorp_clientconnectorservices_v1/test_client_connector_services_service.py +++ b/packages/google-cloud-beyondcorp-clientconnectorservices/tests/unit/gapic/beyondcorp_clientconnectorservices_v1/test_client_connector_services_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ClientConnectorServicesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -163,6 +164,10 @@ def test__get_default_mtls_endpoint(): ClientConnectorServicesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ClientConnectorServicesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1421,11 +1426,13 @@ def test_client_connector_services_service_client_create_channel_credentials_fil ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5023,8 +5030,9 @@ def test_list_client_connector_services_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5095,20 +5103,22 @@ def test_list_client_connector_services_rest_interceptors(null_interceptor): ) client = ClientConnectorServicesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_list_client_connector_services", - ) as post, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_list_client_connector_services_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "pre_list_client_connector_services", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_list_client_connector_services", + ) as post, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_list_client_connector_services_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "pre_list_client_connector_services", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5172,8 +5182,9 @@ def test_get_client_connector_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5249,20 +5260,22 @@ def test_get_client_connector_service_rest_interceptors(null_interceptor): ) client = ClientConnectorServicesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_get_client_connector_service", - ) as post, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_get_client_connector_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "pre_get_client_connector_service", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_get_client_connector_service", + ) as post, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_get_client_connector_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "pre_get_client_connector_service", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5322,8 +5335,9 @@ def test_create_client_connector_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5467,22 +5481,23 @@ def test_create_client_connector_service_rest_interceptors(null_interceptor): ) client = ClientConnectorServicesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_create_client_connector_service", - ) as post, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_create_client_connector_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "pre_create_client_connector_service", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_create_client_connector_service", + ) as post, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_create_client_connector_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "pre_create_client_connector_service", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5543,8 +5558,9 @@ def test_update_client_connector_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5692,22 +5708,23 @@ def test_update_client_connector_service_rest_interceptors(null_interceptor): ) client = ClientConnectorServicesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_update_client_connector_service", - ) as post, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_update_client_connector_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "pre_update_client_connector_service", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_update_client_connector_service", + ) as post, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_update_client_connector_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "pre_update_client_connector_service", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5766,8 +5783,9 @@ def test_delete_client_connector_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5826,22 +5844,23 @@ def test_delete_client_connector_service_rest_interceptors(null_interceptor): ) client = ClientConnectorServicesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_delete_client_connector_service", - ) as post, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "post_delete_client_connector_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientConnectorServicesServiceRestInterceptor, - "pre_delete_client_connector_service", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_delete_client_connector_service", + ) as post, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "post_delete_client_connector_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientConnectorServicesServiceRestInterceptor, + "pre_delete_client_connector_service", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5898,8 +5917,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5958,8 +5978,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6021,8 +6042,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6086,8 +6108,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6151,8 +6174,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6215,8 +6239,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6277,8 +6302,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6339,8 +6365,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6401,8 +6428,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6665,11 +6693,14 @@ def test_client_connector_services_service_base_transport(): def test_client_connector_services_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.beyondcorp_clientconnectorservices_v1.services.client_connector_services_service.transports.ClientConnectorServicesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.beyondcorp_clientconnectorservices_v1.services.client_connector_services_service.transports.ClientConnectorServicesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClientConnectorServicesServiceTransport( @@ -6686,9 +6717,12 @@ def test_client_connector_services_service_base_transport_with_credentials_file( def test_client_connector_services_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.beyondcorp_clientconnectorservices_v1.services.client_connector_services_service.transports.ClientConnectorServicesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.beyondcorp_clientconnectorservices_v1.services.client_connector_services_service.transports.ClientConnectorServicesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClientConnectorServicesServiceTransport() @@ -6767,11 +6801,12 @@ def test_client_connector_services_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7398,6 +7433,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ClientConnectorServicesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7537,6 +7604,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ClientConnectorServicesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7682,6 +7781,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ClientConnectorServicesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7827,6 +7960,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ClientConnectorServicesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7972,6 +8139,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ClientConnectorServicesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8117,6 +8318,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ClientConnectorServicesServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8281,6 +8516,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = ClientConnectorServicesServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8448,6 +8718,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = ClientConnectorServicesServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8625,6 +8930,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = ClientConnectorServicesServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = ClientConnectorServicesServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = ClientConnectorServicesServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/async_client.py b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/async_client.py index 2aa632d0d95b..c175da553134 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/async_client.py +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> ClientGatewaysServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -851,7 +851,7 @@ async def sample_delete_client_gateway(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -877,8 +877,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -887,7 +891,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -895,7 +899,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -906,7 +910,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -932,8 +936,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -942,7 +950,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -950,7 +958,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -961,7 +969,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -991,8 +999,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1001,7 +1013,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1009,7 +1021,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1017,7 +1029,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1046,8 +1058,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1056,7 +1072,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1064,7 +1080,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1072,7 +1088,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1164,8 +1180,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1174,7 +1194,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1182,7 +1204,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1193,7 +1215,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1286,8 +1308,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1296,7 +1322,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1304,7 +1332,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1315,7 +1343,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1346,8 +1374,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1358,7 +1390,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1366,7 +1400,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1377,7 +1411,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1403,8 +1437,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1413,7 +1451,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1421,7 +1459,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1432,7 +1470,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1458,8 +1496,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1468,7 +1510,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1476,7 +1518,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/client.py b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/client.py index 51930ecbdfe0..b3dcb4559821 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/client.py +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/client.py @@ -133,7 +133,7 @@ class ClientGatewaysServiceClient(metaclass=ClientGatewaysServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -141,7 +141,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -151,6 +151,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -458,7 +462,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -557,7 +561,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -657,7 +661,7 @@ def __init__( self._universe_domain = ClientGatewaysServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1279,7 +1283,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1305,8 +1309,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1315,7 +1323,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1324,7 +1332,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1338,7 +1346,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1364,8 +1372,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1374,7 +1386,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1383,7 +1395,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1397,7 +1409,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1427,8 +1439,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1437,7 +1453,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1445,7 +1461,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1453,7 +1469,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1482,8 +1498,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1492,7 +1512,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1500,7 +1520,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1508,7 +1528,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1600,8 +1620,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1610,7 +1634,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1619,7 +1645,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1633,7 +1659,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1726,8 +1752,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1736,7 +1766,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1745,7 +1777,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1759,7 +1791,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1790,8 +1822,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1800,7 +1836,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1809,7 +1847,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1823,7 +1861,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1849,8 +1887,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1859,7 +1901,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1868,7 +1910,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1882,7 +1924,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1908,8 +1950,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1918,7 +1964,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1927,7 +1973,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/README.rst b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/README.rst index 10558ab764b4..b22ff8005ed3 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/README.rst +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ClientGatewaysServiceTransport` is the ABC for all transports. -- public child `ClientGatewaysServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ClientGatewaysServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseClientGatewaysServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ClientGatewaysServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ClientGatewaysServiceTransport`` is the ABC for all transports. + +- public child ``ClientGatewaysServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ClientGatewaysServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseClientGatewaysServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ClientGatewaysServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/base.py b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/base.py index 1bb232b18b89..6c6da8902234 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/base.py +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc.py b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc.py index 3ee4a15c6086..93bded93aba1 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc.py +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -200,6 +200,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc_asyncio.py b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc_asyncio.py index de3013041a44..99b4ab5181de 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -251,6 +251,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/rest.py b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/rest.py index 47a97952308a..9c023084831b 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/rest.py +++ b/packages/google-cloud-beyondcorp-clientgateways/google/cloud/beyondcorp_clientgateways_v1/services/client_gateways_service/transports/rest.py @@ -612,6 +612,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ClientGatewaysServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py index b1bce6dbb24e..c373451cfc6d 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/noxfile.py +++ b/packages/google-cloud-beyondcorp-clientgateways/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-beyondcorp-clientgateways/setup.py b/packages/google-cloud-beyondcorp-clientgateways/setup.py index 601252c6a3e2..627b6efb3c02 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/setup.py +++ b/packages/google-cloud-beyondcorp-clientgateways/setup.py @@ -43,7 +43,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -51,7 +51,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -84,8 +84,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -97,7 +95,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.7.txt b/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.8.txt b/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.9.txt b/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.9.txt +++ b/packages/google-cloud-beyondcorp-clientgateways/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-beyondcorp-clientgateways/tests/unit/gapic/beyondcorp_clientgateways_v1/test_client_gateways_service.py b/packages/google-cloud-beyondcorp-clientgateways/tests/unit/gapic/beyondcorp_clientgateways_v1/test_client_gateways_service.py index 85e1c5804474..9500284376ea 100644 --- a/packages/google-cloud-beyondcorp-clientgateways/tests/unit/gapic/beyondcorp_clientgateways_v1/test_client_gateways_service.py +++ b/packages/google-cloud-beyondcorp-clientgateways/tests/unit/gapic/beyondcorp_clientgateways_v1/test_client_gateways_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ClientGatewaysServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): ClientGatewaysServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ClientGatewaysServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1355,11 +1360,13 @@ def test_client_gateways_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4222,8 +4229,9 @@ def test_list_client_gateways_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4290,18 +4298,20 @@ def test_list_client_gateways_rest_interceptors(null_interceptor): ) client = ClientGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "post_list_client_gateways" - ) as post, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, - "post_list_client_gateways_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "pre_list_client_gateways" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, "post_list_client_gateways" + ) as post, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, + "post_list_client_gateways_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, "pre_list_client_gateways" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4359,8 +4369,9 @@ def test_get_client_gateway_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4429,18 +4440,20 @@ def test_get_client_gateway_rest_interceptors(null_interceptor): ) client = ClientGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "post_get_client_gateway" - ) as post, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, - "post_get_client_gateway_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "pre_get_client_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, "post_get_client_gateway" + ) as post, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, + "post_get_client_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, "pre_get_client_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4498,8 +4511,9 @@ def test_create_client_gateway_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4633,20 +4647,22 @@ def test_create_client_gateway_rest_interceptors(null_interceptor): ) client = ClientGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "post_create_client_gateway" - ) as post, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, - "post_create_client_gateway_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "pre_create_client_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, + "post_create_client_gateway", + ) as post, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, + "post_create_client_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, "pre_create_client_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4699,8 +4715,9 @@ def test_delete_client_gateway_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4757,20 +4774,22 @@ def test_delete_client_gateway_rest_interceptors(null_interceptor): ) client = ClientGatewaysServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "post_delete_client_gateway" - ) as post, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, - "post_delete_client_gateway_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClientGatewaysServiceRestInterceptor, "pre_delete_client_gateway" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, + "post_delete_client_gateway", + ) as post, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, + "post_delete_client_gateway_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClientGatewaysServiceRestInterceptor, "pre_delete_client_gateway" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4823,8 +4842,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4883,8 +4903,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4946,8 +4967,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5011,8 +5033,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5076,8 +5099,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5140,8 +5164,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5202,8 +5227,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5264,8 +5290,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5326,8 +5353,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5557,11 +5585,14 @@ def test_client_gateways_service_base_transport(): def test_client_gateways_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.beyondcorp_clientgateways_v1.services.client_gateways_service.transports.ClientGatewaysServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.beyondcorp_clientgateways_v1.services.client_gateways_service.transports.ClientGatewaysServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClientGatewaysServiceTransport( @@ -5578,9 +5609,12 @@ def test_client_gateways_service_base_transport_with_credentials_file(): def test_client_gateways_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.beyondcorp_clientgateways_v1.services.client_gateways_service.transports.ClientGatewaysServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.beyondcorp_clientgateways_v1.services.client_gateways_service.transports.ClientGatewaysServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClientGatewaysServiceTransport() @@ -5654,11 +5688,12 @@ def test_client_gateways_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6268,6 +6303,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ClientGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6407,6 +6474,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ClientGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6552,6 +6651,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ClientGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6697,6 +6830,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ClientGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6842,6 +7009,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ClientGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6985,6 +7186,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ClientGatewaysServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7149,6 +7384,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = ClientGatewaysServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7316,6 +7586,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = ClientGatewaysServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7493,6 +7798,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = ClientGatewaysServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = ClientGatewaysServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = ClientGatewaysServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py index b8c5650c0e51..899368196274 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> IcebergCatalogServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py index 241e5ddff79e..22b5cf4b8d10 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/client.py @@ -140,7 +140,7 @@ class IcebergCatalogServiceClient(metaclass=IcebergCatalogServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -148,7 +148,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -158,6 +158,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -460,7 +464,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -559,7 +563,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -659,7 +663,7 @@ def __init__( self._universe_domain = IcebergCatalogServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/README.rst b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/README.rst index 48c3876063ac..59aaf88b2985 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/README.rst +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IcebergCatalogServiceTransport` is the ABC for all transports. -- public child `IcebergCatalogServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IcebergCatalogServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIcebergCatalogServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IcebergCatalogServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IcebergCatalogServiceTransport`` is the ABC for all transports. + +- public child ``IcebergCatalogServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IcebergCatalogServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIcebergCatalogServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IcebergCatalogServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/base.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/base.py index b6d98455415a..3eea105cf3a3 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/base.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py index 6b3728733129..4219a2a6a238 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -211,6 +211,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py index 7457c6be5bb6..5523025f077f 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -262,6 +262,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py index 12840494aaee..d9ecced20f4d 100644 --- a/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py +++ b/packages/google-cloud-biglake/google/cloud/biglake_v1/services/iceberg_catalog_service/transports/rest.py @@ -469,6 +469,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IcebergCatalogServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-biglake/noxfile.py b/packages/google-cloud-biglake/noxfile.py index d69c33811084..90929daf1aad 100644 --- a/packages/google-cloud-biglake/noxfile.py +++ b/packages/google-cloud-biglake/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-biglake/setup.py b/packages/google-cloud-biglake/setup.py index 60cb8d3ae3f0..a2f368633013 100644 --- a/packages/google-cloud-biglake/setup.py +++ b/packages/google-cloud-biglake/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-biglake" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-biglake/testing/constraints-3.7.txt b/packages/google-cloud-biglake/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-biglake/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-biglake/testing/constraints-3.8.txt b/packages/google-cloud-biglake/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-biglake/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-biglake/testing/constraints-3.9.txt b/packages/google-cloud-biglake/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-biglake/testing/constraints-3.9.txt +++ b/packages/google-cloud-biglake/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py b/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py index 6f67a0107c58..c3c4a486a77d 100644 --- a/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py +++ b/packages/google-cloud-biglake/tests/unit/gapic/biglake_v1/test_iceberg_catalog_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IcebergCatalogServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): IcebergCatalogServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + IcebergCatalogServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1344,11 +1349,13 @@ def test_iceberg_catalog_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4886,8 +4893,9 @@ def test_get_iceberg_catalog_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4966,18 +4974,20 @@ def test_get_iceberg_catalog_rest_interceptors(null_interceptor): ) client = IcebergCatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "post_get_iceberg_catalog" - ) as post, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, - "post_get_iceberg_catalog_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "pre_get_iceberg_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, "post_get_iceberg_catalog" + ) as post, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_get_iceberg_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, "pre_get_iceberg_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5035,8 +5045,9 @@ def test_list_iceberg_catalogs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5101,18 +5112,21 @@ def test_list_iceberg_catalogs_rest_interceptors(null_interceptor): ) client = IcebergCatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "post_list_iceberg_catalogs" - ) as post, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, - "post_list_iceberg_catalogs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "pre_list_iceberg_catalogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_list_iceberg_catalogs", + ) as post, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_list_iceberg_catalogs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, "pre_list_iceberg_catalogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5170,8 +5184,9 @@ def test_update_iceberg_catalog_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5329,18 +5344,22 @@ def test_update_iceberg_catalog_rest_interceptors(null_interceptor): ) client = IcebergCatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "post_update_iceberg_catalog" - ) as post, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, - "post_update_iceberg_catalog_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "pre_update_iceberg_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_update_iceberg_catalog", + ) as post, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_update_iceberg_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "pre_update_iceberg_catalog", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5398,8 +5417,9 @@ def test_create_iceberg_catalog_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5557,18 +5577,22 @@ def test_create_iceberg_catalog_rest_interceptors(null_interceptor): ) client = IcebergCatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "post_create_iceberg_catalog" - ) as post, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, - "post_create_iceberg_catalog_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "pre_create_iceberg_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_create_iceberg_catalog", + ) as post, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_create_iceberg_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "pre_create_iceberg_catalog", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5626,8 +5650,9 @@ def test_failover_iceberg_catalog_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5689,18 +5714,22 @@ def test_failover_iceberg_catalog_rest_interceptors(null_interceptor): ) client = IcebergCatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "post_failover_iceberg_catalog" - ) as post, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, - "post_failover_iceberg_catalog_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IcebergCatalogServiceRestInterceptor, "pre_failover_iceberg_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_failover_iceberg_catalog", + ) as post, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "post_failover_iceberg_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IcebergCatalogServiceRestInterceptor, + "pre_failover_iceberg_catalog", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5921,11 +5950,14 @@ def test_iceberg_catalog_service_base_transport(): def test_iceberg_catalog_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.biglake_v1.services.iceberg_catalog_service.transports.IcebergCatalogServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.biglake_v1.services.iceberg_catalog_service.transports.IcebergCatalogServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IcebergCatalogServiceTransport( @@ -5945,9 +5977,12 @@ def test_iceberg_catalog_service_base_transport_with_credentials_file(): def test_iceberg_catalog_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.biglake_v1.services.iceberg_catalog_service.transports.IcebergCatalogServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.biglake_v1.services.iceberg_catalog_service.transports.IcebergCatalogServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IcebergCatalogServiceTransport() @@ -6027,11 +6062,12 @@ def test_iceberg_catalog_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/async_client.py b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/async_client.py index 9e043547dace..a4bebfcc04a8 100644 --- a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/async_client.py +++ b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> AnalyticsHubServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/client.py b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/client.py index 6cf0ae1a5342..6fc8a5f7f63b 100644 --- a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/client.py +++ b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/client.py @@ -123,7 +123,7 @@ class AnalyticsHubServiceClient(metaclass=AnalyticsHubServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -628,7 +632,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -725,7 +729,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -825,7 +829,7 @@ def __init__( self._universe_domain = AnalyticsHubServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/README.rst b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/README.rst index dbc9199b0730..c965e5062fe6 100644 --- a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/README.rst +++ b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AnalyticsHubServiceTransport` is the ABC for all transports. -- public child `AnalyticsHubServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AnalyticsHubServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAnalyticsHubServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AnalyticsHubServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AnalyticsHubServiceTransport`` is the ABC for all transports. + +- public child ``AnalyticsHubServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AnalyticsHubServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAnalyticsHubServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AnalyticsHubServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/base.py b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/base.py index 6b3210659f2e..b365da1ff7d6 100644 --- a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/base.py +++ b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc.py b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc.py index f0dae5dee629..263318fd542e 100644 --- a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc_asyncio.py index 56653a77abff..88a7b7568d35 100644 --- a/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-analyticshub/google/cloud/bigquery_analyticshub_v1/services/analytics_hub_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-analyticshub/noxfile.py b/packages/google-cloud-bigquery-analyticshub/noxfile.py index 424b3d86c635..e8febf1e5c9b 100644 --- a/packages/google-cloud-bigquery-analyticshub/noxfile.py +++ b/packages/google-cloud-bigquery-analyticshub/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-analyticshub/setup.py b/packages/google-cloud-bigquery-analyticshub/setup.py index d700daba0a2b..d28e09728bc0 100644 --- a/packages/google-cloud-bigquery-analyticshub/setup.py +++ b/packages/google-cloud-bigquery-analyticshub/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-analyticshub/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-analyticshub/tests/unit/gapic/bigquery_analyticshub_v1/test_analytics_hub_service.py b/packages/google-cloud-bigquery-analyticshub/tests/unit/gapic/bigquery_analyticshub_v1/test_analytics_hub_service.py index 7c8148dc6ac1..eefd83111c60 100644 --- a/packages/google-cloud-bigquery-analyticshub/tests/unit/gapic/bigquery_analyticshub_v1/test_analytics_hub_service.py +++ b/packages/google-cloud-bigquery-analyticshub/tests/unit/gapic/bigquery_analyticshub_v1/test_analytics_hub_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AnalyticsHubServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): AnalyticsHubServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AnalyticsHubServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1311,11 +1316,13 @@ def test_analytics_hub_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -14353,11 +14360,14 @@ def test_analytics_hub_service_base_transport(): def test_analytics_hub_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_analyticshub_v1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_analyticshub_v1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsHubServiceTransport( @@ -14377,9 +14387,12 @@ def test_analytics_hub_service_base_transport_with_credentials_file(): def test_analytics_hub_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_analyticshub_v1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_analyticshub_v1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsHubServiceTransport() @@ -14456,11 +14469,12 @@ def test_analytics_hub_service_transport_auth_gdch_credentials(transport_class): def test_analytics_hub_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/async_client.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/async_client.py index 15407e78a13d..89d0149bea0f 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/async_client.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> MetastoreServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/client.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/client.py index 30a8df06a647..609b90dbedaf 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/client.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/client.py @@ -123,7 +123,7 @@ class MetastoreServiceClient(metaclass=MetastoreServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -498,7 +502,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -595,7 +599,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -693,7 +697,7 @@ def __init__( self._universe_domain = MetastoreServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/README.rst b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/README.rst index 489d37387a08..968219e193d9 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/README.rst +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetastoreServiceTransport` is the ABC for all transports. -- public child `MetastoreServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetastoreServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetastoreServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetastoreServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetastoreServiceTransport`` is the ABC for all transports. + +- public child ``MetastoreServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetastoreServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetastoreServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetastoreServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/base.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/base.py index a00a976bedbf..e74805294ded 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/base.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc.py index cbaf6e66682e..5d1c5f6d0ee8 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc_asyncio.py index 3c6a9eebb73b..d2349ed77417 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/rest.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/rest.py index fa0b59c411cf..dfffb716cdb7 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/rest.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1/services/metastore_service/transports/rest.py @@ -949,6 +949,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MetastoreServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/async_client.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/async_client.py index c605d85b0d6d..1a37a3496122 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/async_client.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> MetastoreServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/client.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/client.py index 76e7f0415716..b493dc522cfb 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/client.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/client.py @@ -123,7 +123,7 @@ class MetastoreServiceClient(metaclass=MetastoreServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -524,7 +528,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -621,7 +625,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -719,7 +723,7 @@ def __init__( self._universe_domain = MetastoreServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/README.rst b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/README.rst index 489d37387a08..968219e193d9 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/README.rst +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetastoreServiceTransport` is the ABC for all transports. -- public child `MetastoreServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetastoreServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetastoreServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetastoreServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetastoreServiceTransport`` is the ABC for all transports. + +- public child ``MetastoreServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetastoreServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetastoreServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetastoreServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/base.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/base.py index 83b5b5b4f902..3fd203d2ee89 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/base.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc.py index b77909d00158..4a3989cd19a1 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc_asyncio.py index 70c3cbf1e3b6..1e71f9cf92e3 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/rest.py b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/rest.py index 3f9e8401ef37..105546dd919d 100644 --- a/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/rest.py +++ b/packages/google-cloud-bigquery-biglake/google/cloud/bigquery_biglake_v1alpha1/services/metastore_service/transports/rest.py @@ -1124,6 +1124,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MetastoreServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-biglake/noxfile.py b/packages/google-cloud-bigquery-biglake/noxfile.py index 9fc5fe83d5b0..e49a2140fe94 100644 --- a/packages/google-cloud-bigquery-biglake/noxfile.py +++ b/packages/google-cloud-bigquery-biglake/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-biglake/setup.py b/packages/google-cloud-bigquery-biglake/setup.py index 6dc98898d8a1..a50f9454bb10 100644 --- a/packages/google-cloud-bigquery-biglake/setup.py +++ b/packages/google-cloud-bigquery-biglake/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-bigquery-biglake" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-biglake/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-biglake/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-bigquery-biglake/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-bigquery-biglake/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-biglake/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-bigquery-biglake/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-bigquery-biglake/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-biglake/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-bigquery-biglake/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-biglake/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1/test_metastore_service.py b/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1/test_metastore_service.py index 6e42ca3c4827..8162eaf7db00 100644 --- a/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1/test_metastore_service.py +++ b/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1/test_metastore_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetastoreServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): MetastoreServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetastoreServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1312,11 +1317,13 @@ def test_metastore_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10878,8 +10885,9 @@ def test_create_catalog_rest_bad_request(request_type=metastore.CreateCatalogReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11016,17 +11024,20 @@ def test_create_catalog_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_catalog" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_catalog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_catalog" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_create_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11075,8 +11086,9 @@ def test_delete_catalog_rest_bad_request(request_type=metastore.DeleteCatalogReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11139,17 +11151,20 @@ def test_delete_catalog_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_catalog" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_catalog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_delete_catalog" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_delete_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11198,8 +11213,9 @@ def test_get_catalog_rest_bad_request(request_type=metastore.GetCatalogRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11262,17 +11278,19 @@ def test_get_catalog_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_catalog" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_catalog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_get_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_catalog" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_catalog_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_get_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11321,8 +11339,9 @@ def test_list_catalogs_rest_bad_request(request_type=metastore.ListCatalogsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11385,17 +11404,20 @@ def test_list_catalogs_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_catalogs" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_catalogs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_catalogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_catalogs" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_list_catalogs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_catalogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11446,8 +11468,9 @@ def test_create_database_rest_bad_request(request_type=metastore.CreateDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11588,17 +11611,20 @@ def test_create_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_create_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11651,8 +11677,9 @@ def test_delete_database_rest_bad_request(request_type=metastore.DeleteDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11719,17 +11746,20 @@ def test_delete_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_delete_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_delete_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11784,8 +11814,9 @@ def test_update_database_rest_bad_request(request_type=metastore.UpdateDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11930,17 +11961,20 @@ def test_update_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_update_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_update_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_update_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_update_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11993,8 +12027,9 @@ def test_get_database_rest_bad_request(request_type=metastore.GetDatabaseRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12061,17 +12096,20 @@ def test_get_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_get_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_get_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_get_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12120,8 +12158,9 @@ def test_list_databases_rest_bad_request(request_type=metastore.ListDatabasesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12184,17 +12223,20 @@ def test_list_databases_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_databases" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_databases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_databases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_databases" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_list_databases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_databases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12247,8 +12289,9 @@ def test_create_table_rest_bad_request(request_type=metastore.CreateTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12403,17 +12446,20 @@ def test_create_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_create_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12464,8 +12510,9 @@ def test_delete_table_rest_bad_request(request_type=metastore.DeleteTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12534,17 +12581,20 @@ def test_delete_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_delete_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_delete_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12597,8 +12647,9 @@ def test_update_table_rest_bad_request(request_type=metastore.UpdateTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12755,17 +12806,20 @@ def test_update_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_update_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_update_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_update_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_update_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12816,8 +12870,9 @@ def test_rename_table_rest_bad_request(request_type=metastore.RenameTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12886,17 +12941,20 @@ def test_rename_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_rename_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_rename_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_rename_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_rename_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_rename_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_rename_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12947,8 +13005,9 @@ def test_get_table_rest_bad_request(request_type=metastore.GetTableRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13017,17 +13076,19 @@ def test_get_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_get_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_table_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_get_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13078,8 +13139,9 @@ def test_list_tables_rest_bad_request(request_type=metastore.ListTablesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13144,17 +13206,19 @@ def test_list_tables_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_tables" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_tables_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_tables" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_tables" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_tables_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_tables" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13570,11 +13634,14 @@ def test_metastore_service_base_transport(): def test_metastore_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_biglake_v1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_biglake_v1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastoreServiceTransport( @@ -13594,9 +13661,12 @@ def test_metastore_service_base_transport_with_credentials_file(): def test_metastore_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_biglake_v1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_biglake_v1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastoreServiceTransport() @@ -13674,11 +13744,12 @@ def test_metastore_service_transport_auth_gdch_credentials(transport_class): def test_metastore_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1alpha1/test_metastore_service.py b/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1alpha1/test_metastore_service.py index 48de023f5f17..e50ff17d8004 100644 --- a/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1alpha1/test_metastore_service.py +++ b/packages/google-cloud-bigquery-biglake/tests/unit/gapic/bigquery_biglake_v1alpha1/test_metastore_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetastoreServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): MetastoreServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetastoreServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1312,11 +1317,13 @@ def test_metastore_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -13363,8 +13370,9 @@ def test_create_catalog_rest_bad_request(request_type=metastore.CreateCatalogReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13501,17 +13509,20 @@ def test_create_catalog_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_catalog" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_catalog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_catalog" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_create_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13560,8 +13571,9 @@ def test_delete_catalog_rest_bad_request(request_type=metastore.DeleteCatalogReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13624,17 +13636,20 @@ def test_delete_catalog_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_catalog" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_catalog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_delete_catalog" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_delete_catalog_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13683,8 +13698,9 @@ def test_get_catalog_rest_bad_request(request_type=metastore.GetCatalogRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13747,17 +13763,19 @@ def test_get_catalog_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_catalog" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_catalog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_get_catalog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_catalog" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_catalog_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_get_catalog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13806,8 +13824,9 @@ def test_list_catalogs_rest_bad_request(request_type=metastore.ListCatalogsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13870,17 +13889,20 @@ def test_list_catalogs_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_catalogs" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_catalogs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_catalogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_catalogs" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_list_catalogs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_catalogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13931,8 +13953,9 @@ def test_create_database_rest_bad_request(request_type=metastore.CreateDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14073,17 +14096,20 @@ def test_create_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_create_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14136,8 +14162,9 @@ def test_delete_database_rest_bad_request(request_type=metastore.DeleteDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14204,17 +14231,20 @@ def test_delete_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_delete_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_delete_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14269,8 +14299,9 @@ def test_update_database_rest_bad_request(request_type=metastore.UpdateDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14415,17 +14446,20 @@ def test_update_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_update_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_update_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_update_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_update_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14478,8 +14512,9 @@ def test_get_database_rest_bad_request(request_type=metastore.GetDatabaseRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14546,17 +14581,20 @@ def test_get_database_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_database" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_get_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_database" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_get_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_get_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14605,8 +14643,9 @@ def test_list_databases_rest_bad_request(request_type=metastore.ListDatabasesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14669,17 +14708,20 @@ def test_list_databases_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_databases" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_databases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_databases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_databases" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_list_databases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_databases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14732,8 +14774,9 @@ def test_create_table_rest_bad_request(request_type=metastore.CreateTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14888,17 +14931,20 @@ def test_create_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_create_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14949,8 +14995,9 @@ def test_delete_table_rest_bad_request(request_type=metastore.DeleteTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15019,17 +15066,20 @@ def test_delete_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_delete_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_delete_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_delete_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15082,8 +15132,9 @@ def test_update_table_rest_bad_request(request_type=metastore.UpdateTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15240,17 +15291,20 @@ def test_update_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_update_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_update_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_update_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_update_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_update_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15301,8 +15355,9 @@ def test_rename_table_rest_bad_request(request_type=metastore.RenameTableRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15371,17 +15426,20 @@ def test_rename_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_rename_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_rename_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_rename_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_rename_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, + "post_rename_table_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_rename_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15432,8 +15490,9 @@ def test_get_table_rest_bad_request(request_type=metastore.GetTableRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15502,17 +15561,19 @@ def test_get_table_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_table" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_get_table_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_get_table" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_table" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_get_table_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_get_table" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15563,8 +15624,9 @@ def test_list_tables_rest_bad_request(request_type=metastore.ListTablesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15629,17 +15691,19 @@ def test_list_tables_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_tables" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_tables_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_tables" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_tables" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_tables_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_tables" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15692,8 +15756,9 @@ def test_create_lock_rest_bad_request(request_type=metastore.CreateLockRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15837,17 +15902,19 @@ def test_create_lock_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_lock" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_create_lock_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_create_lock" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_lock" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_create_lock_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_create_lock" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15898,8 +15965,9 @@ def test_delete_lock_rest_bad_request(request_type=metastore.DeleteLockRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15958,13 +16026,13 @@ def test_delete_lock_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_delete_lock" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_delete_lock" + ) as pre, + ): pre.assert_not_called() pb_message = metastore.DeleteLockRequest.pb(metastore.DeleteLockRequest()) transcode.return_value = { @@ -16007,8 +16075,9 @@ def test_check_lock_rest_bad_request(request_type=metastore.CheckLockRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16078,17 +16147,19 @@ def test_check_lock_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_check_lock" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_check_lock_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_check_lock" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_check_lock" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_check_lock_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_check_lock" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16139,8 +16210,9 @@ def test_list_locks_rest_bad_request(request_type=metastore.ListLocksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16205,17 +16277,19 @@ def test_list_locks_rest_interceptors(null_interceptor): ) client = MetastoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_locks" - ) as post, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "post_list_locks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetastoreServiceRestInterceptor, "pre_list_locks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_locks" + ) as post, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "post_list_locks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetastoreServiceRestInterceptor, "pre_list_locks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16715,11 +16789,14 @@ def test_metastore_service_base_transport(): def test_metastore_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_biglake_v1alpha1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_biglake_v1alpha1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastoreServiceTransport( @@ -16739,9 +16816,12 @@ def test_metastore_service_base_transport_with_credentials_file(): def test_metastore_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_biglake_v1alpha1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_biglake_v1alpha1.services.metastore_service.transports.MetastoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastoreServiceTransport() @@ -16819,11 +16899,12 @@ def test_metastore_service_transport_auth_gdch_credentials(transport_class): def test_metastore_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py index 5aac13c3f62a..cc926e30b119 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> ConnectionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/client.py b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/client.py index dbcf343836f6..e8286c9a2d40 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/client.py +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/client.py @@ -114,7 +114,7 @@ class ConnectionServiceClient(metaclass=ConnectionServiceClientMeta): """Manages external data source connections and credentials.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -485,7 +489,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -582,7 +586,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -682,7 +686,7 @@ def __init__( self._universe_domain = ConnectionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/README.rst b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/README.rst index 78c1c64f4d94..255f0213d916 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/README.rst +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConnectionServiceTransport` is the ABC for all transports. -- public child `ConnectionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConnectionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConnectionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConnectionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConnectionServiceTransport`` is the ABC for all transports. + +- public child ``ConnectionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConnectionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConnectionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConnectionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py index d2bcabe1a341..20598feddd77 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py index b098fded95d8..014c5c6159b4 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py index 1b11230697c4..e2e3e6d7bb30 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/rest.py b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/rest.py index 3d7592561057..6b67cbd9c25a 100644 --- a/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/rest.py +++ b/packages/google-cloud-bigquery-connection/google/cloud/bigquery_connection_v1/services/connection_service/transports/rest.py @@ -561,6 +561,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConnectionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-connection/noxfile.py b/packages/google-cloud-bigquery-connection/noxfile.py index dd95f942f153..d85fefb5cae9 100644 --- a/packages/google-cloud-bigquery-connection/noxfile.py +++ b/packages/google-cloud-bigquery-connection/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-connection/setup.py b/packages/google-cloud-bigquery-connection/setup.py index da7e657a347b..5c24eb8c4e6f 100644 --- a/packages/google-cloud-bigquery-connection/setup.py +++ b/packages/google-cloud-bigquery-connection/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-connection/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-connection/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bigquery-connection/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-connection/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-connection/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bigquery-connection/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bigquery-connection/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-connection/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bigquery-connection/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-connection/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-connection/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py b/packages/google-cloud-bigquery-connection/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py index b73eb1b2cbef..32b0cf9871a9 100644 --- a/packages/google-cloud-bigquery-connection/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py +++ b/packages/google-cloud-bigquery-connection/tests/unit/gapic/bigquery_connection_v1/test_connection_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConnectionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): ConnectionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConnectionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1324,11 +1329,13 @@ def test_connection_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6492,8 +6499,9 @@ def test_create_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6691,18 +6699,20 @@ def test_create_connection_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_create_connection" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, - "post_create_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_create_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_create_connection" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_create_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_create_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6753,8 +6763,9 @@ def test_get_connection_rest_bad_request(request_type=connection.GetConnectionRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6827,17 +6838,20 @@ def test_get_connection_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_get_connection" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_get_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_get_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_get_connection" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_get_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_get_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6890,8 +6904,9 @@ def test_list_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6954,18 +6969,20 @@ def test_list_connections_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_list_connections" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, - "post_list_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_list_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_list_connections" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_list_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_list_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7020,8 +7037,9 @@ def test_update_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7219,18 +7237,20 @@ def test_update_connection_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_update_connection" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, - "post_update_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_update_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_update_connection" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_update_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_update_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7283,8 +7303,9 @@ def test_delete_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7341,13 +7362,13 @@ def test_delete_connection_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_delete_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_delete_connection" + ) as pre, + ): pre.assert_not_called() pb_message = connection.DeleteConnectionRequest.pb( connection.DeleteConnectionRequest() @@ -7394,8 +7415,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7459,17 +7481,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7522,8 +7547,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7587,17 +7613,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7650,8 +7679,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7713,18 +7743,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ConnectionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ConnectionServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConnectionServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConnectionServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8004,11 +8036,14 @@ def test_connection_service_base_transport(): def test_connection_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConnectionServiceTransport( @@ -8028,9 +8063,12 @@ def test_connection_service_base_transport_with_credentials_file(): def test_connection_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_connection_v1.services.connection_service.transports.ConnectionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConnectionServiceTransport() @@ -8108,11 +8146,12 @@ def test_connection_service_transport_auth_gdch_credentials(transport_class): def test_connection_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/async_client.py b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/async_client.py index 0dbcfa3478ef..7e4832eeeb1c 100644 --- a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/async_client.py +++ b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> AnalyticsHubServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2087,7 +2087,7 @@ async def sample_test_iam_permissions(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2113,8 +2113,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2123,7 +2127,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2131,7 +2135,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2142,7 +2146,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2168,8 +2172,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2178,7 +2186,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2186,7 +2194,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/client.py b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/client.py index 255fa207cb97..55ed1d8dcede 100644 --- a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/client.py +++ b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/client.py @@ -121,7 +121,7 @@ class AnalyticsHubServiceClient(metaclass=AnalyticsHubServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -487,7 +491,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -584,7 +588,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -684,7 +688,7 @@ def __init__( self._universe_domain = AnalyticsHubServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2523,7 +2527,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2549,8 +2553,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2559,7 +2567,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2568,7 +2576,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2582,7 +2590,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2608,8 +2616,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2618,7 +2630,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2627,7 +2639,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/README.rst b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/README.rst index dbc9199b0730..c965e5062fe6 100644 --- a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/README.rst +++ b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AnalyticsHubServiceTransport` is the ABC for all transports. -- public child `AnalyticsHubServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AnalyticsHubServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAnalyticsHubServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AnalyticsHubServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AnalyticsHubServiceTransport`` is the ABC for all transports. + +- public child ``AnalyticsHubServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AnalyticsHubServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAnalyticsHubServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AnalyticsHubServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/base.py b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/base.py index 0bc3b48fa999..26b0dff6cbcc 100644 --- a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/base.py +++ b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc.py b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc.py index 363dba685ed7..0c5d517be7cc 100644 --- a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc_asyncio.py index 6789d617eb18..58e34af852a3 100644 --- a/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-data-exchange/google/cloud/bigquery_data_exchange_v1beta1/services/analytics_hub_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-data-exchange/noxfile.py b/packages/google-cloud-bigquery-data-exchange/noxfile.py index e64cb5e0c1df..8d2df37b96d7 100644 --- a/packages/google-cloud-bigquery-data-exchange/noxfile.py +++ b/packages/google-cloud-bigquery-data-exchange/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-data-exchange/setup.py b/packages/google-cloud-bigquery-data-exchange/setup.py index 94d7deae243f..f2f861d0272a 100644 --- a/packages/google-cloud-bigquery-data-exchange/setup.py +++ b/packages/google-cloud-bigquery-data-exchange/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-data-exchange/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-data-exchange/tests/unit/gapic/bigquery_data_exchange_v1beta1/test_analytics_hub_service.py b/packages/google-cloud-bigquery-data-exchange/tests/unit/gapic/bigquery_data_exchange_v1beta1/test_analytics_hub_service.py index 289c871f805a..c6699334b38f 100644 --- a/packages/google-cloud-bigquery-data-exchange/tests/unit/gapic/bigquery_data_exchange_v1beta1/test_analytics_hub_service.py +++ b/packages/google-cloud-bigquery-data-exchange/tests/unit/gapic/bigquery_data_exchange_v1beta1/test_analytics_hub_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AnalyticsHubServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): AnalyticsHubServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AnalyticsHubServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1304,11 +1309,13 @@ def test_analytics_hub_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7929,11 +7936,14 @@ def test_analytics_hub_service_base_transport(): def test_analytics_hub_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_data_exchange_v1beta1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_data_exchange_v1beta1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsHubServiceTransport( @@ -7953,9 +7963,12 @@ def test_analytics_hub_service_base_transport_with_credentials_file(): def test_analytics_hub_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_data_exchange_v1beta1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_data_exchange_v1beta1.services.analytics_hub_service.transports.AnalyticsHubServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnalyticsHubServiceTransport() @@ -8032,11 +8045,12 @@ def test_analytics_hub_service_transport_auth_gdch_credentials(transport_class): def test_analytics_hub_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8625,6 +8639,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AnalyticsHubServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AnalyticsHubServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AnalyticsHubServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8768,6 +8816,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AnalyticsHubServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AnalyticsHubServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AnalyticsHubServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/async_client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/async_client.py index 3a2ae41cde7a..d2a5a5807a21 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/async_client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> DataPolicyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/client.py index 630c9b093855..05a1bae3424c 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/client.py @@ -115,7 +115,7 @@ class DataPolicyServiceClient(metaclass=DataPolicyServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = DataPolicyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/README.rst b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/README.rst index b83d156af245..710011198a0c 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/README.rst +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataPolicyServiceTransport` is the ABC for all transports. -- public child `DataPolicyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataPolicyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataPolicyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataPolicyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataPolicyServiceTransport`` is the ABC for all transports. + +- public child ``DataPolicyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataPolicyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataPolicyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataPolicyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/base.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/base.py index b8beac6e9a67..8d019cee98e4 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/base.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc.py index 8be3e0ffe779..4e2ce4f3924d 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc_asyncio.py index 16fe1871c9b3..524dfdfad307 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/rest.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/rest.py index e2139099b658..8b1b33f0e28c 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/rest.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1/services/data_policy_service/transports/rest.py @@ -617,6 +617,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataPolicyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/async_client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/async_client.py index dc55cb873d93..02605024d077 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/async_client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> DataPolicyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/client.py index 982347813a6e..8738ceeeb3c6 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/client.py @@ -115,7 +115,7 @@ class DataPolicyServiceClient(metaclass=DataPolicyServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = DataPolicyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/README.rst b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/README.rst index b83d156af245..710011198a0c 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/README.rst +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataPolicyServiceTransport` is the ABC for all transports. -- public child `DataPolicyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataPolicyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataPolicyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataPolicyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataPolicyServiceTransport`` is the ABC for all transports. + +- public child ``DataPolicyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataPolicyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataPolicyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataPolicyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/base.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/base.py index a431c68b8bd5..56c28757387e 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/base.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc.py index 118ee2ad85eb..cda186d3f52f 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc_asyncio.py index c118ecd854ef..b9b3844aab9b 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v1beta1/services/data_policy_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/async_client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/async_client.py index a2ff3d832373..29cd512afe32 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/async_client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> DataPolicyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/client.py index cb8fd1bc0203..718f08c9fa16 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/client.py @@ -115,7 +115,7 @@ class DataPolicyServiceClient(metaclass=DataPolicyServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -488,7 +492,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -585,7 +589,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -685,7 +689,7 @@ def __init__( self._universe_domain = DataPolicyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/README.rst b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/README.rst index b83d156af245..710011198a0c 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/README.rst +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataPolicyServiceTransport` is the ABC for all transports. -- public child `DataPolicyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataPolicyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataPolicyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataPolicyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataPolicyServiceTransport`` is the ABC for all transports. + +- public child ``DataPolicyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataPolicyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataPolicyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataPolicyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/base.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/base.py index a9ad428af1f2..2b072edcc8b6 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/base.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc.py index d6b1cacb8a85..cbeec6fa4293 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc_asyncio.py index b954f690fc45..cca4ce10fde1 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/rest.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/rest.py index b21702351b82..458a6cdafbc5 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/rest.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2/services/data_policy_service/transports/rest.py @@ -671,6 +671,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataPolicyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/async_client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/async_client.py index 26a9f348c407..4b77765e9d78 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/async_client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> DataPolicyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/client.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/client.py index c8cdc3231e2d..3c385cfc4fef 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/client.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/client.py @@ -117,7 +117,7 @@ class DataPolicyServiceClient(metaclass=DataPolicyServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = DataPolicyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/README.rst b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/README.rst index b83d156af245..710011198a0c 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/README.rst +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataPolicyServiceTransport` is the ABC for all transports. -- public child `DataPolicyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataPolicyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataPolicyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataPolicyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataPolicyServiceTransport`` is the ABC for all transports. + +- public child ``DataPolicyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataPolicyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataPolicyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataPolicyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/base.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/base.py index b463702e0ab4..64b5ddbdc743 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/base.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc.py index 2a43b507cd50..e529619cb144 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc_asyncio.py index 15a97e04478c..83665845aca9 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/rest.py b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/rest.py index 245bcabdce4c..bf70d694f1ab 100644 --- a/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/rest.py +++ b/packages/google-cloud-bigquery-datapolicies/google/cloud/bigquery_datapolicies_v2beta1/services/data_policy_service/transports/rest.py @@ -671,6 +671,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataPolicyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-datapolicies/noxfile.py b/packages/google-cloud-bigquery-datapolicies/noxfile.py index a7ee748f4de1..e3473bb1bb78 100644 --- a/packages/google-cloud-bigquery-datapolicies/noxfile.py +++ b/packages/google-cloud-bigquery-datapolicies/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-datapolicies/setup.py b/packages/google-cloud-bigquery-datapolicies/setup.py index c65e44d08313..2050cd11071e 100644 --- a/packages/google-cloud-bigquery-datapolicies/setup.py +++ b/packages/google-cloud-bigquery-datapolicies/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-datapolicies/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1/test_data_policy_service.py b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1/test_data_policy_service.py index 131e66d75ddc..09069cd03e2d 100644 --- a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1/test_data_policy_service.py +++ b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1/test_data_policy_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataPolicyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): DataPolicyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataPolicyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1323,11 +1328,13 @@ def test_data_policy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6638,8 +6645,9 @@ def test_create_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6784,18 +6792,20 @@ def test_create_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_create_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_create_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_create_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_create_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_create_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_create_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6852,8 +6862,9 @@ def test_update_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7002,18 +7013,20 @@ def test_update_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_update_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_update_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_update_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_update_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_update_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_update_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7066,8 +7079,9 @@ def test_rename_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7138,18 +7152,20 @@ def test_rename_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_rename_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_rename_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_rename_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_rename_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_rename_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_rename_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7202,8 +7218,9 @@ def test_delete_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7260,13 +7277,13 @@ def test_delete_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_delete_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_delete_data_policy" + ) as pre, + ): pre.assert_not_called() pb_message = datapolicy.DeleteDataPolicyRequest.pb( datapolicy.DeleteDataPolicyRequest() @@ -7309,8 +7326,9 @@ def test_get_data_policy_rest_bad_request(request_type=datapolicy.GetDataPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7381,18 +7399,20 @@ def test_get_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_get_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_get_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_get_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_get_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_get_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7445,8 +7465,9 @@ def test_list_data_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7509,18 +7530,20 @@ def test_list_data_policies_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_list_data_policies" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_list_data_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_list_data_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_list_data_policies" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_list_data_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_list_data_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7580,8 +7603,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7645,17 +7669,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7708,8 +7735,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7773,17 +7801,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7836,8 +7867,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7899,18 +7931,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8215,11 +8249,14 @@ def test_data_policy_service_base_transport(): def test_data_policy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_datapolicies_v1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_datapolicies_v1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport( @@ -8239,9 +8276,12 @@ def test_data_policy_service_base_transport_with_credentials_file(): def test_data_policy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_datapolicies_v1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_datapolicies_v1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport() @@ -8319,11 +8359,12 @@ def test_data_policy_service_transport_auth_gdch_credentials(transport_class): def test_data_policy_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1beta1/test_data_policy_service.py b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1beta1/test_data_policy_service.py index c9220d732ee0..34052887c1ae 100644 --- a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1beta1/test_data_policy_service.py +++ b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v1beta1/test_data_policy_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataPolicyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): DataPolicyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataPolicyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1288,11 +1293,13 @@ def test_data_policy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4640,11 +4647,14 @@ def test_data_policy_service_base_transport(): def test_data_policy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_datapolicies_v1beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_datapolicies_v1beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport( @@ -4664,9 +4674,12 @@ def test_data_policy_service_base_transport_with_credentials_file(): def test_data_policy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_datapolicies_v1beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_datapolicies_v1beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport() @@ -4743,11 +4756,12 @@ def test_data_policy_service_transport_auth_gdch_credentials(transport_class): def test_data_policy_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2/test_data_policy_service.py b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2/test_data_policy_service.py index d08ed4d4b0a3..ef7297e0cc1c 100644 --- a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2/test_data_policy_service.py +++ b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2/test_data_policy_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataPolicyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): DataPolicyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataPolicyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1323,11 +1328,13 @@ def test_data_policy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7392,8 +7399,9 @@ def test_create_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7471,18 +7479,20 @@ def test_create_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_create_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_create_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_create_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_create_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_create_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_create_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7535,8 +7545,9 @@ def test_add_grantees_rest_bad_request(request_type=datapolicy.AddGranteesReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7616,17 +7627,20 @@ def test_add_grantees_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_add_grantees" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_add_grantees_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_add_grantees" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_add_grantees" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_add_grantees_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_add_grantees" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7679,8 +7693,9 @@ def test_remove_grantees_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7760,18 +7775,20 @@ def test_remove_grantees_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_remove_grantees" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_remove_grantees_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_remove_grantees" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_remove_grantees" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_remove_grantees_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_remove_grantees" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7828,8 +7845,9 @@ def test_update_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7988,18 +8006,20 @@ def test_update_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_update_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_update_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_update_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_update_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_update_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_update_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8052,8 +8072,9 @@ def test_delete_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8110,13 +8131,13 @@ def test_delete_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_delete_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_delete_data_policy" + ) as pre, + ): pre.assert_not_called() pb_message = datapolicy.DeleteDataPolicyRequest.pb( datapolicy.DeleteDataPolicyRequest() @@ -8159,8 +8180,9 @@ def test_get_data_policy_rest_bad_request(request_type=datapolicy.GetDataPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8238,18 +8260,20 @@ def test_get_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_get_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_get_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_get_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_get_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_get_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8302,8 +8326,9 @@ def test_list_data_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8366,18 +8391,20 @@ def test_list_data_policies_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_list_data_policies" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_list_data_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_list_data_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_list_data_policies" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_list_data_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_list_data_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8437,8 +8464,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8502,17 +8530,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8565,8 +8596,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8630,17 +8662,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8693,8 +8728,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8756,18 +8792,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9091,11 +9129,14 @@ def test_data_policy_service_base_transport(): def test_data_policy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_datapolicies_v2.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_datapolicies_v2.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport( @@ -9115,9 +9156,12 @@ def test_data_policy_service_base_transport_with_credentials_file(): def test_data_policy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_datapolicies_v2.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_datapolicies_v2.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport() @@ -9195,11 +9239,12 @@ def test_data_policy_service_transport_auth_gdch_credentials(transport_class): def test_data_policy_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2beta1/test_data_policy_service.py b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2beta1/test_data_policy_service.py index ee384eeb6c1e..94a5a580ca3a 100644 --- a/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2beta1/test_data_policy_service.py +++ b/packages/google-cloud-bigquery-datapolicies/tests/unit/gapic/bigquery_datapolicies_v2beta1/test_data_policy_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataPolicyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): DataPolicyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataPolicyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1323,11 +1328,13 @@ def test_data_policy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7375,8 +7382,9 @@ def test_create_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7454,18 +7462,20 @@ def test_create_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_create_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_create_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_create_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_create_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_create_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_create_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7518,8 +7528,9 @@ def test_add_grantees_rest_bad_request(request_type=datapolicy.AddGranteesReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7599,17 +7610,20 @@ def test_add_grantees_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_add_grantees" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_add_grantees_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_add_grantees" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_add_grantees" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_add_grantees_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_add_grantees" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7662,8 +7676,9 @@ def test_remove_grantees_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7743,18 +7758,20 @@ def test_remove_grantees_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_remove_grantees" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_remove_grantees_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_remove_grantees" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_remove_grantees" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_remove_grantees_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_remove_grantees" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7811,8 +7828,9 @@ def test_update_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7971,18 +7989,20 @@ def test_update_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_update_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_update_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_update_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_update_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_update_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_update_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8035,8 +8055,9 @@ def test_delete_data_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8093,13 +8114,13 @@ def test_delete_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_delete_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_delete_data_policy" + ) as pre, + ): pre.assert_not_called() pb_message = datapolicy.DeleteDataPolicyRequest.pb( datapolicy.DeleteDataPolicyRequest() @@ -8142,8 +8163,9 @@ def test_get_data_policy_rest_bad_request(request_type=datapolicy.GetDataPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8221,18 +8243,20 @@ def test_get_data_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_data_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_get_data_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_get_data_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_get_data_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_get_data_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_get_data_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8285,8 +8309,9 @@ def test_list_data_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8349,18 +8374,20 @@ def test_list_data_policies_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_list_data_policies" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_list_data_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_list_data_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_list_data_policies" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_list_data_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_list_data_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8420,8 +8447,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8485,17 +8513,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8548,8 +8579,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8613,17 +8645,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8676,8 +8711,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8739,18 +8775,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = DataPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataPolicyServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataPolicyServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9074,11 +9112,14 @@ def test_data_policy_service_base_transport(): def test_data_policy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_datapolicies_v2beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_datapolicies_v2beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport( @@ -9098,9 +9139,12 @@ def test_data_policy_service_base_transport_with_credentials_file(): def test_data_policy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_datapolicies_v2beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_datapolicies_v2beta1.services.data_policy_service.transports.DataPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataPolicyServiceTransport() @@ -9178,11 +9222,12 @@ def test_data_policy_service_transport_auth_gdch_credentials(transport_class): def test_data_policy_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/async_client.py b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/async_client.py index 1c1f2de59164..f89c2d4b92fc 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/async_client.py +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> DataTransferServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2191,7 +2191,7 @@ async def sample_unenroll_data_sources(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2217,8 +2217,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2227,7 +2231,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2235,7 +2239,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2246,7 +2250,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2272,8 +2276,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2282,7 +2290,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2290,7 +2298,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py index 1ea2ea896fd9..b88a2e9b8758 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py @@ -118,7 +118,7 @@ class DataTransferServiceClient(metaclass=DataTransferServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -482,7 +486,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -579,7 +583,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -679,7 +683,7 @@ def __init__( self._universe_domain = DataTransferServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2620,7 +2624,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2646,8 +2650,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2656,7 +2664,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2665,7 +2673,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2679,7 +2687,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2705,8 +2713,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2715,7 +2727,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2724,7 +2736,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/README.rst b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/README.rst index 6f9ef878ffff..0c85aedd771b 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/README.rst +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataTransferServiceTransport` is the ABC for all transports. -- public child `DataTransferServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataTransferServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataTransferServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataTransferServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataTransferServiceTransport`` is the ABC for all transports. + +- public child ``DataTransferServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataTransferServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataTransferServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataTransferServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/base.py b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/base.py index bba198be487e..e20c393dd6a6 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/base.py +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc.py b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc.py index 28d420a066fd..9c9c1a1494c4 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc_asyncio.py index 195fe511facb..69244c977c89 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/rest.py b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/rest.py index 1b96db40e650..19f552c9ee99 100644 --- a/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/rest.py +++ b/packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/rest.py @@ -964,6 +964,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataTransferServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-datatransfer/noxfile.py b/packages/google-cloud-bigquery-datatransfer/noxfile.py index 01ea6ced94e2..85f39a160c11 100644 --- a/packages/google-cloud-bigquery-datatransfer/noxfile.py +++ b/packages/google-cloud-bigquery-datatransfer/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-datatransfer/setup.py b/packages/google-cloud-bigquery-datatransfer/setup.py index f0903d16d1a8..70bf2346092e 100644 --- a/packages/google-cloud-bigquery-datatransfer/setup.py +++ b/packages/google-cloud-bigquery-datatransfer/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-bigquery-datatransfer" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-datatransfer/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-bigquery-datatransfer/tests/unit/gapic/bigquery_datatransfer_v1/test_data_transfer_service.py b/packages/google-cloud-bigquery-datatransfer/tests/unit/gapic/bigquery_datatransfer_v1/test_data_transfer_service.py index 5ad4de062c36..bbc945ad3d3f 100644 --- a/packages/google-cloud-bigquery-datatransfer/tests/unit/gapic/bigquery_datatransfer_v1/test_data_transfer_service.py +++ b/packages/google-cloud-bigquery-datatransfer/tests/unit/gapic/bigquery_datatransfer_v1/test_data_transfer_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataTransferServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): DataTransferServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataTransferServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1348,11 +1353,13 @@ def test_data_transfer_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -11681,8 +11688,9 @@ def test_get_data_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11781,18 +11789,20 @@ def test_get_data_source_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_get_data_source" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_get_data_source_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_get_data_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_get_data_source" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_get_data_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_get_data_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11845,8 +11855,9 @@ def test_list_data_sources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11909,18 +11920,20 @@ def test_list_data_sources_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_list_data_sources" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_list_data_sources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_list_data_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_list_data_sources" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_list_data_sources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_list_data_sources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11978,8 +11991,9 @@ def test_create_transfer_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12173,18 +12187,20 @@ def test_create_transfer_config_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_create_transfer_config" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_create_transfer_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_create_transfer_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_create_transfer_config" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_create_transfer_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_create_transfer_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12241,8 +12257,9 @@ def test_update_transfer_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12440,18 +12457,20 @@ def test_update_transfer_config_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_update_transfer_config" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_update_transfer_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_update_transfer_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_update_transfer_config" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_update_transfer_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_update_transfer_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12506,8 +12525,9 @@ def test_delete_transfer_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12566,13 +12586,13 @@ def test_delete_transfer_config_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_delete_transfer_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_delete_transfer_config" + ) as pre, + ): pre.assert_not_called() pb_message = datatransfer.DeleteTransferConfigRequest.pb( datatransfer.DeleteTransferConfigRequest() @@ -12619,8 +12639,9 @@ def test_get_transfer_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12704,18 +12725,20 @@ def test_get_transfer_config_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_get_transfer_config" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_get_transfer_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_get_transfer_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_get_transfer_config" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_get_transfer_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_get_transfer_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12768,8 +12791,9 @@ def test_list_transfer_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12832,18 +12856,20 @@ def test_list_transfer_configs_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_list_transfer_configs" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_list_transfer_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_list_transfer_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_list_transfer_configs" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_list_transfer_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_list_transfer_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12903,8 +12929,9 @@ def test_schedule_transfer_runs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12966,18 +12993,20 @@ def test_schedule_transfer_runs_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_schedule_transfer_runs" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_schedule_transfer_runs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_schedule_transfer_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_schedule_transfer_runs" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_schedule_transfer_runs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_schedule_transfer_runs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13037,8 +13066,9 @@ def test_start_manual_transfer_runs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13100,18 +13130,22 @@ def test_start_manual_transfer_runs_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_start_manual_transfer_runs" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_start_manual_transfer_runs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_start_manual_transfer_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_start_manual_transfer_runs", + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_start_manual_transfer_runs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "pre_start_manual_transfer_runs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13171,8 +13205,9 @@ def test_get_transfer_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13248,18 +13283,20 @@ def test_get_transfer_run_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_get_transfer_run" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_get_transfer_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_get_transfer_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_get_transfer_run" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_get_transfer_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_get_transfer_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13314,8 +13351,9 @@ def test_delete_transfer_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13374,13 +13412,13 @@ def test_delete_transfer_run_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_delete_transfer_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_delete_transfer_run" + ) as pre, + ): pre.assert_not_called() pb_message = datatransfer.DeleteTransferRunRequest.pb( datatransfer.DeleteTransferRunRequest() @@ -13427,8 +13465,9 @@ def test_list_transfer_runs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13493,18 +13532,20 @@ def test_list_transfer_runs_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_list_transfer_runs" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_list_transfer_runs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_list_transfer_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_list_transfer_runs" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_list_transfer_runs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_list_transfer_runs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13564,8 +13605,9 @@ def test_list_transfer_logs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13630,18 +13672,20 @@ def test_list_transfer_logs_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_list_transfer_logs" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_list_transfer_logs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_list_transfer_logs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_list_transfer_logs" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_list_transfer_logs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_list_transfer_logs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13699,8 +13743,9 @@ def test_check_valid_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13763,18 +13808,20 @@ def test_check_valid_creds_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "post_check_valid_creds" - ) as post, mock.patch.object( - transports.DataTransferServiceRestInterceptor, - "post_check_valid_creds_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_check_valid_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "post_check_valid_creds" + ) as post, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, + "post_check_valid_creds_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_check_valid_creds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13832,8 +13879,9 @@ def test_enroll_data_sources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13890,13 +13938,13 @@ def test_enroll_data_sources_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_enroll_data_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_enroll_data_sources" + ) as pre, + ): pre.assert_not_called() pb_message = datatransfer.EnrollDataSourcesRequest.pb( datatransfer.EnrollDataSourcesRequest() @@ -13941,8 +13989,9 @@ def test_unenroll_data_sources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13999,13 +14048,13 @@ def test_unenroll_data_sources_rest_interceptors(null_interceptor): ) client = DataTransferServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTransferServiceRestInterceptor, "pre_unenroll_data_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTransferServiceRestInterceptor, "pre_unenroll_data_sources" + ) as pre, + ): pre.assert_not_called() pb_message = datatransfer.UnenrollDataSourcesRequest.pb( datatransfer.UnenrollDataSourcesRequest() @@ -14050,8 +14099,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14110,8 +14160,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14584,11 +14635,14 @@ def test_data_transfer_service_base_transport(): def test_data_transfer_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.transports.DataTransferServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.transports.DataTransferServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataTransferServiceTransport( @@ -14605,9 +14659,12 @@ def test_data_transfer_service_base_transport_with_credentials_file(): def test_data_transfer_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.transports.DataTransferServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.transports.DataTransferServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataTransferServiceTransport() @@ -14679,11 +14736,12 @@ def test_data_transfer_service_transport_auth_gdch_credentials(transport_class): def test_data_transfer_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -15345,6 +15403,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataTransferServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataTransferServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataTransferServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15488,6 +15580,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataTransferServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataTransferServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataTransferServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-bigquery-logging/noxfile.py b/packages/google-cloud-bigquery-logging/noxfile.py index 5856a6a2c47c..37899ff20929 100644 --- a/packages/google-cloud-bigquery-logging/noxfile.py +++ b/packages/google-cloud-bigquery-logging/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-logging/setup.py b/packages/google-cloud-bigquery-logging/setup.py index bafda5d93442..7cc18d8ea9c1 100644 --- a/packages/google-cloud-bigquery-logging/setup.py +++ b/packages/google-cloud-bigquery-logging/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-logging/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-logging/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bigquery-logging/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-logging/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-logging/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bigquery-logging/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bigquery-logging/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-logging/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bigquery-logging/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-logging/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/async_client.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/async_client.py index e145142e22d2..8a90da9aa001 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/async_client.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> MigrationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/client.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/client.py index 8f699cd2ed33..c5e8060110dd 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/client.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/client.py @@ -115,7 +115,7 @@ class MigrationServiceClient(metaclass=MigrationServiceClientMeta): """Service to handle EDW migrations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -561,7 +565,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -659,7 +663,7 @@ def __init__( self._universe_domain = MigrationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/README.rst b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/README.rst index ef5e0cb2c853..e7d0f4026c4b 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/README.rst +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MigrationServiceTransport` is the ABC for all transports. -- public child `MigrationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MigrationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMigrationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MigrationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MigrationServiceTransport`` is the ABC for all transports. + +- public child ``MigrationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MigrationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMigrationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MigrationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/base.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/base.py index 28a2b6366d15..e1156cddd36e 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/base.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc.py index c96be6ad43e5..a8356401c601 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc_asyncio.py index af82c8b62fc9..41a54104a882 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2/services/migration_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/async_client.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/async_client.py index 8bb86a70df9c..a4b92275dc9f 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/async_client.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> MigrationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/client.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/client.py index 487302e185d2..b82dcc2797b3 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/client.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/client.py @@ -115,7 +115,7 @@ class MigrationServiceClient(metaclass=MigrationServiceClientMeta): """Service to handle EDW migrations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -561,7 +565,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -659,7 +663,7 @@ def __init__( self._universe_domain = MigrationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/README.rst b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/README.rst index ef5e0cb2c853..e7d0f4026c4b 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/README.rst +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MigrationServiceTransport` is the ABC for all transports. -- public child `MigrationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MigrationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMigrationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MigrationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MigrationServiceTransport`` is the ABC for all transports. + +- public child ``MigrationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MigrationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMigrationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MigrationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/base.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/base.py index c4af6da7e24b..fad5aa9667e5 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/base.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc.py index 4b49035003f2..7281833be2d8 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc_asyncio.py index 8ab9b9e95d8d..f8ad2293bccb 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/migration_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/async_client.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/async_client.py index bdf36c5f56e3..190bb99f0ba5 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/async_client.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> SqlTranslationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/client.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/client.py index 605a9d0bd957..ba079967fe63 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/client.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/client.py @@ -108,7 +108,7 @@ class SqlTranslationServiceClient(metaclass=SqlTranslationServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = SqlTranslationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/README.rst b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/README.rst index 67b67fcd4e6d..db71c3e21fa4 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/README.rst +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SqlTranslationServiceTransport` is the ABC for all transports. -- public child `SqlTranslationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SqlTranslationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSqlTranslationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SqlTranslationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SqlTranslationServiceTransport`` is the ABC for all transports. + +- public child ``SqlTranslationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SqlTranslationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSqlTranslationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SqlTranslationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/base.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/base.py index 9050218b0e99..582b84191d52 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/base.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc.py index 7345cda2ff82..875fe4b679cd 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc_asyncio.py index e03f8a1bbaa8..2e923bddf907 100644 --- a/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-migration/google/cloud/bigquery_migration_v2alpha/services/sql_translation_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-migration/noxfile.py b/packages/google-cloud-bigquery-migration/noxfile.py index a97c5bf10814..d4ad3ca6bd8d 100644 --- a/packages/google-cloud-bigquery-migration/noxfile.py +++ b/packages/google-cloud-bigquery-migration/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-migration/setup.py b/packages/google-cloud-bigquery-migration/setup.py index 6eb74aee78b8..282ea579dfca 100644 --- a/packages/google-cloud-bigquery-migration/setup.py +++ b/packages/google-cloud-bigquery-migration/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-bigquery-migration" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-migration/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-migration/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-bigquery-migration/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-bigquery-migration/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-migration/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-bigquery-migration/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-bigquery-migration/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-migration/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-bigquery-migration/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-migration/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2/test_migration_service.py b/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2/test_migration_service.py index 0e2cbd7c946c..91c726e9dbf3 100644 --- a/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2/test_migration_service.py +++ b/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2/test_migration_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MigrationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): MigrationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MigrationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_migration_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4692,11 +4699,14 @@ def test_migration_service_base_transport(): def test_migration_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_migration_v2.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_migration_v2.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationServiceTransport( @@ -4713,9 +4723,12 @@ def test_migration_service_base_transport_with_credentials_file(): def test_migration_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_migration_v2.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_migration_v2.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationServiceTransport() @@ -4786,11 +4799,12 @@ def test_migration_service_transport_auth_gdch_credentials(transport_class): def test_migration_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_migration_service.py b/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_migration_service.py index 8eb21717df5e..601fe5a54861 100644 --- a/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_migration_service.py +++ b/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_migration_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MigrationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): MigrationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MigrationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1286,11 +1291,13 @@ def test_migration_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4689,11 +4696,14 @@ def test_migration_service_base_transport(): def test_migration_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_migration_v2alpha.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_migration_v2alpha.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationServiceTransport( @@ -4710,9 +4720,12 @@ def test_migration_service_base_transport_with_credentials_file(): def test_migration_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_migration_v2alpha.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_migration_v2alpha.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationServiceTransport() @@ -4783,11 +4796,12 @@ def test_migration_service_transport_auth_gdch_credentials(transport_class): def test_migration_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_sql_translation_service.py b/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_sql_translation_service.py index a0e8c8f257d5..c3e38ace88cb 100644 --- a/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_sql_translation_service.py +++ b/packages/google-cloud-bigquery-migration/tests/unit/gapic/bigquery_migration_v2alpha/test_sql_translation_service.py @@ -115,6 +115,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SqlTranslationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -137,6 +138,10 @@ def test__get_default_mtls_endpoint(): SqlTranslationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SqlTranslationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1298,11 +1303,13 @@ def test_sql_translation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1893,11 +1900,14 @@ def test_sql_translation_service_base_transport(): def test_sql_translation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_migration_v2alpha.services.sql_translation_service.transports.SqlTranslationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_migration_v2alpha.services.sql_translation_service.transports.SqlTranslationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SqlTranslationServiceTransport( @@ -1914,9 +1924,12 @@ def test_sql_translation_service_base_transport_with_credentials_file(): def test_sql_translation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_migration_v2alpha.services.sql_translation_service.transports.SqlTranslationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_migration_v2alpha.services.sql_translation_service.transports.SqlTranslationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SqlTranslationServiceTransport() @@ -1989,11 +2002,12 @@ def test_sql_translation_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py index e298f5ecc508..b11b30b3f6fd 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py @@ -231,7 +231,7 @@ def transport(self) -> ReservationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py index 4787accb29e9..f6cbc558ee13 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py @@ -132,7 +132,7 @@ class ReservationServiceClient(metaclass=ReservationServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -140,7 +140,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -150,6 +150,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -547,7 +551,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -644,7 +648,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -744,7 +748,7 @@ def __init__( self._universe_domain = ReservationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/README.rst b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/README.rst index b69ca178e2ae..85ee33768064 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/README.rst +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationServiceTransport` is the ABC for all transports. -- public child `ReservationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationServiceTransport`` is the ABC for all transports. + +- public child ``ReservationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py index a3216df37cb1..78f4cf271cd1 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py index de99768eacea..e1e158b3e20a 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -203,6 +203,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py index aa879acbfeb1..16406daec870 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -254,6 +254,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/rest.py b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/rest.py index dcf1dfc39087..127ee54c9afe 100644 --- a/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/rest.py +++ b/packages/google-cloud-bigquery-reservation/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/rest.py @@ -1666,6 +1666,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-bigquery-reservation/noxfile.py b/packages/google-cloud-bigquery-reservation/noxfile.py index 2c3f097e8d8c..26efc90a249d 100644 --- a/packages/google-cloud-bigquery-reservation/noxfile.py +++ b/packages/google-cloud-bigquery-reservation/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-reservation/setup.py b/packages/google-cloud-bigquery-reservation/setup.py index a993c592ada6..e50e7c45f487 100644 --- a/packages/google-cloud-bigquery-reservation/setup.py +++ b/packages/google-cloud-bigquery-reservation/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-reservation/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-reservation/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-bigquery-reservation/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-reservation/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-reservation/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-bigquery-reservation/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-bigquery-reservation/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-reservation/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-bigquery-reservation/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-reservation/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-bigquery-reservation/tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py b/packages/google-cloud-bigquery-reservation/tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py index f8f4b0eb2cc6..89f07427743f 100644 --- a/packages/google-cloud-bigquery-reservation/tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py +++ b/packages/google-cloud-bigquery-reservation/tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): ReservationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1331,11 +1336,13 @@ def test_reservation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -19581,8 +19588,9 @@ def test_create_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19770,18 +19778,20 @@ def test_create_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_create_reservation" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_create_reservation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_create_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_create_reservation" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_create_reservation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_create_reservation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19836,8 +19846,9 @@ def test_list_reservations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19900,18 +19911,20 @@ def test_list_reservations_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_list_reservations" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_list_reservations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_list_reservations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_list_reservations" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_list_reservations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_list_reservations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19969,8 +19982,9 @@ def test_get_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20055,18 +20069,20 @@ def test_get_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_get_reservation" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_get_reservation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_get_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_get_reservation" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_get_reservation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_get_reservation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20119,8 +20135,9 @@ def test_delete_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20177,13 +20194,13 @@ def test_delete_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_delete_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_delete_reservation" + ) as pre, + ): pre.assert_not_called() pb_message = reservation.DeleteReservationRequest.pb( reservation.DeleteReservationRequest() @@ -20232,8 +20249,9 @@ def test_update_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20425,18 +20443,20 @@ def test_update_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_update_reservation" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_update_reservation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_update_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_update_reservation" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_update_reservation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_update_reservation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20491,8 +20511,9 @@ def test_failover_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20577,18 +20598,20 @@ def test_failover_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_failover_reservation" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_failover_reservation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_failover_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_failover_reservation" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_failover_reservation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_failover_reservation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20641,8 +20664,9 @@ def test_create_capacity_commitment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20810,18 +20834,22 @@ def test_create_capacity_commitment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_create_capacity_commitment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_create_capacity_commitment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_create_capacity_commitment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_create_capacity_commitment", + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_create_capacity_commitment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "pre_create_capacity_commitment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20876,8 +20904,9 @@ def test_list_capacity_commitments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20940,18 +20969,22 @@ def test_list_capacity_commitments_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_list_capacity_commitments" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_list_capacity_commitments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_list_capacity_commitments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_list_capacity_commitments", + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_list_capacity_commitments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "pre_list_capacity_commitments", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21011,8 +21044,9 @@ def test_get_capacity_commitment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21091,18 +21125,20 @@ def test_get_capacity_commitment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_get_capacity_commitment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_get_capacity_commitment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_get_capacity_commitment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_get_capacity_commitment" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_get_capacity_commitment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_get_capacity_commitment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21159,8 +21195,9 @@ def test_delete_capacity_commitment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21219,13 +21256,14 @@ def test_delete_capacity_commitment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_delete_capacity_commitment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "pre_delete_capacity_commitment", + ) as pre, + ): pre.assert_not_called() pb_message = reservation.DeleteCapacityCommitmentRequest.pb( reservation.DeleteCapacityCommitmentRequest() @@ -21274,8 +21312,9 @@ def test_update_capacity_commitment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21447,18 +21486,22 @@ def test_update_capacity_commitment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_update_capacity_commitment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_update_capacity_commitment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_update_capacity_commitment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_update_capacity_commitment", + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_update_capacity_commitment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "pre_update_capacity_commitment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21515,8 +21558,9 @@ def test_split_capacity_commitment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21578,18 +21622,22 @@ def test_split_capacity_commitment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_split_capacity_commitment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_split_capacity_commitment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_split_capacity_commitment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_split_capacity_commitment", + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_split_capacity_commitment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "pre_split_capacity_commitment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21647,8 +21695,9 @@ def test_merge_capacity_commitments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21725,18 +21774,22 @@ def test_merge_capacity_commitments_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_merge_capacity_commitments" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_merge_capacity_commitments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_merge_capacity_commitments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_merge_capacity_commitments", + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_merge_capacity_commitments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "pre_merge_capacity_commitments", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21791,8 +21844,9 @@ def test_create_assignment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21938,18 +21992,20 @@ def test_create_assignment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_create_assignment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_create_assignment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_create_assignment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_create_assignment" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_create_assignment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_create_assignment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22002,8 +22058,9 @@ def test_list_assignments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22066,18 +22123,20 @@ def test_list_assignments_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_list_assignments" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_list_assignments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_list_assignments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_list_assignments" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_list_assignments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_list_assignments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22137,8 +22196,9 @@ def test_delete_assignment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22197,13 +22257,13 @@ def test_delete_assignment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_delete_assignment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_delete_assignment" + ) as pre, + ): pre.assert_not_called() pb_message = reservation.DeleteAssignmentRequest.pb( reservation.DeleteAssignmentRequest() @@ -22248,8 +22308,9 @@ def test_search_assignments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22312,18 +22373,20 @@ def test_search_assignments_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_search_assignments" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_search_assignments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_search_assignments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_search_assignments" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_search_assignments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_search_assignments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22381,8 +22444,9 @@ def test_search_all_assignments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22445,18 +22509,20 @@ def test_search_all_assignments_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_search_all_assignments" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_search_all_assignments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_search_all_assignments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_search_all_assignments" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_search_all_assignments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_search_all_assignments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22516,8 +22582,9 @@ def test_move_assignment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22590,18 +22657,20 @@ def test_move_assignment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_move_assignment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_move_assignment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_move_assignment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_move_assignment" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_move_assignment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_move_assignment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22658,8 +22727,9 @@ def test_update_assignment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22809,18 +22879,20 @@ def test_update_assignment_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_update_assignment" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_update_assignment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_update_assignment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_update_assignment" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_update_assignment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_update_assignment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22873,8 +22945,9 @@ def test_get_bi_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22939,18 +23012,20 @@ def test_get_bi_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_get_bi_reservation" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_get_bi_reservation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_get_bi_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_get_bi_reservation" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_get_bi_reservation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_get_bi_reservation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23005,8 +23080,9 @@ def test_update_bi_reservation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23152,18 +23228,20 @@ def test_update_bi_reservation_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_update_bi_reservation" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_update_bi_reservation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_update_bi_reservation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_update_bi_reservation" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_update_bi_reservation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_update_bi_reservation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23218,8 +23296,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23283,18 +23362,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23347,8 +23428,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23412,18 +23494,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23476,8 +23560,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23539,18 +23624,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23606,8 +23693,9 @@ def test_create_reservation_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23740,18 +23828,21 @@ def test_create_reservation_group_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_create_reservation_group" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_create_reservation_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_create_reservation_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_create_reservation_group", + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_create_reservation_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_create_reservation_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23808,8 +23899,9 @@ def test_get_reservation_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23874,18 +23966,20 @@ def test_get_reservation_group_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_get_reservation_group" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_get_reservation_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_get_reservation_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_get_reservation_group" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_get_reservation_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_get_reservation_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23942,8 +24036,9 @@ def test_delete_reservation_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24002,13 +24097,13 @@ def test_delete_reservation_group_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_delete_reservation_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_delete_reservation_group" + ) as pre, + ): pre.assert_not_called() pb_message = reservation.DeleteReservationGroupRequest.pb( reservation.DeleteReservationGroupRequest() @@ -24053,8 +24148,9 @@ def test_list_reservation_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24117,18 +24213,20 @@ def test_list_reservation_groups_rest_interceptors(null_interceptor): ) client = ReservationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationServiceRestInterceptor, "post_list_reservation_groups" - ) as post, mock.patch.object( - transports.ReservationServiceRestInterceptor, - "post_list_reservation_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationServiceRestInterceptor, "pre_list_reservation_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "post_list_reservation_groups" + ) as post, + mock.patch.object( + transports.ReservationServiceRestInterceptor, + "post_list_reservation_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationServiceRestInterceptor, "pre_list_reservation_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24891,11 +24989,14 @@ def test_reservation_service_base_transport(): def test_reservation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationServiceTransport( @@ -24915,9 +25016,12 @@ def test_reservation_service_base_transport_with_credentials_file(): def test_reservation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationServiceTransport() @@ -24995,11 +25099,12 @@ def test_reservation_service_transport_auth_gdch_credentials(transport_class): def test_reservation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/async_client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/async_client.py index 9f63dcfd71fc..7c207ca9c89c 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/async_client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> BigQueryReadTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/client.py index efad33d545bf..20803dec0f13 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/client.py @@ -112,7 +112,7 @@ class BigQueryReadClient(metaclass=BigQueryReadClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -483,7 +487,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -580,7 +584,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -676,7 +680,7 @@ def __init__( self._universe_domain = BigQueryReadClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/README.rst b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/README.rst index 687d374a1668..19debe02888e 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/README.rst +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigQueryReadTransport` is the ABC for all transports. -- public child `BigQueryReadGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigQueryReadGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigQueryReadRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigQueryReadRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigQueryReadTransport`` is the ABC for all transports. + +- public child ``BigQueryReadGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigQueryReadGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigQueryReadRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigQueryReadRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/base.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/base.py index 4f8f8b1cae88..e0f3f00ec2cb 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/base.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc.py index 1bb4eb1b974d..f778c0aabdd7 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc_asyncio.py index 77cfc5f750f9..3e7181e426ef 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_read/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/async_client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/async_client.py index 1194fca60ddd..cab0ed19ed23 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/async_client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/async_client.py @@ -199,7 +199,7 @@ def transport(self) -> BigQueryWriteTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/client.py index 5a95b6e76176..0890db4d1014 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/client.py @@ -118,7 +118,7 @@ class BigQueryWriteClient(metaclass=BigQueryWriteClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = BigQueryWriteClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/README.rst b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/README.rst index d2db1fed7502..e82a5146b2f6 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/README.rst +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigQueryWriteTransport` is the ABC for all transports. -- public child `BigQueryWriteGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigQueryWriteGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigQueryWriteRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigQueryWriteRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigQueryWriteTransport`` is the ABC for all transports. + +- public child ``BigQueryWriteGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigQueryWriteGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigQueryWriteRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigQueryWriteRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/base.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/base.py index 83c409bfdde1..1997d880a6a2 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/base.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc.py index 65235810b39a..edb92768ef74 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc_asyncio.py index 83dfecb3d713..1bfd9f9b5896 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/services/big_query_write/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/async_client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/async_client.py index 6aaa104ecfa0..d6a38ed4b2be 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/async_client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> MetastorePartitionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/client.py index 068e4443ab32..7876baad7c7e 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/client.py @@ -112,7 +112,7 @@ class MetastorePartitionServiceClient(metaclass=MetastorePartitionServiceClientM """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -560,7 +564,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = MetastorePartitionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/README.rst b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/README.rst index ff0f177aa3e5..8ad1b0c95ee0 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/README.rst +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetastorePartitionServiceTransport` is the ABC for all transports. -- public child `MetastorePartitionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetastorePartitionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetastorePartitionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetastorePartitionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetastorePartitionServiceTransport`` is the ABC for all transports. + +- public child ``MetastorePartitionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetastorePartitionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetastorePartitionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetastorePartitionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/base.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/base.py index 0d28635e60a7..1ed3979f6385 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/base.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc.py index 76f0d1376746..f272081aa665 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc_asyncio.py index b81caa4c9a63..0b3b482dda44 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1alpha/services/metastore_partition_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/async_client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/async_client.py index 948d7976f000..d74a762b48ee 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/async_client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> MetastorePartitionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/client.py index f4cb6522be41..777203659bff 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/client.py @@ -112,7 +112,7 @@ class MetastorePartitionServiceClient(metaclass=MetastorePartitionServiceClientM """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -560,7 +564,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = MetastorePartitionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/README.rst b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/README.rst index ff0f177aa3e5..8ad1b0c95ee0 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/README.rst +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetastorePartitionServiceTransport` is the ABC for all transports. -- public child `MetastorePartitionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetastorePartitionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetastorePartitionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetastorePartitionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetastorePartitionServiceTransport`` is the ABC for all transports. + +- public child ``MetastorePartitionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetastorePartitionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetastorePartitionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetastorePartitionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/base.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/base.py index d731a0f6bd96..69a8c151f69c 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/base.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc.py index 47e8bdd06780..38a997bb1d00 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc_asyncio.py index 77125af97365..1a2c9c8e8db2 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta/services/metastore_partition_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/async_client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/async_client.py index 87aaf5b0e556..9d5dc89ddff9 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/async_client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> BigQueryReadTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py index 7bd1ef2a2f7c..9c8d8550c716 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py @@ -115,7 +115,7 @@ class BigQueryReadClient(metaclass=BigQueryReadClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -486,7 +490,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -583,7 +587,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -679,7 +683,7 @@ def __init__( self._universe_domain = BigQueryReadClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/README.rst b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/README.rst index 687d374a1668..19debe02888e 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/README.rst +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigQueryReadTransport` is the ABC for all transports. -- public child `BigQueryReadGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigQueryReadGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigQueryReadRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigQueryReadRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigQueryReadTransport`` is the ABC for all transports. + +- public child ``BigQueryReadGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigQueryReadGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigQueryReadRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigQueryReadRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/base.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/base.py index 04af897a34bc..b484d4cdf17a 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/base.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc.py index 70b00dd46044..6683dbcaa0b2 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc_asyncio.py index d9480070e515..99b49e0c326c 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_read/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/async_client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/async_client.py index 7dba19ada44d..7c664ee19a1d 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/async_client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> BigQueryWriteTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py index 1339a1cfce53..67d8a9f56b47 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py @@ -119,7 +119,7 @@ class BigQueryWriteClient(metaclass=BigQueryWriteClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = BigQueryWriteClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/README.rst b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/README.rst index d2db1fed7502..e82a5146b2f6 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/README.rst +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigQueryWriteTransport` is the ABC for all transports. -- public child `BigQueryWriteGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigQueryWriteGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigQueryWriteRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigQueryWriteRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigQueryWriteTransport`` is the ABC for all transports. + +- public child ``BigQueryWriteGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigQueryWriteGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigQueryWriteRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigQueryWriteRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/base.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/base.py index 3ec7406c9a90..d23fd4d1e7ab 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/base.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc.py index 215b3f16cdf1..1c89f31d6d65 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc_asyncio.py b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc_asyncio.py index 9359e87d9816..c5998140b7b0 100644 --- a/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/services/big_query_write/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigquery-storage/noxfile.py b/packages/google-cloud-bigquery-storage/noxfile.py index 9fe11685649c..25726e0dd874 100644 --- a/packages/google-cloud-bigquery-storage/noxfile.py +++ b/packages/google-cloud-bigquery-storage/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -106,8 +104,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -118,6 +117,9 @@ def mypy(session): "mypy", "-p", "google", + # TODO(https://github.com/googleapis/google-cloud-python/issues/16083) + # "--check-untyped-defs", + *session.posargs, ) @@ -309,7 +311,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -567,7 +572,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -662,7 +667,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-bigquery-storage/setup.py b/packages/google-cloud-bigquery-storage/setup.py index e9e71b7615ec..e77f0a3777a7 100644 --- a/packages/google-cloud-bigquery-storage/setup.py +++ b/packages/google-cloud-bigquery-storage/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,13 +49,12 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = { - # 'importlib-metadata' is required for Python 3.7 compatibility - "pandas": ["pandas>=0.21.1", "importlib-metadata>=1.0.0; python_version<'3.8'"], - "fastavro": ["fastavro>=0.21.2"], - "pyarrow": ["pyarrow>=0.15.0"], + "pandas": ["pandas>=1.1.3"], + "fastavro": ["fastavro>=1.1.0"], + "pyarrow": ["pyarrow>=3.0.0"], } url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-bigquery-storage" @@ -86,8 +85,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -99,7 +96,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-bigquery-storage/testing/constraints-3.7.txt b/packages/google-cloud-bigquery-storage/testing/constraints-3.7.txt deleted file mode 100644 index e80388df25cd..000000000000 --- a/packages/google-cloud-bigquery-storage/testing/constraints-3.7.txt +++ /dev/null @@ -1,20 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -libcst==0.2.5 -fastavro==0.21.2 -# pytz is required by pandas -pytz -pandas==1.0.5 -pyarrow==0.15.0 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-bigquery-storage/testing/constraints-3.8.txt b/packages/google-cloud-bigquery-storage/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-bigquery-storage/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-bigquery-storage/testing/constraints-3.9.txt b/packages/google-cloud-bigquery-storage/testing/constraints-3.9.txt index 7599dea499ed..879478021048 100644 --- a/packages/google-cloud-bigquery-storage/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigquery-storage/testing/constraints-3.9.txt @@ -1,10 +1,21 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +libcst==0.2.5 +fastavro==1.1.0 +# pytz is required by pandas +pytz +pandas==1.1.3 +# numpy is a dependency of pandas +numpy==1.19.3 +pyarrow==3.0.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py index de939eb1d03d..a4511b45c00f 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BigQueryReadClient._get_default_mtls_endpoint(None) is None assert ( @@ -134,6 +135,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BigQueryReadClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + BigQueryReadClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1237,11 +1242,13 @@ def test_big_query_read_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2550,11 +2557,14 @@ def test_big_query_read_base_transport(): def test_big_query_read_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_storage_v1.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_storage_v1.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport( @@ -2574,9 +2584,12 @@ def test_big_query_read_base_transport_with_credentials_file(): def test_big_query_read_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_storage_v1.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_storage_v1.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport() @@ -2653,11 +2666,12 @@ def test_big_query_read_transport_auth_gdch_credentials(transport_class): def test_big_query_read_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py index 4a3ce5330203..af42320ad700 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BigQueryWriteClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): assert ( BigQueryWriteClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BigQueryWriteClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1265,11 +1270,13 @@ def test_big_query_write_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3568,11 +3575,14 @@ def test_big_query_write_base_transport(): def test_big_query_write_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_storage_v1.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_storage_v1.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport( @@ -3593,9 +3603,12 @@ def test_big_query_write_base_transport_with_credentials_file(): def test_big_query_write_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_storage_v1.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_storage_v1.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport() @@ -3674,11 +3687,12 @@ def test_big_query_write_transport_auth_gdch_credentials(transport_class): def test_big_query_write_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1alpha/test_metastore_partition_service.py b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1alpha/test_metastore_partition_service.py index 71b6eaa98cfe..984e9fa57f2e 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1alpha/test_metastore_partition_service.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1alpha/test_metastore_partition_service.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetastorePartitionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): MetastorePartitionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetastorePartitionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1317,11 +1322,13 @@ def test_metastore_partition_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2987,11 +2994,14 @@ def test_metastore_partition_service_base_transport(): def test_metastore_partition_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_storage_v1alpha.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_storage_v1alpha.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastorePartitionServiceTransport( @@ -3011,9 +3021,12 @@ def test_metastore_partition_service_base_transport_with_credentials_file(): def test_metastore_partition_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_storage_v1alpha.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_storage_v1alpha.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastorePartitionServiceTransport() @@ -3092,11 +3105,12 @@ def test_metastore_partition_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta/test_metastore_partition_service.py b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta/test_metastore_partition_service.py index 75f9f1aa7a2a..52295745cc98 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta/test_metastore_partition_service.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta/test_metastore_partition_service.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetastorePartitionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): MetastorePartitionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetastorePartitionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1317,11 +1322,13 @@ def test_metastore_partition_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2987,11 +2994,14 @@ def test_metastore_partition_service_base_transport(): def test_metastore_partition_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_storage_v1beta.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_storage_v1beta.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastorePartitionServiceTransport( @@ -3011,9 +3021,12 @@ def test_metastore_partition_service_base_transport_with_credentials_file(): def test_metastore_partition_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_storage_v1beta.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_storage_v1beta.services.metastore_partition_service.transports.MetastorePartitionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetastorePartitionServiceTransport() @@ -3092,11 +3105,12 @@ def test_metastore_partition_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py index 030d37ec2e3d..11df49524929 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BigQueryReadClient._get_default_mtls_endpoint(None) is None assert ( @@ -134,6 +135,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BigQueryReadClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + BigQueryReadClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1237,11 +1242,13 @@ def test_big_query_read_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2530,11 +2537,14 @@ def test_big_query_read_base_transport(): def test_big_query_read_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_storage_v1beta2.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_storage_v1beta2.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport( @@ -2554,9 +2564,12 @@ def test_big_query_read_base_transport_with_credentials_file(): def test_big_query_read_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_storage_v1beta2.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_storage_v1beta2.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport() @@ -2633,11 +2646,12 @@ def test_big_query_read_transport_auth_gdch_credentials(transport_class): def test_big_query_read_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py index 4943d87ba2a8..f937a7b01f4c 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BigQueryWriteClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( BigQueryWriteClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BigQueryWriteClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1259,11 +1264,13 @@ def test_big_query_write_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3542,11 +3549,14 @@ def test_big_query_write_base_transport(): def test_big_query_write_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.bigquery_storage_v1beta2.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.bigquery_storage_v1beta2.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport( @@ -3567,9 +3577,12 @@ def test_big_query_write_base_transport_with_credentials_file(): def test_big_query_write_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.bigquery_storage_v1beta2.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.bigquery_storage_v1beta2.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport() @@ -3648,11 +3661,12 @@ def test_big_query_write_transport_auth_gdch_credentials(transport_class): def test_big_query_write_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1.py b/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1.py index 81aa2bf6e426..d27c5b14123a 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1.py @@ -336,9 +336,13 @@ def test_initial_send_with_timeout(self, background_consumer, bidi_rpc): ) now = time.monotonic() later = now + writer._DEFAULT_TIMEOUT + 1 - with mock.patch.object(writer.time, "sleep"), mock.patch.object( - writer.time, "monotonic", mock.MagicMock(side_effect=(now, later)) - ), pytest.raises(exceptions.Unknown): + with ( + mock.patch.object(writer.time, "sleep"), + mock.patch.object( + writer.time, "monotonic", mock.MagicMock(side_effect=(now, later)) + ), + pytest.raises(exceptions.Unknown), + ): connection.send(initial_request) @mock.patch("google.api_core.bidi.BidiRpc", autospec=True) diff --git a/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1beta2.py b/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1beta2.py index d567a329bb8a..5bde4065aa05 100644 --- a/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1beta2.py +++ b/packages/google-cloud-bigquery-storage/tests/unit/test_writer_v1beta2.py @@ -130,9 +130,15 @@ def test_initial_send_with_timeout(background_consumer, bidi_rpc, module_under_t now = time.monotonic() later = now + module_under_test._DEFAULT_TIMEOUT + 1 - with mock.patch.object(module_under_test.time, "sleep"), mock.patch.object( - module_under_test.time, "monotonic", mock.MagicMock(side_effect=(now, later)) - ), pytest.raises(exceptions.Unknown): + with ( + mock.patch.object(module_under_test.time, "sleep"), + mock.patch.object( + module_under_test.time, + "monotonic", + mock.MagicMock(side_effect=(now, later)), + ), + pytest.raises(exceptions.Unknown), + ): manager.send(initial_request) diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/async_client.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/async_client.py index b533323b5f03..2478e0f9e345 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/async_client.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> BudgetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/client.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/client.py index 72a85f673da6..6a447ecca4ec 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/client.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/client.py @@ -114,7 +114,7 @@ class BudgetServiceClient(metaclass=BudgetServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -436,7 +440,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -533,7 +537,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -629,7 +633,7 @@ def __init__( self._universe_domain = BudgetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/README.rst b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/README.rst index 2dbfa440f9fa..f74535bc8b6b 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/README.rst +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BudgetServiceTransport` is the ABC for all transports. -- public child `BudgetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BudgetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBudgetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BudgetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BudgetServiceTransport`` is the ABC for all transports. + +- public child ``BudgetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BudgetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBudgetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BudgetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py index 09e5b803c4dc..c21038652c06 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc.py index a8f65cd97791..38932fbfd7ad 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py index 0a06d1359006..befd86f22e43 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/rest.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/rest.py index 84a91baf7754..15e388cf8b98 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/rest.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/services/budget_service/transports/rest.py @@ -386,6 +386,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BudgetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py index d8ef7f91a34d..194c731dbe73 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> BudgetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py index 88bc1348bc1c..0f2b053f4455 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/client.py @@ -110,7 +110,7 @@ class BudgetServiceClient(metaclass=BudgetServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -432,7 +436,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -529,7 +533,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = BudgetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/README.rst b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/README.rst index 2dbfa440f9fa..f74535bc8b6b 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/README.rst +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BudgetServiceTransport` is the ABC for all transports. -- public child `BudgetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BudgetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBudgetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BudgetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BudgetServiceTransport`` is the ABC for all transports. + +- public child ``BudgetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BudgetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBudgetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BudgetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py index b0f473baf4c9..3d45744d50c6 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc.py index 952f7505aaa9..eb0296f252fe 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py index ff64eae54490..f2b076a1b6e7 100644 --- a/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing-budgets/noxfile.py b/packages/google-cloud-billing-budgets/noxfile.py index d8606ff50715..5fb67122b569 100644 --- a/packages/google-cloud-billing-budgets/noxfile.py +++ b/packages/google-cloud-billing-budgets/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-billing-budgets/setup.py b/packages/google-cloud-billing-budgets/setup.py index 29ac90dc8246..ee8d022fbca9 100644 --- a/packages/google-cloud-billing-budgets/setup.py +++ b/packages/google-cloud-billing-budgets/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-billing-budgets" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-billing-budgets/testing/constraints-3.7.txt b/packages/google-cloud-billing-budgets/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-billing-budgets/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-billing-budgets/testing/constraints-3.8.txt b/packages/google-cloud-billing-budgets/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-billing-budgets/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-billing-budgets/testing/constraints-3.9.txt b/packages/google-cloud-billing-budgets/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-billing-budgets/testing/constraints-3.9.txt +++ b/packages/google-cloud-billing-budgets/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1/test_budget_service.py b/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1/test_budget_service.py index 3a2c68094e05..86ab7796e598 100644 --- a/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1/test_budget_service.py +++ b/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1/test_budget_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BudgetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): assert ( BudgetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BudgetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1280,11 +1285,13 @@ def test_budget_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4481,8 +4488,9 @@ def test_create_budget_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4657,17 +4665,19 @@ def test_create_budget_rest_interceptors(null_interceptor): ) client = BudgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_create_budget" - ) as post, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_create_budget_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BudgetServiceRestInterceptor, "pre_create_budget" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_create_budget" + ) as post, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_create_budget_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "pre_create_budget" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4720,8 +4730,9 @@ def test_update_budget_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4896,17 +4907,19 @@ def test_update_budget_rest_interceptors(null_interceptor): ) client = BudgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_update_budget" - ) as post, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_update_budget_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BudgetServiceRestInterceptor, "pre_update_budget" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_update_budget" + ) as post, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_update_budget_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "pre_update_budget" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4957,8 +4970,9 @@ def test_get_budget_rest_bad_request(request_type=budget_service.GetBudgetReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5025,17 +5039,19 @@ def test_get_budget_rest_interceptors(null_interceptor): ) client = BudgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_get_budget" - ) as post, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_get_budget_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BudgetServiceRestInterceptor, "pre_get_budget" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_get_budget" + ) as post, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_get_budget_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "pre_get_budget" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5086,8 +5102,9 @@ def test_list_budgets_rest_bad_request(request_type=budget_service.ListBudgetsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5150,17 +5167,19 @@ def test_list_budgets_rest_interceptors(null_interceptor): ) client = BudgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_list_budgets" - ) as post, mock.patch.object( - transports.BudgetServiceRestInterceptor, "post_list_budgets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BudgetServiceRestInterceptor, "pre_list_budgets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_list_budgets" + ) as post, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "post_list_budgets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "pre_list_budgets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5215,8 +5234,9 @@ def test_delete_budget_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5273,13 +5293,13 @@ def test_delete_budget_rest_interceptors(null_interceptor): ) client = BudgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BudgetServiceRestInterceptor, "pre_delete_budget" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BudgetServiceRestInterceptor, "pre_delete_budget" + ) as pre, + ): pre.assert_not_called() pb_message = budget_service.DeleteBudgetRequest.pb( budget_service.DeleteBudgetRequest() @@ -5477,11 +5497,14 @@ def test_budget_service_base_transport(): def test_budget_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.billing.budgets_v1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.billing.budgets_v1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BudgetServiceTransport( @@ -5501,9 +5524,12 @@ def test_budget_service_base_transport_with_credentials_file(): def test_budget_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.billing.budgets_v1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.billing.budgets_v1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BudgetServiceTransport() @@ -5581,11 +5607,12 @@ def test_budget_service_transport_auth_gdch_credentials(transport_class): def test_budget_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1beta1/test_budget_service.py b/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1beta1/test_budget_service.py index 5498fb98b412..bbb55765f088 100644 --- a/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1beta1/test_budget_service.py +++ b/packages/google-cloud-billing-budgets/tests/unit/gapic/budgets_v1beta1/test_budget_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BudgetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( BudgetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BudgetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1260,11 +1265,13 @@ def test_budget_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3112,11 +3119,14 @@ def test_budget_service_base_transport(): def test_budget_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.billing.budgets_v1beta1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.billing.budgets_v1beta1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BudgetServiceTransport( @@ -3136,9 +3146,12 @@ def test_budget_service_base_transport_with_credentials_file(): def test_budget_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.billing.budgets_v1beta1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.billing.budgets_v1beta1.services.budget_service.transports.BudgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BudgetServiceTransport() @@ -3215,11 +3228,12 @@ def test_budget_service_transport_auth_gdch_credentials(transport_class): def test_budget_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/async_client.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/async_client.py index e678e31d2745..83c62d03c7d9 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/async_client.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> CloudBillingTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/client.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/client.py index 7cbbf8508ac9..422ea5cf51a0 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/client.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/client.py @@ -114,7 +114,7 @@ class CloudBillingClient(metaclass=CloudBillingClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -477,7 +481,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -574,7 +578,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -670,7 +674,7 @@ def __init__( self._universe_domain = CloudBillingClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/README.rst b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/README.rst index 30b6301b9314..30c6f8d7935a 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/README.rst +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudBillingTransport` is the ABC for all transports. -- public child `CloudBillingGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudBillingGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudBillingRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudBillingRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudBillingTransport`` is the ABC for all transports. + +- public child ``CloudBillingGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudBillingGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudBillingRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudBillingRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py index cee1f5fd7beb..ac65876a6dba 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc.py index 4a92b6b360a0..cf68cc1c4526 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc_asyncio.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc_asyncio.py index f8b16c3a9938..2a070afbfd4e 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc_asyncio.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/rest.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/rest.py index f9a5c3e5ce53..a03d0a749987 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/rest.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/rest.py @@ -780,6 +780,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudBillingRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/async_client.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/async_client.py index 90df4f9cda80..f58838c3ca7c 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/async_client.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> CloudCatalogTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/client.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/client.py index aefea94ba17c..e0800989f0d7 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/client.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/client.py @@ -112,7 +112,7 @@ class CloudCatalogClient(metaclass=CloudCatalogClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -447,7 +451,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -544,7 +548,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -640,7 +644,7 @@ def __init__( self._universe_domain = CloudCatalogClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/README.rst b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/README.rst index bde5716ecfde..acb67cb23160 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/README.rst +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudCatalogTransport` is the ABC for all transports. -- public child `CloudCatalogGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudCatalogGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudCatalogRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudCatalogRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudCatalogTransport`` is the ABC for all transports. + +- public child ``CloudCatalogGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudCatalogGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudCatalogRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudCatalogRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py index 3595cafa2fc6..6550f980b273 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc.py index c6b33088b49a..e69f21e7e790 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc_asyncio.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc_asyncio.py index b7e8ba1a6a0d..07b10dde4bab 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc_asyncio.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/rest.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/rest.py index 957a55f92f38..87059eef2558 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/rest.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/rest.py @@ -259,6 +259,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudCatalogRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-billing/noxfile.py b/packages/google-cloud-billing/noxfile.py index 2985a2cd8100..131ce6622101 100644 --- a/packages/google-cloud-billing/noxfile.py +++ b/packages/google-cloud-billing/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-billing/setup.py b/packages/google-cloud-billing/setup.py index c60743c3e3cc..cd195183e60e 100644 --- a/packages/google-cloud-billing/setup.py +++ b/packages/google-cloud-billing/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-billing/testing/constraints-3.7.txt b/packages/google-cloud-billing/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-billing/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-billing/testing/constraints-3.8.txt b/packages/google-cloud-billing/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-billing/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-billing/testing/constraints-3.9.txt b/packages/google-cloud-billing/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-billing/testing/constraints-3.9.txt +++ b/packages/google-cloud-billing/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py index f8a566efd4f2..7bda84e13def 100644 --- a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py +++ b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudBillingClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CloudBillingClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CloudBillingClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1262,11 +1267,13 @@ def test_cloud_billing_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8170,8 +8177,9 @@ def test_get_billing_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8244,17 +8252,20 @@ def test_get_billing_account_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_get_billing_account" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_get_billing_account_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_get_billing_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_get_billing_account" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_get_billing_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_get_billing_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8309,8 +8320,9 @@ def test_list_billing_accounts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8373,18 +8385,20 @@ def test_list_billing_accounts_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_list_billing_accounts" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_list_billing_accounts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_list_billing_accounts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_list_billing_accounts" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_list_billing_accounts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_list_billing_accounts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8442,8 +8456,9 @@ def test_update_billing_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8591,18 +8606,20 @@ def test_update_billing_account_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_update_billing_account" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_update_billing_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_update_billing_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_update_billing_account" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_update_billing_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_update_billing_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8657,8 +8674,9 @@ def test_create_billing_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8808,18 +8826,20 @@ def test_create_billing_account_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_create_billing_account" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_create_billing_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_create_billing_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_create_billing_account" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_create_billing_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_create_billing_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8874,8 +8894,9 @@ def test_list_project_billing_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8938,18 +8959,20 @@ def test_list_project_billing_info_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_list_project_billing_info" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_list_project_billing_info_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_list_project_billing_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_list_project_billing_info" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_list_project_billing_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_list_project_billing_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9007,8 +9030,9 @@ def test_get_project_billing_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9077,18 +9101,20 @@ def test_get_project_billing_info_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_get_project_billing_info" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_get_project_billing_info_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_get_project_billing_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_get_project_billing_info" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_get_project_billing_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_get_project_billing_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9143,8 +9169,9 @@ def test_update_project_billing_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9290,18 +9317,20 @@ def test_update_project_billing_info_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_update_project_billing_info" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_update_project_billing_info_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_update_project_billing_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_update_project_billing_info" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_update_project_billing_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_update_project_billing_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9356,8 +9385,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9419,17 +9449,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9480,8 +9512,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9543,17 +9576,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9604,8 +9639,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9665,18 +9701,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9732,8 +9770,9 @@ def test_move_billing_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9806,18 +9845,20 @@ def test_move_billing_account_rest_interceptors(null_interceptor): ) client = CloudBillingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBillingRestInterceptor, "post_move_billing_account" - ) as post, mock.patch.object( - transports.CloudBillingRestInterceptor, - "post_move_billing_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBillingRestInterceptor, "pre_move_billing_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBillingRestInterceptor, "post_move_billing_account" + ) as post, + mock.patch.object( + transports.CloudBillingRestInterceptor, + "post_move_billing_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBillingRestInterceptor, "pre_move_billing_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10169,11 +10210,14 @@ def test_cloud_billing_base_transport(): def test_cloud_billing_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.billing_v1.services.cloud_billing.transports.CloudBillingTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.billing_v1.services.cloud_billing.transports.CloudBillingTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudBillingTransport( @@ -10194,9 +10238,12 @@ def test_cloud_billing_base_transport_with_credentials_file(): def test_cloud_billing_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.billing_v1.services.cloud_billing.transports.CloudBillingTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.billing_v1.services.cloud_billing.transports.CloudBillingTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudBillingTransport() @@ -10276,11 +10323,12 @@ def test_cloud_billing_transport_auth_gdch_credentials(transport_class): def test_cloud_billing_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py index f4b1db023407..f3c30dfbf2f6 100644 --- a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py +++ b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudCatalogClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CloudCatalogClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CloudCatalogClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1258,11 +1263,13 @@ def test_cloud_catalog_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2765,8 +2772,9 @@ def test_list_services_rest_bad_request(request_type=cloud_catalog.ListServicesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2829,17 +2837,19 @@ def test_list_services_rest_interceptors(null_interceptor): ) client = CloudCatalogClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudCatalogRestInterceptor, "post_list_services" - ) as post, mock.patch.object( - transports.CloudCatalogRestInterceptor, "post_list_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudCatalogRestInterceptor, "pre_list_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudCatalogRestInterceptor, "post_list_services" + ) as post, + mock.patch.object( + transports.CloudCatalogRestInterceptor, "post_list_services_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudCatalogRestInterceptor, "pre_list_services" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2892,8 +2902,9 @@ def test_list_skus_rest_bad_request(request_type=cloud_catalog.ListSkusRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2956,17 +2967,19 @@ def test_list_skus_rest_interceptors(null_interceptor): ) client = CloudCatalogClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudCatalogRestInterceptor, "post_list_skus" - ) as post, mock.patch.object( - transports.CloudCatalogRestInterceptor, "post_list_skus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudCatalogRestInterceptor, "pre_list_skus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudCatalogRestInterceptor, "post_list_skus" + ) as post, + mock.patch.object( + transports.CloudCatalogRestInterceptor, "post_list_skus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudCatalogRestInterceptor, "pre_list_skus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3109,11 +3122,14 @@ def test_cloud_catalog_base_transport(): def test_cloud_catalog_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.billing_v1.services.cloud_catalog.transports.CloudCatalogTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.billing_v1.services.cloud_catalog.transports.CloudCatalogTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudCatalogTransport( @@ -3134,9 +3150,12 @@ def test_cloud_catalog_base_transport_with_credentials_file(): def test_cloud_catalog_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.billing_v1.services.cloud_catalog.transports.CloudCatalogTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.billing_v1.services.cloud_catalog.transports.CloudCatalogTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudCatalogTransport() @@ -3216,11 +3235,12 @@ def test_cloud_catalog_transport_auth_gdch_credentials(transport_class): def test_cloud_catalog_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py index 4c6edeac2c9d..23741b5181ad 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> BinauthzManagementServiceV1Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py index 0c6edc115f01..d3d449b66110 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/client.py @@ -124,7 +124,7 @@ class BinauthzManagementServiceV1Client( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = BinauthzManagementServiceV1Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/README.rst b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/README.rst index 9260e2de1f39..4d1d53b24929 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/README.rst +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BinauthzManagementServiceV1Transport` is the ABC for all transports. -- public child `BinauthzManagementServiceV1GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BinauthzManagementServiceV1GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBinauthzManagementServiceV1RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BinauthzManagementServiceV1RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BinauthzManagementServiceV1Transport`` is the ABC for all transports. + +- public child ``BinauthzManagementServiceV1GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BinauthzManagementServiceV1GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBinauthzManagementServiceV1RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BinauthzManagementServiceV1RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py index 58bf8681b5ec..85d6acac7063 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py index 86049138b3a9..b1f78ad97165 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py index 1010dc7fabb0..3f552d3b9a8b 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/rest.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/rest.py index 0f04052872f2..26511bd50344 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/rest.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/binauthz_management_service_v1/transports/rest.py @@ -484,6 +484,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BinauthzManagementServiceV1RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py index d7287b9e285f..e3af6cf54130 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> SystemPolicyV1Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py index 0a767cf014b7..88b349bcddd0 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/client.py @@ -110,7 +110,7 @@ class SystemPolicyV1Client(metaclass=SystemPolicyV1ClientMeta): """API for working with the system policy.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -428,7 +432,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -525,7 +529,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -621,7 +625,7 @@ def __init__( self._universe_domain = SystemPolicyV1Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/README.rst b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/README.rst index fca1151bbad2..1047d9f5766f 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/README.rst +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SystemPolicyV1Transport` is the ABC for all transports. -- public child `SystemPolicyV1GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SystemPolicyV1GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSystemPolicyV1RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SystemPolicyV1RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SystemPolicyV1Transport`` is the ABC for all transports. + +- public child ``SystemPolicyV1GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SystemPolicyV1GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSystemPolicyV1RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SystemPolicyV1RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py index b40769c21e80..649eff534c30 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py index 56c27fc99c6f..080f7989f998 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py index b10cd0d4b33e..4acd107f97bd 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/rest.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/rest.py index f375a0731720..00ab0c937c0d 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/rest.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/system_policy_v1/transports/rest.py @@ -197,6 +197,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SystemPolicyV1RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py index 856bf7df339f..8291a02b8b3c 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> ValidationHelperV1Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py index 94553af63fb0..735573e67441 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/client.py @@ -108,7 +108,7 @@ class ValidationHelperV1Client(metaclass=ValidationHelperV1ClientMeta): """BinAuthz Attestor verification""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = ValidationHelperV1Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/README.rst b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/README.rst index a281c52d87e1..3816bc0e807a 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/README.rst +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ValidationHelperV1Transport` is the ABC for all transports. -- public child `ValidationHelperV1GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ValidationHelperV1GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseValidationHelperV1RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ValidationHelperV1RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ValidationHelperV1Transport`` is the ABC for all transports. + +- public child ``ValidationHelperV1GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ValidationHelperV1GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseValidationHelperV1RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ValidationHelperV1RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py index 71e27d846590..46531d95f6eb 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py index 23dcbc0bcf0b..33665c5271ae 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py index f21b0528c661..bb4a304806a7 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/rest.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/rest.py index 5986468d07bb..b4ac85734314 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/rest.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1/services/validation_helper_v1/transports/rest.py @@ -205,6 +205,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ValidationHelperV1RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py index 22c34c08c03f..3d812dcb51b1 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> BinauthzManagementServiceV1Beta1Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py index 95dc2bc45c5e..d3e53ad854e9 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/client.py @@ -129,7 +129,7 @@ class BinauthzManagementServiceV1Beta1Client( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -137,7 +137,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -147,6 +147,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/README.rst b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/README.rst index d7f2c8c68e58..4651a8de3278 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/README.rst +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BinauthzManagementServiceV1Beta1Transport` is the ABC for all transports. -- public child `BinauthzManagementServiceV1Beta1GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBinauthzManagementServiceV1Beta1RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BinauthzManagementServiceV1Beta1RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BinauthzManagementServiceV1Beta1Transport`` is the ABC for all transports. + +- public child ``BinauthzManagementServiceV1Beta1GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BinauthzManagementServiceV1Beta1GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBinauthzManagementServiceV1Beta1RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BinauthzManagementServiceV1Beta1RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py index f058d1792303..933d425bf934 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py index 8a48a392c6ff..99ed3505857b 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py index 62a0d5efc4eb..47707414dc10 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/rest.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/rest.py index 54a1618e31f1..b23cd60f49f7 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/rest.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/binauthz_management_service_v1_beta1/transports/rest.py @@ -484,6 +484,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BinauthzManagementServiceV1Beta1RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/async_client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/async_client.py index 9f5073fd4d2a..c3fc7a3ca417 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/async_client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> SystemPolicyV1Beta1Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/client.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/client.py index b4c45e422f64..5c956067dcc2 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/client.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/client.py @@ -110,7 +110,7 @@ class SystemPolicyV1Beta1Client(metaclass=SystemPolicyV1Beta1ClientMeta): """API for working with the system policy.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -428,7 +432,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -525,7 +529,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = SystemPolicyV1Beta1Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/README.rst b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/README.rst index 168f0eec1fcf..302f6eec79cf 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/README.rst +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SystemPolicyV1Beta1Transport` is the ABC for all transports. -- public child `SystemPolicyV1Beta1GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SystemPolicyV1Beta1GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSystemPolicyV1Beta1RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SystemPolicyV1Beta1RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SystemPolicyV1Beta1Transport`` is the ABC for all transports. + +- public child ``SystemPolicyV1Beta1GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SystemPolicyV1Beta1GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSystemPolicyV1Beta1RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SystemPolicyV1Beta1RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/base.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/base.py index 509a8873e867..ebedacf7bc46 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/base.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc.py index da001513718a..ab9ebcac4248 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc_asyncio.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc_asyncio.py index c00a0d498582..1994635ed7b2 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc_asyncio.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/rest.py b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/rest.py index ff8aa417af7b..05d2f17bb2a2 100644 --- a/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/rest.py +++ b/packages/google-cloud-binary-authorization/google/cloud/binaryauthorization_v1beta1/services/system_policy_v1_beta1/transports/rest.py @@ -197,6 +197,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SystemPolicyV1Beta1RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-binary-authorization/noxfile.py b/packages/google-cloud-binary-authorization/noxfile.py index 18e4cefe711d..556f1f24bf0d 100644 --- a/packages/google-cloud-binary-authorization/noxfile.py +++ b/packages/google-cloud-binary-authorization/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-binary-authorization/setup.py b/packages/google-cloud-binary-authorization/setup.py index 1ccf49410c5f..32994a24e370 100644 --- a/packages/google-cloud-binary-authorization/setup.py +++ b/packages/google-cloud-binary-authorization/setup.py @@ -41,16 +41,16 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "grafeas >= 1.1.2, <2.0", + "grafeas >= 1.7.0, <2.0", "grpcio >= 1.33.2, < 2.0.0", "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-binary-authorization" @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-binary-authorization/testing/constraints-3.7.txt b/packages/google-cloud-binary-authorization/testing/constraints-3.7.txt deleted file mode 100644 index 156e3a78037c..000000000000 --- a/packages/google-cloud-binary-authorization/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -grafeas==1.1.2 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-binary-authorization/testing/constraints-3.8.txt b/packages/google-cloud-binary-authorization/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-binary-authorization/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-binary-authorization/testing/constraints-3.9.txt b/packages/google-cloud-binary-authorization/testing/constraints-3.9.txt index 7599dea499ed..15a3255c03d4 100644 --- a/packages/google-cloud-binary-authorization/testing/constraints-3.9.txt +++ b/packages/google-cloud-binary-authorization/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +grafeas==1.7.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py index ccc6fb1efb94..4351588bdee3 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py +++ b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_binauthz_management_service_v1.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BinauthzManagementServiceV1Client._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): BinauthzManagementServiceV1Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BinauthzManagementServiceV1Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1384,11 +1389,13 @@ def test_binauthz_management_service_v1_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5679,8 +5686,9 @@ def test_get_policy_rest_bad_request(request_type=service.GetPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5750,18 +5758,20 @@ def test_get_policy_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "post_get_policy" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, - "post_get_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_get_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "post_get_policy" + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_get_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_get_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5810,8 +5820,9 @@ def test_update_policy_rest_bad_request(request_type=service.UpdatePolicyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5967,18 +5978,20 @@ def test_update_policy_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "post_update_policy" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, - "post_update_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_update_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "post_update_policy" + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_update_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_update_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6027,8 +6040,9 @@ def test_create_attestor_rest_bad_request(request_type=service.CreateAttestorReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6180,18 +6194,21 @@ def test_create_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "post_create_attestor" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, - "post_create_attestor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_create_attestor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_create_attestor", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_create_attestor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_create_attestor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6240,8 +6257,9 @@ def test_get_attestor_rest_bad_request(request_type=service.GetAttestorRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6306,18 +6324,20 @@ def test_get_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "post_get_attestor" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, - "post_get_attestor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_get_attestor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "post_get_attestor" + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_get_attestor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_get_attestor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6366,8 +6386,9 @@ def test_update_attestor_rest_bad_request(request_type=service.UpdateAttestorReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6519,18 +6540,21 @@ def test_update_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "post_update_attestor" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, - "post_update_attestor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_update_attestor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_update_attestor", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_update_attestor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_update_attestor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6579,8 +6603,9 @@ def test_list_attestors_rest_bad_request(request_type=service.ListAttestorsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6643,18 +6668,20 @@ def test_list_attestors_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "post_list_attestors" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, - "post_list_attestors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_list_attestors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "post_list_attestors" + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, + "post_list_attestors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_list_attestors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6705,8 +6732,9 @@ def test_delete_attestor_rest_bad_request(request_type=service.DeleteAttestorReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6763,13 +6791,13 @@ def test_delete_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1RestInterceptor, "pre_delete_attestor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1RestInterceptor, "pre_delete_attestor" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteAttestorRequest.pb(service.DeleteAttestorRequest()) transcode.return_value = { @@ -7007,11 +7035,14 @@ def test_binauthz_management_service_v1_base_transport(): def test_binauthz_management_service_v1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.binaryauthorization_v1.services.binauthz_management_service_v1.transports.BinauthzManagementServiceV1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.binaryauthorization_v1.services.binauthz_management_service_v1.transports.BinauthzManagementServiceV1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BinauthzManagementServiceV1Transport( @@ -7028,9 +7059,12 @@ def test_binauthz_management_service_v1_base_transport_with_credentials_file(): def test_binauthz_management_service_v1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.binaryauthorization_v1.services.binauthz_management_service_v1.transports.BinauthzManagementServiceV1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.binaryauthorization_v1.services.binauthz_management_service_v1.transports.BinauthzManagementServiceV1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BinauthzManagementServiceV1Transport() @@ -7109,11 +7143,12 @@ def test_binauthz_management_service_v1_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py index ba2db75501a3..00cae7db5134 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py +++ b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_system_policy_v1.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SystemPolicyV1Client._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( SystemPolicyV1Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SystemPolicyV1Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1284,11 +1289,13 @@ def test_system_policy_v1_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2029,8 +2036,9 @@ def test_get_system_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2100,17 +2108,20 @@ def test_get_system_policy_rest_interceptors(null_interceptor): ) client = SystemPolicyV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SystemPolicyV1RestInterceptor, "post_get_system_policy" - ) as post, mock.patch.object( - transports.SystemPolicyV1RestInterceptor, "post_get_system_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SystemPolicyV1RestInterceptor, "pre_get_system_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SystemPolicyV1RestInterceptor, "post_get_system_policy" + ) as post, + mock.patch.object( + transports.SystemPolicyV1RestInterceptor, + "post_get_system_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SystemPolicyV1RestInterceptor, "pre_get_system_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2230,11 +2241,14 @@ def test_system_policy_v1_base_transport(): def test_system_policy_v1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.binaryauthorization_v1.services.system_policy_v1.transports.SystemPolicyV1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.binaryauthorization_v1.services.system_policy_v1.transports.SystemPolicyV1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SystemPolicyV1Transport( @@ -2251,9 +2265,12 @@ def test_system_policy_v1_base_transport_with_credentials_file(): def test_system_policy_v1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.binaryauthorization_v1.services.system_policy_v1.transports.SystemPolicyV1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.binaryauthorization_v1.services.system_policy_v1.transports.SystemPolicyV1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SystemPolicyV1Transport() @@ -2325,11 +2342,12 @@ def test_system_policy_v1_transport_auth_gdch_credentials(transport_class): def test_system_policy_v1_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py index 15729d1275d7..664a6fb19b6a 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py +++ b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1/test_validation_helper_v1.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ValidationHelperV1Client._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): ValidationHelperV1Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ValidationHelperV1Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1321,11 +1326,13 @@ def test_validation_helper_v1_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1955,8 +1962,9 @@ def test_validate_attestation_occurrence_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2023,20 +2031,22 @@ def test_validate_attestation_occurrence_rest_interceptors(null_interceptor): ) client = ValidationHelperV1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ValidationHelperV1RestInterceptor, - "post_validate_attestation_occurrence", - ) as post, mock.patch.object( - transports.ValidationHelperV1RestInterceptor, - "post_validate_attestation_occurrence_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ValidationHelperV1RestInterceptor, - "pre_validate_attestation_occurrence", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ValidationHelperV1RestInterceptor, + "post_validate_attestation_occurrence", + ) as post, + mock.patch.object( + transports.ValidationHelperV1RestInterceptor, + "post_validate_attestation_occurrence_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ValidationHelperV1RestInterceptor, + "pre_validate_attestation_occurrence", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2163,11 +2173,14 @@ def test_validation_helper_v1_base_transport(): def test_validation_helper_v1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.binaryauthorization_v1.services.validation_helper_v1.transports.ValidationHelperV1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.binaryauthorization_v1.services.validation_helper_v1.transports.ValidationHelperV1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ValidationHelperV1Transport( @@ -2184,9 +2197,12 @@ def test_validation_helper_v1_base_transport_with_credentials_file(): def test_validation_helper_v1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.binaryauthorization_v1.services.validation_helper_v1.transports.ValidationHelperV1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.binaryauthorization_v1.services.validation_helper_v1.transports.ValidationHelperV1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ValidationHelperV1Transport() @@ -2258,11 +2274,12 @@ def test_validation_helper_v1_transport_auth_gdch_credentials(transport_class): def test_validation_helper_v1_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py index 35a39f316995..291f69ea1013 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py +++ b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_binauthz_management_service_v1_beta1.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( BinauthzManagementServiceV1Beta1Client._get_default_mtls_endpoint(None) is None @@ -150,6 +151,12 @@ def test__get_default_mtls_endpoint(): BinauthzManagementServiceV1Beta1Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BinauthzManagementServiceV1Beta1Client._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1419,11 +1426,13 @@ def test_binauthz_management_service_v1_beta1_client_create_channel_credentials_ ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5716,8 +5725,9 @@ def test_get_policy_rest_bad_request(request_type=service.GetPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5787,18 +5797,21 @@ def test_get_policy_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "post_get_policy" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_get_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "pre_get_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_get_policy", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_get_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, "pre_get_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5847,8 +5860,9 @@ def test_update_policy_rest_bad_request(request_type=service.UpdatePolicyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6004,18 +6018,22 @@ def test_update_policy_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "post_update_policy" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_update_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "pre_update_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_update_policy", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_update_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "pre_update_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6064,8 +6082,9 @@ def test_create_attestor_rest_bad_request(request_type=service.CreateAttestorReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6217,20 +6236,22 @@ def test_create_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_create_attestor", - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_create_attestor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "pre_create_attestor", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_create_attestor", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_create_attestor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "pre_create_attestor", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6279,8 +6300,9 @@ def test_get_attestor_rest_bad_request(request_type=service.GetAttestorRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6345,18 +6367,22 @@ def test_get_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "post_get_attestor" - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_get_attestor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "pre_get_attestor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_get_attestor", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_get_attestor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "pre_get_attestor", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6405,8 +6431,9 @@ def test_update_attestor_rest_bad_request(request_type=service.UpdateAttestorReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6558,20 +6585,22 @@ def test_update_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_update_attestor", - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_update_attestor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "pre_update_attestor", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_update_attestor", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_update_attestor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "pre_update_attestor", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6620,8 +6649,9 @@ def test_list_attestors_rest_bad_request(request_type=service.ListAttestorsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6684,19 +6714,22 @@ def test_list_attestors_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_list_attestors", - ) as post, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "post_list_attestors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, "pre_list_attestors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_list_attestors", + ) as post, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "post_list_attestors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "pre_list_attestors", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6747,8 +6780,9 @@ def test_delete_attestor_rest_bad_request(request_type=service.DeleteAttestorReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6805,14 +6839,14 @@ def test_delete_attestor_rest_interceptors(null_interceptor): ) client = BinauthzManagementServiceV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BinauthzManagementServiceV1Beta1RestInterceptor, - "pre_delete_attestor", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BinauthzManagementServiceV1Beta1RestInterceptor, + "pre_delete_attestor", + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteAttestorRequest.pb(service.DeleteAttestorRequest()) transcode.return_value = { @@ -7050,11 +7084,14 @@ def test_binauthz_management_service_v1_beta1_base_transport(): def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BinauthzManagementServiceV1Beta1Transport( @@ -7071,9 +7108,12 @@ def test_binauthz_management_service_v1_beta1_base_transport_with_credentials_fi def test_binauthz_management_service_v1_beta1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.binaryauthorization_v1beta1.services.binauthz_management_service_v1_beta1.transports.BinauthzManagementServiceV1Beta1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BinauthzManagementServiceV1Beta1Transport() @@ -7152,11 +7192,12 @@ def test_binauthz_management_service_v1_beta1_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_system_policy_v1_beta1.py b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_system_policy_v1_beta1.py index 684864ca6b4d..5e5592eb20e7 100644 --- a/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_system_policy_v1_beta1.py +++ b/packages/google-cloud-binary-authorization/tests/unit/gapic/binaryauthorization_v1beta1/test_system_policy_v1_beta1.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SystemPolicyV1Beta1Client._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): SystemPolicyV1Beta1Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SystemPolicyV1Beta1Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1340,11 +1345,13 @@ def test_system_policy_v1_beta1_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2085,8 +2092,9 @@ def test_get_system_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2156,18 +2164,20 @@ def test_get_system_policy_rest_interceptors(null_interceptor): ) client = SystemPolicyV1Beta1Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SystemPolicyV1Beta1RestInterceptor, "post_get_system_policy" - ) as post, mock.patch.object( - transports.SystemPolicyV1Beta1RestInterceptor, - "post_get_system_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SystemPolicyV1Beta1RestInterceptor, "pre_get_system_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SystemPolicyV1Beta1RestInterceptor, "post_get_system_policy" + ) as post, + mock.patch.object( + transports.SystemPolicyV1Beta1RestInterceptor, + "post_get_system_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SystemPolicyV1Beta1RestInterceptor, "pre_get_system_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2287,11 +2297,14 @@ def test_system_policy_v1_beta1_base_transport(): def test_system_policy_v1_beta1_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.binaryauthorization_v1beta1.services.system_policy_v1_beta1.transports.SystemPolicyV1Beta1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.binaryauthorization_v1beta1.services.system_policy_v1_beta1.transports.SystemPolicyV1Beta1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SystemPolicyV1Beta1Transport( @@ -2308,9 +2321,12 @@ def test_system_policy_v1_beta1_base_transport_with_credentials_file(): def test_system_policy_v1_beta1_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.binaryauthorization_v1beta1.services.system_policy_v1_beta1.transports.SystemPolicyV1Beta1Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.binaryauthorization_v1beta1.services.system_policy_v1_beta1.transports.SystemPolicyV1Beta1Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SystemPolicyV1Beta1Transport() @@ -2382,11 +2398,12 @@ def test_system_policy_v1_beta1_transport_auth_gdch_credentials(transport_class) def test_system_policy_v1_beta1_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py index 1a0d6ff0fe68..6a6f20c11144 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py @@ -234,7 +234,7 @@ def transport(self) -> CloudBuildTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py index e63bf42f31ff..7c2f5ef9bba3 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py @@ -124,7 +124,7 @@ class CloudBuildClient(metaclass=CloudBuildClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -715,7 +719,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -812,7 +816,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -908,7 +912,7 @@ def __init__( self._universe_domain = CloudBuildClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/README.rst b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/README.rst index 93e8e02f44fd..d655f69c2868 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/README.rst +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudBuildTransport` is the ABC for all transports. -- public child `CloudBuildGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudBuildGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudBuildRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudBuildRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudBuildTransport`` is the ABC for all transports. + +- public child ``CloudBuildGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudBuildGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudBuildRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudBuildRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py index 6ebd11b952be..a9f1d52767d8 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py index 648778a654cb..68905dc1f2b4 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py index 58fe81736430..9824350cc0ef 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/rest.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/rest.py index a1ca48576788..e5c596c8d3c5 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/rest.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v1/services/cloud_build/transports/rest.py @@ -1174,6 +1174,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudBuildRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/async_client.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/async_client.py index 6ab90aaf5fca..85d04fa90ef3 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/async_client.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> RepositoryManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2085,7 +2085,7 @@ async def sample_fetch_git_refs(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2111,8 +2111,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2121,7 +2125,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2129,7 +2133,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2140,7 +2144,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2169,8 +2173,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2179,7 +2187,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2187,7 +2195,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2195,7 +2203,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2287,8 +2295,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2297,7 +2309,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2305,7 +2319,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2316,7 +2330,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2409,8 +2423,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2419,7 +2437,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2427,7 +2447,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2438,7 +2458,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2469,8 +2489,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2481,7 +2505,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2489,7 +2515,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/client.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/client.py index 538d48914f68..d94231fe100c 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/client.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/client.py @@ -121,7 +121,7 @@ class RepositoryManagerClient(metaclass=RepositoryManagerClientMeta): """Manages connections to source code repositories.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -518,7 +522,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -615,7 +619,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -715,7 +719,7 @@ def __init__( self._universe_domain = RepositoryManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2556,7 +2560,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2582,8 +2586,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2592,7 +2600,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2601,7 +2609,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2615,7 +2623,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2644,8 +2652,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2654,7 +2666,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2662,7 +2674,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2670,7 +2682,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2762,8 +2774,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2772,7 +2788,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2781,7 +2799,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2795,7 +2813,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2888,8 +2906,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2898,7 +2920,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2907,7 +2931,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2921,7 +2945,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2952,8 +2976,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2962,7 +2990,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2971,7 +3001,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/README.rst b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/README.rst index 01e7c906831c..883603e2a5e8 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/README.rst +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RepositoryManagerTransport` is the ABC for all transports. -- public child `RepositoryManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RepositoryManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRepositoryManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RepositoryManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RepositoryManagerTransport`` is the ABC for all transports. + +- public child ``RepositoryManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RepositoryManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRepositoryManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RepositoryManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/base.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/base.py index 4114f7afbadc..eba59d2ad3fa 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/base.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc.py index baf585f843f8..b98aaf5d7868 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc_asyncio.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc_asyncio.py index b3ad07d22445..0e5c27498539 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/rest.py b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/rest.py index 2e076e1638d4..8cfb6864cd84 100644 --- a/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/rest.py +++ b/packages/google-cloud-build/google/cloud/devtools/cloudbuild_v2/services/repository_manager/transports/rest.py @@ -1071,6 +1071,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RepositoryManagerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-build/noxfile.py b/packages/google-cloud-build/noxfile.py index 8c1f85a7130c..9ee23fa6da7a 100644 --- a/packages/google-cloud-build/noxfile.py +++ b/packages/google-cloud-build/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-build/setup.py b/packages/google-cloud-build/setup.py index c01c9204286a..ec24cc46691c 100644 --- a/packages/google-cloud-build/setup.py +++ b/packages/google-cloud-build/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -50,7 +50,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-build" @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-build/testing/constraints-3.7.txt b/packages/google-cloud-build/testing/constraints-3.7.txt deleted file mode 100644 index 2bcfa952021b..000000000000 --- a/packages/google-cloud-build/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -grpc-google-iam-v1==0.12.4 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-build/testing/constraints-3.8.txt b/packages/google-cloud-build/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-build/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-build/testing/constraints-3.9.txt b/packages/google-cloud-build/testing/constraints-3.9.txt index 7599dea499ed..36c91811afe8 100644 --- a/packages/google-cloud-build/testing/constraints-3.9.txt +++ b/packages/google-cloud-build/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +grpc-google-iam-v1==0.12.4 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py b/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py index 535276fb42dd..ccb5f6921270 100644 --- a/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py +++ b/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudBuildClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CloudBuildClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CloudBuildClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1250,11 +1254,13 @@ def test_cloud_build_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -13574,8 +13580,9 @@ def test_create_build_rest_bad_request(request_type=cloudbuild.CreateBuildReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13932,19 +13939,20 @@ def test_create_build_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_create_build" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_create_build_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_create_build" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_create_build" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_create_build_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_create_build" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13993,8 +14001,9 @@ def test_get_build_rest_bad_request(request_type=cloudbuild.GetBuildRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14077,17 +14086,17 @@ def test_get_build_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_build" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_build_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_get_build" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_build" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_build_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.CloudBuildRestInterceptor, "pre_get_build") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14136,8 +14145,9 @@ def test_list_builds_rest_bad_request(request_type=cloudbuild.ListBuildsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14200,17 +14210,19 @@ def test_list_builds_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_list_builds" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_list_builds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_list_builds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_list_builds" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_list_builds_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_list_builds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14261,8 +14273,9 @@ def test_cancel_build_rest_bad_request(request_type=cloudbuild.CancelBuildReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14345,17 +14358,19 @@ def test_cancel_build_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_cancel_build" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_cancel_build_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_cancel_build" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_cancel_build" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_cancel_build_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_cancel_build" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14404,8 +14419,9 @@ def test_retry_build_rest_bad_request(request_type=cloudbuild.RetryBuildRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14462,19 +14478,20 @@ def test_retry_build_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_retry_build" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_retry_build_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_retry_build" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_retry_build" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_retry_build_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_retry_build" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14523,8 +14540,9 @@ def test_approve_build_rest_bad_request(request_type=cloudbuild.ApproveBuildRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14581,19 +14599,20 @@ def test_approve_build_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_approve_build" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_approve_build_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_approve_build" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_approve_build" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_approve_build_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_approve_build" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14644,8 +14663,9 @@ def test_create_build_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15090,17 +15110,20 @@ def test_create_build_trigger_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_create_build_trigger" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_create_build_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_create_build_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_create_build_trigger" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_create_build_trigger_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_create_build_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15153,8 +15176,9 @@ def test_get_build_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15236,17 +15260,19 @@ def test_get_build_trigger_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_build_trigger" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_build_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_get_build_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_build_trigger" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_build_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_get_build_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15299,8 +15325,9 @@ def test_list_build_triggers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15363,17 +15390,20 @@ def test_list_build_triggers_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_list_build_triggers" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_list_build_triggers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_list_build_triggers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_list_build_triggers" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_list_build_triggers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_list_build_triggers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15431,8 +15461,9 @@ def test_delete_build_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15489,13 +15520,13 @@ def test_delete_build_trigger_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_delete_build_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_delete_build_trigger" + ) as pre, + ): pre.assert_not_called() pb_message = cloudbuild.DeleteBuildTriggerRequest.pb( cloudbuild.DeleteBuildTriggerRequest() @@ -15540,8 +15571,9 @@ def test_update_build_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15986,17 +16018,20 @@ def test_update_build_trigger_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_update_build_trigger" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_update_build_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_update_build_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_update_build_trigger" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_update_build_trigger_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_update_build_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16049,8 +16084,9 @@ def test_run_build_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16184,19 +16220,20 @@ def test_run_build_trigger_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_run_build_trigger" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_run_build_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_run_build_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_run_build_trigger" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_run_build_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_run_build_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16249,8 +16286,9 @@ def test_receive_trigger_webhook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16387,18 +16425,20 @@ def test_receive_trigger_webhook_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_receive_trigger_webhook" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, - "post_receive_trigger_webhook_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_receive_trigger_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_receive_trigger_webhook" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_receive_trigger_webhook_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_receive_trigger_webhook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16456,8 +16496,9 @@ def test_create_worker_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16609,19 +16650,21 @@ def test_create_worker_pool_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_create_worker_pool" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_create_worker_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_create_worker_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_create_worker_pool" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_create_worker_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_create_worker_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16672,8 +16715,9 @@ def test_get_worker_pool_rest_bad_request(request_type=cloudbuild.GetWorkerPoolR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16744,17 +16788,19 @@ def test_get_worker_pool_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_worker_pool" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_worker_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_get_worker_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_worker_pool" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_worker_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_get_worker_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16807,8 +16853,9 @@ def test_delete_worker_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16865,19 +16912,21 @@ def test_delete_worker_pool_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_delete_worker_pool" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_delete_worker_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_delete_worker_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_delete_worker_pool" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_delete_worker_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_delete_worker_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16934,8 +16983,9 @@ def test_update_worker_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17091,19 +17141,21 @@ def test_update_worker_pool_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudBuildRestInterceptor, "post_update_worker_pool" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_update_worker_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_update_worker_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_update_worker_pool" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_update_worker_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_update_worker_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17156,8 +17208,9 @@ def test_list_worker_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17220,17 +17273,19 @@ def test_list_worker_pools_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_list_worker_pools" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_list_worker_pools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_list_worker_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_list_worker_pools" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_list_worker_pools_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_list_worker_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17285,8 +17340,9 @@ def test_get_default_service_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17351,18 +17407,20 @@ def test_get_default_service_account_rest_interceptors(null_interceptor): ) client = CloudBuildClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudBuildRestInterceptor, "post_get_default_service_account" - ) as post, mock.patch.object( - transports.CloudBuildRestInterceptor, - "post_get_default_service_account_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudBuildRestInterceptor, "pre_get_default_service_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudBuildRestInterceptor, "post_get_default_service_account" + ) as post, + mock.patch.object( + transports.CloudBuildRestInterceptor, + "post_get_default_service_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudBuildRestInterceptor, "pre_get_default_service_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18430,11 +18488,14 @@ def test_cloud_build_base_transport(): def test_cloud_build_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.devtools.cloudbuild_v1.services.cloud_build.transports.CloudBuildTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.devtools.cloudbuild_v1.services.cloud_build.transports.CloudBuildTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudBuildTransport( @@ -18451,9 +18512,12 @@ def test_cloud_build_base_transport_with_credentials_file(): def test_cloud_build_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.devtools.cloudbuild_v1.services.cloud_build.transports.CloudBuildTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.devtools.cloudbuild_v1.services.cloud_build.transports.CloudBuildTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudBuildTransport() @@ -18525,11 +18589,12 @@ def test_cloud_build_transport_auth_gdch_credentials(transport_class): def test_cloud_build_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v2/test_repository_manager.py b/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v2/test_repository_manager.py index a8f11e4703ff..867b368b70de 100644 --- a/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v2/test_repository_manager.py +++ b/packages/google-cloud-build/tests/unit/gapic/cloudbuild_v2/test_repository_manager.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RepositoryManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): RepositoryManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RepositoryManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1332,11 +1337,13 @@ def test_repository_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10361,8 +10368,9 @@ def test_create_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10546,20 +10554,21 @@ def test_create_connection_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_create_connection" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_create_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_create_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_create_connection" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_create_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_create_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10612,8 +10621,9 @@ def test_get_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10682,17 +10692,20 @@ def test_get_connection_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_get_connection" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_get_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_get_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_get_connection" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_get_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_get_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10745,8 +10758,9 @@ def test_list_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10809,18 +10823,20 @@ def test_list_connections_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_list_connections" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_list_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_list_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_list_connections" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_list_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_list_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10880,8 +10896,9 @@ def test_update_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11067,20 +11084,21 @@ def test_update_connection_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_update_connection" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_update_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_update_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_update_connection" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_update_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_update_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11133,8 +11151,9 @@ def test_delete_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11191,20 +11210,21 @@ def test_delete_connection_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_delete_connection" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_delete_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_delete_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_delete_connection" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_delete_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_delete_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11257,8 +11277,9 @@ def test_create_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11391,20 +11412,21 @@ def test_create_repository_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_create_repository" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_create_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_create_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_create_repository" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_create_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_create_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11457,8 +11479,9 @@ def test_batch_create_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11515,20 +11538,22 @@ def test_batch_create_repositories_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_batch_create_repositories" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_batch_create_repositories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_batch_create_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_batch_create_repositories", + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_batch_create_repositories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_batch_create_repositories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11583,8 +11608,9 @@ def test_get_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11655,17 +11681,20 @@ def test_get_repository_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_get_repository" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_get_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_get_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_get_repository" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_get_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_get_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11718,8 +11747,9 @@ def test_list_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11782,18 +11812,20 @@ def test_list_repositories_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_list_repositories" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_list_repositories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_list_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_list_repositories" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_list_repositories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_list_repositories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11853,8 +11885,9 @@ def test_delete_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11913,20 +11946,21 @@ def test_delete_repository_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_delete_repository" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_delete_repository_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_delete_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_delete_repository" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_delete_repository_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_delete_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11981,8 +12015,9 @@ def test_fetch_read_write_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12047,18 +12082,20 @@ def test_fetch_read_write_token_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_fetch_read_write_token" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_fetch_read_write_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_fetch_read_write_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_fetch_read_write_token" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_fetch_read_write_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_fetch_read_write_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12118,8 +12155,9 @@ def test_fetch_read_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12184,18 +12222,20 @@ def test_fetch_read_token_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_fetch_read_token" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_fetch_read_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_fetch_read_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_fetch_read_token" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_fetch_read_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_fetch_read_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12255,8 +12295,9 @@ def test_fetch_linkable_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12321,18 +12362,22 @@ def test_fetch_linkable_repositories_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_fetch_linkable_repositories" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, - "post_fetch_linkable_repositories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_fetch_linkable_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_fetch_linkable_repositories", + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_fetch_linkable_repositories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "pre_fetch_linkable_repositories", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12390,8 +12435,9 @@ def test_fetch_git_refs_rest_bad_request(request_type=repositories.FetchGitRefsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12456,17 +12502,20 @@ def test_fetch_git_refs_rest_interceptors(null_interceptor): ) client = RepositoryManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_fetch_git_refs" - ) as post, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "post_fetch_git_refs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RepositoryManagerRestInterceptor, "pre_fetch_git_refs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "post_fetch_git_refs" + ) as post, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, + "post_fetch_git_refs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RepositoryManagerRestInterceptor, "pre_fetch_git_refs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12523,8 +12572,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12587,8 +12637,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12651,8 +12702,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12715,8 +12767,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12777,8 +12830,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13224,11 +13278,14 @@ def test_repository_manager_base_transport(): def test_repository_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.devtools.cloudbuild_v2.services.repository_manager.transports.RepositoryManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.devtools.cloudbuild_v2.services.repository_manager.transports.RepositoryManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RepositoryManagerTransport( @@ -13245,9 +13302,12 @@ def test_repository_manager_base_transport_with_credentials_file(): def test_repository_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.devtools.cloudbuild_v2.services.repository_manager.transports.RepositoryManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.devtools.cloudbuild_v2.services.repository_manager.transports.RepositoryManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RepositoryManagerTransport() @@ -13319,11 +13379,12 @@ def test_repository_manager_transport_auth_gdch_credentials(transport_class): def test_repository_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -14047,6 +14108,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RepositoryManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RepositoryManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RepositoryManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14192,6 +14285,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RepositoryManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RepositoryManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = RepositoryManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14356,6 +14483,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = RepositoryManagerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = RepositoryManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = RepositoryManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14523,6 +14685,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = RepositoryManagerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = RepositoryManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = RepositoryManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14700,6 +14897,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = RepositoryManagerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = RepositoryManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = RepositoryManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/async_client.py b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/async_client.py index 7e430312b3b5..3e4f4367373a 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/async_client.py +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> UsageServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/client.py b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/client.py index 4ad7654c8aa3..c829777389b2 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/client.py +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/client.py @@ -111,7 +111,7 @@ class UsageServiceClient(metaclass=UsageServiceClientMeta): """Provides access to historical and forecasted usage data.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -460,7 +464,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -557,7 +561,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -653,7 +657,7 @@ def __init__( self._universe_domain = UsageServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/README.rst b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/README.rst index e0400cc1848b..88248b49b43a 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/README.rst +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UsageServiceTransport` is the ABC for all transports. -- public child `UsageServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UsageServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUsageServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UsageServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UsageServiceTransport`` is the ABC for all transports. + +- public child ``UsageServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UsageServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUsageServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UsageServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/base.py b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/base.py index e3c59e99d1df..f4dfc0f1b655 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/base.py +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc.py b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc.py index adc97d8fc873..fa12d5fb9290 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc.py +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc_asyncio.py b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc_asyncio.py index f169d043227e..5083b4f9865e 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/rest.py b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/rest.py index d7217f802f55..3541ccc5ee6a 100644 --- a/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/rest.py +++ b/packages/google-cloud-capacityplanner/google/cloud/capacityplanner_v1beta/services/usage_service/transports/rest.py @@ -492,6 +492,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UsageServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-capacityplanner/noxfile.py b/packages/google-cloud-capacityplanner/noxfile.py index 78729096e055..95b8572f4b04 100644 --- a/packages/google-cloud-capacityplanner/noxfile.py +++ b/packages/google-cloud-capacityplanner/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-capacityplanner/setup.py b/packages/google-cloud-capacityplanner/setup.py index faa77d646e6a..6d533de1e68a 100644 --- a/packages/google-cloud-capacityplanner/setup.py +++ b/packages/google-cloud-capacityplanner/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-capacityplanner" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-capacityplanner/testing/constraints-3.7.txt b/packages/google-cloud-capacityplanner/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-capacityplanner/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-capacityplanner/testing/constraints-3.8.txt b/packages/google-cloud-capacityplanner/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-capacityplanner/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-capacityplanner/testing/constraints-3.9.txt b/packages/google-cloud-capacityplanner/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-capacityplanner/testing/constraints-3.9.txt +++ b/packages/google-cloud-capacityplanner/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-capacityplanner/tests/unit/gapic/capacityplanner_v1beta/test_usage_service.py b/packages/google-cloud-capacityplanner/tests/unit/gapic/capacityplanner_v1beta/test_usage_service.py index 631aecdde582..8ebaae34016e 100644 --- a/packages/google-cloud-capacityplanner/tests/unit/gapic/capacityplanner_v1beta/test_usage_service.py +++ b/packages/google-cloud-capacityplanner/tests/unit/gapic/capacityplanner_v1beta/test_usage_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UsageServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert UsageServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + UsageServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1262,11 +1267,13 @@ def test_usage_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4291,8 +4298,9 @@ def test_query_usage_histories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4352,18 +4360,20 @@ def test_query_usage_histories_rest_interceptors(null_interceptor): ) client = UsageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UsageServiceRestInterceptor, "post_query_usage_histories" - ) as post, mock.patch.object( - transports.UsageServiceRestInterceptor, - "post_query_usage_histories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UsageServiceRestInterceptor, "pre_query_usage_histories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_query_usage_histories" + ) as post, + mock.patch.object( + transports.UsageServiceRestInterceptor, + "post_query_usage_histories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UsageServiceRestInterceptor, "pre_query_usage_histories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4421,8 +4431,9 @@ def test_query_forecasts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4482,17 +4493,19 @@ def test_query_forecasts_rest_interceptors(null_interceptor): ) client = UsageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UsageServiceRestInterceptor, "post_query_forecasts" - ) as post, mock.patch.object( - transports.UsageServiceRestInterceptor, "post_query_forecasts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UsageServiceRestInterceptor, "pre_query_forecasts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_query_forecasts" + ) as post, + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_query_forecasts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UsageServiceRestInterceptor, "pre_query_forecasts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4550,8 +4563,9 @@ def test_query_reservations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4611,17 +4625,20 @@ def test_query_reservations_rest_interceptors(null_interceptor): ) client = UsageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UsageServiceRestInterceptor, "post_query_reservations" - ) as post, mock.patch.object( - transports.UsageServiceRestInterceptor, "post_query_reservations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UsageServiceRestInterceptor, "pre_query_reservations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_query_reservations" + ) as post, + mock.patch.object( + transports.UsageServiceRestInterceptor, + "post_query_reservations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UsageServiceRestInterceptor, "pre_query_reservations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4679,8 +4696,9 @@ def test_export_usage_histories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4737,20 +4755,21 @@ def test_export_usage_histories_rest_interceptors(null_interceptor): ) client = UsageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UsageServiceRestInterceptor, "post_export_usage_histories" - ) as post, mock.patch.object( - transports.UsageServiceRestInterceptor, - "post_export_usage_histories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UsageServiceRestInterceptor, "pre_export_usage_histories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_export_usage_histories" + ) as post, + mock.patch.object( + transports.UsageServiceRestInterceptor, + "post_export_usage_histories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UsageServiceRestInterceptor, "pre_export_usage_histories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4803,8 +4822,9 @@ def test_export_forecasts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4861,19 +4881,21 @@ def test_export_forecasts_rest_interceptors(null_interceptor): ) client = UsageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UsageServiceRestInterceptor, "post_export_forecasts" - ) as post, mock.patch.object( - transports.UsageServiceRestInterceptor, "post_export_forecasts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UsageServiceRestInterceptor, "pre_export_forecasts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_export_forecasts" + ) as post, + mock.patch.object( + transports.UsageServiceRestInterceptor, + "post_export_forecasts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UsageServiceRestInterceptor, "pre_export_forecasts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4926,8 +4948,9 @@ def test_export_reservations_usage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4984,20 +5007,21 @@ def test_export_reservations_usage_rest_interceptors(null_interceptor): ) client = UsageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UsageServiceRestInterceptor, "post_export_reservations_usage" - ) as post, mock.patch.object( - transports.UsageServiceRestInterceptor, - "post_export_reservations_usage_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UsageServiceRestInterceptor, "pre_export_reservations_usage" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UsageServiceRestInterceptor, "post_export_reservations_usage" + ) as post, + mock.patch.object( + transports.UsageServiceRestInterceptor, + "post_export_reservations_usage_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UsageServiceRestInterceptor, "pre_export_reservations_usage" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5254,11 +5278,14 @@ def test_usage_service_base_transport(): def test_usage_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.capacityplanner_v1beta.services.usage_service.transports.UsageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.capacityplanner_v1beta.services.usage_service.transports.UsageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UsageServiceTransport( @@ -5278,9 +5305,12 @@ def test_usage_service_base_transport_with_credentials_file(): def test_usage_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.capacityplanner_v1beta.services.usage_service.transports.UsageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.capacityplanner_v1beta.services.usage_service.transports.UsageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UsageServiceTransport() @@ -5358,11 +5388,12 @@ def test_usage_service_transport_auth_gdch_credentials(transport_class): def test_usage_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/async_client.py b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/async_client.py index 03d0ed5f9bd2..517199e4668a 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/async_client.py +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/async_client.py @@ -262,7 +262,7 @@ def transport(self) -> CertificateManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4277,7 +4277,7 @@ async def sample_delete_trust_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4303,8 +4303,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4313,7 +4317,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4321,7 +4325,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4332,7 +4336,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4358,8 +4362,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4368,7 +4376,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4376,7 +4384,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4387,7 +4395,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4417,8 +4425,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4427,7 +4439,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4435,7 +4447,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4443,7 +4455,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4472,8 +4484,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4482,7 +4498,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4490,7 +4506,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4498,7 +4514,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4524,8 +4540,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4534,7 +4554,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4542,7 +4562,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4553,7 +4573,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4579,8 +4599,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4589,7 +4613,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4597,7 +4621,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/client.py b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/client.py index f2171cb1f8f9..6cc3b8661c6a 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/client.py +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/client.py @@ -154,7 +154,7 @@ class CertificateManagerClient(metaclass=CertificateManagerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -162,7 +162,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -172,6 +172,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -615,7 +619,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -712,7 +716,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -812,7 +816,7 @@ def __init__( self._universe_domain = CertificateManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4756,7 +4760,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4782,8 +4786,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4792,7 +4800,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4801,7 +4809,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4815,7 +4823,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4841,8 +4849,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4851,7 +4863,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4860,7 +4872,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4874,7 +4886,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4904,8 +4916,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4914,7 +4930,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4922,7 +4938,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4930,7 +4946,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4959,8 +4975,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4969,7 +4989,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4977,7 +4997,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4985,7 +5005,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5011,8 +5031,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5021,7 +5045,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5030,7 +5054,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5044,7 +5068,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5070,8 +5094,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5080,7 +5108,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5089,7 +5117,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/README.rst b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/README.rst index b2ce92ff9cce..787ee6e9d239 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/README.rst +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CertificateManagerTransport` is the ABC for all transports. -- public child `CertificateManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CertificateManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCertificateManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CertificateManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CertificateManagerTransport`` is the ABC for all transports. + +- public child ``CertificateManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CertificateManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCertificateManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CertificateManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/base.py b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/base.py index b8eeb0c0d9b6..c8115765ba8f 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/base.py +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc.py b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc.py index 6b8a729d24a4..5caa7bb97c02 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc.py +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -221,6 +221,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc_asyncio.py b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc_asyncio.py index 5facfe547702..6a27fbcafda9 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -272,6 +272,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/rest.py b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/rest.py index 97e0b593a6c1..cd866c93292c 100644 --- a/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/rest.py +++ b/packages/google-cloud-certificate-manager/google/cloud/certificate_manager_v1/services/certificate_manager/transports/rest.py @@ -2007,6 +2007,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CertificateManagerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-certificate-manager/noxfile.py b/packages/google-cloud-certificate-manager/noxfile.py index 2bb9379b4c65..1bdac352c91f 100644 --- a/packages/google-cloud-certificate-manager/noxfile.py +++ b/packages/google-cloud-certificate-manager/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-certificate-manager/setup.py b/packages/google-cloud-certificate-manager/setup.py index eac6a02bb55c..ea12f91acc1e 100644 --- a/packages/google-cloud-certificate-manager/setup.py +++ b/packages/google-cloud-certificate-manager/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-certificate-manager" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-certificate-manager/testing/constraints-3.7.txt b/packages/google-cloud-certificate-manager/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-certificate-manager/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-certificate-manager/testing/constraints-3.8.txt b/packages/google-cloud-certificate-manager/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-certificate-manager/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-certificate-manager/testing/constraints-3.9.txt b/packages/google-cloud-certificate-manager/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-certificate-manager/testing/constraints-3.9.txt +++ b/packages/google-cloud-certificate-manager/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-certificate-manager/tests/unit/gapic/certificate_manager_v1/test_certificate_manager.py b/packages/google-cloud-certificate-manager/tests/unit/gapic/certificate_manager_v1/test_certificate_manager.py index aea76cb9b553..b1c7c1ea10a2 100644 --- a/packages/google-cloud-certificate-manager/tests/unit/gapic/certificate_manager_v1/test_certificate_manager.py +++ b/packages/google-cloud-certificate-manager/tests/unit/gapic/certificate_manager_v1/test_certificate_manager.py @@ -137,6 +137,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CertificateManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -159,6 +160,10 @@ def test__get_default_mtls_endpoint(): CertificateManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CertificateManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1340,11 +1345,13 @@ def test_certificate_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -20648,8 +20655,9 @@ def test_list_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20714,18 +20722,20 @@ def test_list_certificates_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_list_certificates" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_list_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_list_certificates" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_list_certificates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20783,8 +20793,9 @@ def test_get_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20855,18 +20866,20 @@ def test_get_certificate_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_get_certificate" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_get_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_get_certificate" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_get_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20921,8 +20934,9 @@ def test_create_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21079,20 +21093,21 @@ def test_create_certificate_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_create_certificate" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_create_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_create_certificate" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_create_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21149,8 +21164,9 @@ def test_update_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21311,20 +21327,21 @@ def test_update_certificate_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_update_certificate" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_update_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_update_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_update_certificate" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_update_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21377,8 +21394,9 @@ def test_delete_certificate_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21435,20 +21453,21 @@ def test_delete_certificate_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_delete_certificate" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_certificate_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_delete_certificate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_delete_certificate" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_certificate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_delete_certificate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21501,8 +21520,9 @@ def test_list_certificate_maps_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21567,18 +21587,20 @@ def test_list_certificate_maps_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_list_certificate_maps" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_certificate_maps_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_list_certificate_maps" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_list_certificate_maps" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_certificate_maps_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_list_certificate_maps" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21638,8 +21660,9 @@ def test_get_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21706,18 +21729,20 @@ def test_get_certificate_map_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_get_certificate_map" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_get_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_get_certificate_map" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_get_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21772,8 +21797,9 @@ def test_create_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21913,20 +21939,21 @@ def test_create_certificate_map_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_create_certificate_map" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_create_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_create_certificate_map" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_create_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21983,8 +22010,9 @@ def test_update_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22128,20 +22156,21 @@ def test_update_certificate_map_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_update_certificate_map" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_update_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_update_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_update_certificate_map" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_update_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22196,8 +22225,9 @@ def test_delete_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22256,20 +22286,21 @@ def test_delete_certificate_map_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_delete_certificate_map" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_delete_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_delete_certificate_map" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_delete_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22324,8 +22355,9 @@ def test_list_certificate_map_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22394,19 +22426,22 @@ def test_list_certificate_map_entries_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_certificate_map_entries", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_certificate_map_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_list_certificate_map_entries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_certificate_map_entries", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_certificate_map_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_list_certificate_map_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22466,8 +22501,9 @@ def test_get_certificate_map_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22539,18 +22575,22 @@ def test_get_certificate_map_entry_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_get_certificate_map_entry" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_certificate_map_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_get_certificate_map_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_certificate_map_entry", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_certificate_map_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_get_certificate_map_entry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22610,8 +22650,9 @@ def test_create_certificate_map_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22752,21 +22793,23 @@ def test_create_certificate_map_entry_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_certificate_map_entry", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_certificate_map_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_create_certificate_map_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_certificate_map_entry", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_certificate_map_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_create_certificate_map_entry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22823,8 +22866,9 @@ def test_update_certificate_map_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22967,21 +23011,23 @@ def test_update_certificate_map_entry_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_update_certificate_map_entry", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_update_certificate_map_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_update_certificate_map_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_certificate_map_entry", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_certificate_map_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_update_certificate_map_entry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23036,8 +23082,9 @@ def test_delete_certificate_map_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23096,21 +23143,23 @@ def test_delete_certificate_map_entry_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_certificate_map_entry", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_certificate_map_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_delete_certificate_map_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_certificate_map_entry", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_certificate_map_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_delete_certificate_map_entry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23163,8 +23212,9 @@ def test_list_dns_authorizations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23231,18 +23281,20 @@ def test_list_dns_authorizations_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_list_dns_authorizations" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_dns_authorizations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_list_dns_authorizations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_list_dns_authorizations" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_dns_authorizations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_list_dns_authorizations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23302,8 +23354,9 @@ def test_get_dns_authorization_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23374,18 +23427,20 @@ def test_get_dns_authorization_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_get_dns_authorization" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_dns_authorization_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_get_dns_authorization" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_get_dns_authorization" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_dns_authorization_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_get_dns_authorization" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23443,8 +23498,9 @@ def test_create_dns_authorization_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23584,20 +23640,22 @@ def test_create_dns_authorization_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_create_dns_authorization" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_dns_authorization_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_create_dns_authorization" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_dns_authorization", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_dns_authorization_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_create_dns_authorization" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23654,8 +23712,9 @@ def test_update_dns_authorization_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23799,20 +23858,22 @@ def test_update_dns_authorization_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_update_dns_authorization" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_update_dns_authorization_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_update_dns_authorization" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_dns_authorization", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_dns_authorization_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_update_dns_authorization" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23867,8 +23928,9 @@ def test_delete_dns_authorization_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23927,20 +23989,22 @@ def test_delete_dns_authorization_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_delete_dns_authorization" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_dns_authorization_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_delete_dns_authorization" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_dns_authorization", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_dns_authorization_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_delete_dns_authorization" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23993,8 +24057,9 @@ def test_list_certificate_issuance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24065,20 +24130,22 @@ def test_list_certificate_issuance_configs_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_certificate_issuance_configs", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_certificate_issuance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "pre_list_certificate_issuance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_certificate_issuance_configs", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_certificate_issuance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_list_certificate_issuance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24144,8 +24211,9 @@ def test_get_certificate_issuance_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24221,20 +24289,22 @@ def test_get_certificate_issuance_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_certificate_issuance_config", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_certificate_issuance_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "pre_get_certificate_issuance_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_certificate_issuance_config", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_certificate_issuance_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_get_certificate_issuance_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24292,8 +24362,9 @@ def test_create_certificate_issuance_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24436,22 +24507,23 @@ def test_create_certificate_issuance_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_certificate_issuance_config", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_certificate_issuance_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "pre_create_certificate_issuance_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_certificate_issuance_config", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_certificate_issuance_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_create_certificate_issuance_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24510,8 +24582,9 @@ def test_delete_certificate_issuance_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24570,22 +24643,23 @@ def test_delete_certificate_issuance_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_certificate_issuance_config", - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_certificate_issuance_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "pre_delete_certificate_issuance_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_certificate_issuance_config", + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_certificate_issuance_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "pre_delete_certificate_issuance_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24640,8 +24714,9 @@ def test_list_trust_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24706,18 +24781,20 @@ def test_list_trust_configs_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_list_trust_configs" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_list_trust_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_list_trust_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_list_trust_configs" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_list_trust_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_list_trust_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24775,8 +24852,9 @@ def test_get_trust_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24843,18 +24921,20 @@ def test_get_trust_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_get_trust_config" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_get_trust_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_get_trust_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_get_trust_config" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_get_trust_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_get_trust_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24907,8 +24987,9 @@ def test_create_trust_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25046,20 +25127,21 @@ def test_create_trust_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_create_trust_config" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_create_trust_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_create_trust_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_create_trust_config" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_create_trust_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_create_trust_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25116,8 +25198,9 @@ def test_update_trust_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25259,20 +25342,21 @@ def test_update_trust_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_update_trust_config" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_update_trust_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_update_trust_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_update_trust_config" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_update_trust_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_update_trust_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25325,8 +25409,9 @@ def test_delete_trust_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25383,20 +25468,21 @@ def test_delete_trust_config_rest_interceptors(null_interceptor): ) client = CertificateManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CertificateManagerRestInterceptor, "post_delete_trust_config" - ) as post, mock.patch.object( - transports.CertificateManagerRestInterceptor, - "post_delete_trust_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CertificateManagerRestInterceptor, "pre_delete_trust_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CertificateManagerRestInterceptor, "post_delete_trust_config" + ) as post, + mock.patch.object( + transports.CertificateManagerRestInterceptor, + "post_delete_trust_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CertificateManagerRestInterceptor, "pre_delete_trust_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25449,8 +25535,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25509,8 +25596,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25571,8 +25659,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25633,8 +25722,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25695,8 +25785,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25757,8 +25848,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -26562,11 +26654,14 @@ def test_certificate_manager_base_transport(): def test_certificate_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.certificate_manager_v1.services.certificate_manager.transports.CertificateManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.certificate_manager_v1.services.certificate_manager.transports.CertificateManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CertificateManagerTransport( @@ -26583,9 +26678,12 @@ def test_certificate_manager_base_transport_with_credentials_file(): def test_certificate_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.certificate_manager_v1.services.certificate_manager.transports.CertificateManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.certificate_manager_v1.services.certificate_manager.transports.CertificateManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CertificateManagerTransport() @@ -26657,11 +26755,12 @@ def test_certificate_manager_transport_auth_gdch_credentials(transport_class): def test_certificate_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -27515,6 +27614,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CertificateManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CertificateManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CertificateManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27654,6 +27785,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CertificateManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CertificateManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CertificateManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27799,6 +27962,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CertificateManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CertificateManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CertificateManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27944,6 +28141,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CertificateManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CertificateManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CertificateManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -28089,6 +28320,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CertificateManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CertificateManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CertificateManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -28230,6 +28495,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CertificateManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CertificateManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CertificateManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/async_client.py index afab0d7c550f..d0133c5646b1 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/async_client.py @@ -266,7 +266,7 @@ def transport(self) -> AgentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -6240,7 +6240,7 @@ async def sample_get_changelog(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6266,8 +6266,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6276,7 +6280,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6284,7 +6288,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6295,7 +6299,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6321,8 +6325,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6331,7 +6339,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6339,7 +6347,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6350,7 +6358,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6380,8 +6388,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6390,7 +6402,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6398,7 +6410,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6406,7 +6418,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6435,8 +6447,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6445,7 +6461,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6453,7 +6469,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6461,7 +6477,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6487,8 +6503,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6497,7 +6517,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6505,7 +6525,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6516,7 +6536,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6542,8 +6562,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6552,7 +6576,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6560,7 +6584,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/client.py index a1fed01a7e9f..f15077e7643b 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/client.py @@ -156,7 +156,7 @@ class AgentServiceClient(metaclass=AgentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -164,7 +164,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -174,6 +174,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -835,7 +839,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -932,7 +936,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1028,7 +1032,7 @@ def __init__( self._universe_domain = AgentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6862,7 +6866,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6888,8 +6892,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6898,7 +6906,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6907,7 +6915,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6921,7 +6929,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6947,8 +6955,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6957,7 +6969,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6966,7 +6978,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6980,7 +6992,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7010,8 +7022,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7020,7 +7036,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7028,7 +7044,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7036,7 +7052,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7065,8 +7081,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7075,7 +7095,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7083,7 +7103,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7091,7 +7111,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7117,8 +7137,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7127,7 +7151,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7136,7 +7160,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7150,7 +7174,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7176,8 +7200,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7186,7 +7214,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7195,7 +7223,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/README.rst index 4c0341274edf..da8c1b02d119 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AgentServiceTransport` is the ABC for all transports. -- public child `AgentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AgentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAgentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AgentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AgentServiceTransport`` is the ABC for all transports. + +- public child ``AgentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AgentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAgentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AgentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/base.py index e6be001da860..ffe9f3d3031f 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/base.py @@ -106,6 +106,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -155,6 +159,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc.py index 18b26e01ad23..ac89477534f6 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc.py @@ -77,7 +77,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -112,7 +112,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -208,6 +208,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc_asyncio.py index 380eb3439ccb..fd8d35284ce2 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/grpc_asyncio.py @@ -83,7 +83,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -118,7 +118,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -259,6 +259,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/rest.py index 60458e0245d9..cd15ff85ab2f 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/agent_service/transports/rest.py @@ -2654,6 +2654,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AgentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/async_client.py index bf9e1da27de3..ab1bf34c6dfa 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> SessionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -557,7 +557,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -583,8 +583,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -593,7 +597,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -601,7 +605,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -612,7 +616,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -638,8 +642,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -648,7 +656,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -656,7 +664,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -667,7 +675,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -697,8 +705,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -707,7 +719,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -715,7 +727,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -723,7 +735,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -752,8 +764,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -762,7 +778,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -770,7 +786,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -778,7 +794,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -804,8 +820,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -814,7 +834,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -822,7 +842,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -833,7 +853,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -859,8 +879,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -869,7 +893,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -877,7 +901,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/client.py index fd0c2c502f51..9eb5b4dfc1ec 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/client.py @@ -115,7 +115,7 @@ class SessionServiceClient(metaclass=SessionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -516,7 +520,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -613,7 +617,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -709,7 +713,7 @@ def __init__( self._universe_domain = SessionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1063,7 +1067,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1089,8 +1093,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1099,7 +1107,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1108,7 +1116,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1130,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1156,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1170,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1167,7 +1179,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1181,7 +1193,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1211,8 +1223,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1221,7 +1237,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1229,7 +1245,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1237,7 +1253,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1266,8 +1282,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1276,7 +1296,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1284,7 +1304,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1292,7 +1312,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1318,8 +1338,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1328,7 +1352,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1337,7 +1361,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1351,7 +1375,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1377,8 +1401,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1387,7 +1415,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1396,7 +1424,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/README.rst index f67320e75a5d..ec396d9ed40d 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionServiceTransport` is the ABC for all transports. -- public child `SessionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionServiceTransport`` is the ABC for all transports. + +- public child ``SessionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/base.py index 2a4af45afa9a..9e8a991a3d7b 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc.py index fea2902f62e1..b95220f9f675 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc_asyncio.py index b7197e0849fb..16c3857dca84 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/rest.py index 552d76b762f6..4dd9e10bb1d1 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/session_service/transports/rest.py @@ -352,6 +352,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/async_client.py index 582c2c1fa05f..0c86531c2e05 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> ToolServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -566,7 +566,7 @@ async def sample_retrieve_tools(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -592,8 +592,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -602,7 +606,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -610,7 +614,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -621,7 +625,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -647,8 +651,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -657,7 +665,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -665,7 +673,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -676,7 +684,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -706,8 +714,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -716,7 +728,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -724,7 +736,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -732,7 +744,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -761,8 +773,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -771,7 +787,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -779,7 +795,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -787,7 +803,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -813,8 +829,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -823,7 +843,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -831,7 +851,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -842,7 +862,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -868,8 +888,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -878,7 +902,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -886,7 +910,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/client.py index 674d009d6c14..e3255b3e4c73 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/client.py @@ -112,7 +112,7 @@ class ToolServiceClient(metaclass=ToolServiceClientMeta): """Tool service provides APIs for interacting with CES tools.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -531,7 +535,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -628,7 +632,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -724,7 +728,7 @@ def __init__( self._universe_domain = ToolServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1088,7 +1092,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1114,8 +1118,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1124,7 +1132,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1133,7 +1141,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1147,7 +1155,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1173,8 +1181,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1183,7 +1195,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1192,7 +1204,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1206,7 +1218,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1236,8 +1248,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1246,7 +1262,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1254,7 +1270,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1262,7 +1278,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1291,8 +1307,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1301,7 +1321,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1309,7 +1329,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1317,7 +1337,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1343,8 +1363,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1353,7 +1377,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1362,7 +1386,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1376,7 +1400,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1402,8 +1426,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1412,7 +1440,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1421,7 +1449,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/README.rst index b8d87f66bcf8..7aca20302399 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ToolServiceTransport` is the ABC for all transports. -- public child `ToolServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ToolServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseToolServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ToolServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ToolServiceTransport`` is the ABC for all transports. + +- public child ``ToolServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ToolServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseToolServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ToolServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/base.py index 9bb37b3f2aec..cb0ee6c279c4 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc.py index 8cb21094913c..2dabed38500e 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc_asyncio.py index d6720ce67928..39150643719f 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/rest.py index 551c24c702f1..c27c5b459e70 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/tool_service/transports/rest.py @@ -467,6 +467,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ToolServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/async_client.py index 2adfa44dd952..4edacb0f5c39 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> WidgetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -388,7 +388,7 @@ async def sample_generate_chat_token(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -414,8 +414,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -424,7 +428,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -432,7 +436,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -443,7 +447,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -469,8 +473,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -479,7 +487,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -487,7 +495,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -498,7 +506,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -528,8 +536,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -538,7 +550,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -546,7 +558,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -554,7 +566,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -583,8 +595,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -593,7 +609,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -601,7 +617,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -609,7 +625,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -635,8 +651,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -645,7 +665,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -653,7 +673,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -664,7 +684,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -690,8 +710,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -700,7 +724,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -708,7 +732,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/client.py index 3114982a985a..d2c6d793645e 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/client.py @@ -112,7 +112,7 @@ class WidgetServiceClient(metaclass=WidgetServiceClientMeta): """Provides APIs for widgets to interact with CES APIs.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -463,7 +467,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -560,7 +564,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -656,7 +660,7 @@ def __init__( self._universe_domain = WidgetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -853,7 +857,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -879,8 +883,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -889,7 +897,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -898,7 +906,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -912,7 +920,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -938,8 +946,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -948,7 +960,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -957,7 +969,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -971,7 +983,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1001,8 +1013,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1011,7 +1027,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1019,7 +1035,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1027,7 +1043,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1056,8 +1072,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1066,7 +1086,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1074,7 +1094,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1082,7 +1102,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1108,8 +1128,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1118,7 +1142,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1127,7 +1151,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1141,7 +1165,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1167,8 +1191,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1177,7 +1205,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1186,7 +1214,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/README.rst index 2c4c750cc475..64d0efec2636 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WidgetServiceTransport` is the ABC for all transports. -- public child `WidgetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WidgetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWidgetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WidgetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WidgetServiceTransport`` is the ABC for all transports. + +- public child ``WidgetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WidgetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWidgetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WidgetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/base.py index 0bfeb8eac062..093d29500dba 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc.py index 433cc062f940..fe5144716c09 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc_asyncio.py index 66b6c0563a23..2ed61b228de6 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/rest.py index 9ebdcab427c6..52af5c67093b 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1/services/widget_service/transports/rest.py @@ -352,6 +352,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WidgetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/async_client.py index f144f0879053..079a509311ca 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/async_client.py @@ -273,7 +273,7 @@ def transport(self) -> AgentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -6485,7 +6485,7 @@ async def sample_get_changelog(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6511,8 +6511,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6521,7 +6525,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6529,7 +6533,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6540,7 +6544,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6566,8 +6570,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6576,7 +6584,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6584,7 +6592,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6595,7 +6603,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6625,8 +6633,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6635,7 +6647,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6643,7 +6655,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6651,7 +6663,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6680,8 +6692,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6690,7 +6706,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6698,7 +6714,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6706,7 +6722,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6732,8 +6748,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6742,7 +6762,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6750,7 +6770,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6761,7 +6781,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6787,8 +6807,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6797,7 +6821,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6805,7 +6829,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/client.py index a9888dda73dd..1aa9e37ee4ab 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/client.py @@ -159,7 +159,7 @@ class AgentServiceClient(metaclass=AgentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -167,7 +167,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -177,6 +177,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -858,7 +862,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -955,7 +959,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1051,7 +1055,7 @@ def __init__( self._universe_domain = AgentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -7117,7 +7121,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7143,8 +7147,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7153,7 +7161,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7162,7 +7170,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7176,7 +7184,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7202,8 +7210,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7212,7 +7224,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7221,7 +7233,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7235,7 +7247,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7265,8 +7277,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7275,7 +7291,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7283,7 +7299,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7291,7 +7307,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7320,8 +7336,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7330,7 +7350,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7338,7 +7358,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7346,7 +7366,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7372,8 +7392,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7382,7 +7406,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7391,7 +7415,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7405,7 +7429,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7431,8 +7455,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7441,7 +7469,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7450,7 +7478,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/README.rst index 4c0341274edf..da8c1b02d119 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AgentServiceTransport` is the ABC for all transports. -- public child `AgentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AgentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAgentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AgentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AgentServiceTransport`` is the ABC for all transports. + +- public child ``AgentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AgentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAgentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AgentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/base.py index 1c428ad6a9df..27c145e9995c 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/base.py @@ -108,6 +108,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -157,6 +161,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc.py index 5954b494294b..abd920c3f943 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc.py @@ -79,7 +79,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -114,7 +114,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -210,6 +210,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc_asyncio.py index 77b8c7dda187..58ef0f066609 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/grpc_asyncio.py @@ -85,7 +85,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -120,7 +120,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -261,6 +261,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/rest.py index 0dbf4fd37e5d..8f1e194a2b31 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/agent_service/transports/rest.py @@ -2774,6 +2774,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AgentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/async_client.py index fcfe3017bfe9..8496fbb8d3e3 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/async_client.py @@ -251,7 +251,7 @@ def transport(self) -> EvaluationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4210,7 +4210,7 @@ async def sample_test_persona_voice(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4236,8 +4236,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4246,7 +4250,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4254,7 +4258,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4265,7 +4269,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4291,8 +4295,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4301,7 +4309,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4309,7 +4317,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4320,7 +4328,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4350,8 +4358,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4360,7 +4372,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4368,7 +4380,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4376,7 +4388,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4405,8 +4417,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4415,7 +4431,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4423,7 +4439,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4431,7 +4447,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4457,8 +4473,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4467,7 +4487,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4475,7 +4495,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4486,7 +4506,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4512,8 +4532,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4522,7 +4546,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4530,7 +4554,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/client.py index 76b18b7685d3..d68dc97dfd82 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/client.py @@ -127,7 +127,7 @@ class EvaluationServiceClient(metaclass=EvaluationServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -768,7 +772,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -865,7 +869,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -965,7 +969,7 @@ def __init__( self._universe_domain = EvaluationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4855,7 +4859,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4881,8 +4885,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4891,7 +4899,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4900,7 +4908,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4914,7 +4922,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4940,8 +4948,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4950,7 +4962,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4959,7 +4971,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4973,7 +4985,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5003,8 +5015,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5013,7 +5029,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5021,7 +5037,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5029,7 +5045,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5058,8 +5074,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5068,7 +5088,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5076,7 +5096,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5084,7 +5104,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5110,8 +5130,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5120,7 +5144,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5129,7 +5153,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5143,7 +5167,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5169,8 +5193,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5179,7 +5207,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5188,7 +5216,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/README.rst index b012f0c5c184..21b6cc6a5fa7 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EvaluationServiceTransport` is the ABC for all transports. -- public child `EvaluationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EvaluationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEvaluationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EvaluationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EvaluationServiceTransport`` is the ABC for all transports. + +- public child ``EvaluationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EvaluationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEvaluationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EvaluationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/base.py index 3d533cf7d153..e4a4f01a4f28 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc.py index be7dc7e1b385..9036f70b23db 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc_asyncio.py index dd228d6c6380..d95e7d7f3f43 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/rest.py index d2381d5e7928..a973256e1e2d 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/evaluation_service/transports/rest.py @@ -1907,6 +1907,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EvaluationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/async_client.py index 6c3981393c15..157e684130fb 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> SessionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -557,7 +557,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -583,8 +583,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -593,7 +597,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -601,7 +605,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -612,7 +616,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -638,8 +642,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -648,7 +656,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -656,7 +664,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -667,7 +675,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -697,8 +705,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -707,7 +719,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -715,7 +727,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -723,7 +735,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -752,8 +764,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -762,7 +778,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -770,7 +786,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -778,7 +794,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -804,8 +820,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -814,7 +834,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -822,7 +842,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -833,7 +853,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -859,8 +879,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -869,7 +893,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -877,7 +901,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/client.py index 5ff1797ce43e..385979c824ca 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/client.py @@ -115,7 +115,7 @@ class SessionServiceClient(metaclass=SessionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -516,7 +520,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -613,7 +617,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -709,7 +713,7 @@ def __init__( self._universe_domain = SessionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1063,7 +1067,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1089,8 +1093,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1099,7 +1107,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1108,7 +1116,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1130,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1156,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1170,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1167,7 +1179,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1181,7 +1193,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1211,8 +1223,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1221,7 +1237,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1229,7 +1245,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1237,7 +1253,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1266,8 +1282,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1276,7 +1296,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1284,7 +1304,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1292,7 +1312,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1318,8 +1338,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1328,7 +1352,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1337,7 +1361,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1351,7 +1375,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1377,8 +1401,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1387,7 +1415,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1396,7 +1424,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/README.rst index f67320e75a5d..ec396d9ed40d 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionServiceTransport` is the ABC for all transports. -- public child `SessionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionServiceTransport`` is the ABC for all transports. + +- public child ``SessionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/base.py index e205d75a035c..4e5d73fced77 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc.py index e4daba54f0fc..8d0324385ad7 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc_asyncio.py index 87aada3f8ac3..a0729e2601be 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/rest.py index 7b1a8caf4a70..7da908c1f373 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/session_service/transports/rest.py @@ -352,6 +352,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/async_client.py index 6af88ffc49c8..c548760ff3b5 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ToolServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -568,7 +568,7 @@ async def sample_retrieve_tools(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -594,8 +594,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -604,7 +608,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -612,7 +616,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -623,7 +627,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -649,8 +653,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -659,7 +667,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -667,7 +675,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -678,7 +686,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -708,8 +716,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -718,7 +730,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -726,7 +738,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -734,7 +746,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -763,8 +775,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -773,7 +789,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -781,7 +797,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -789,7 +805,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -815,8 +831,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -825,7 +845,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -833,7 +853,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -844,7 +864,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -870,8 +890,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -880,7 +904,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -888,7 +912,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/client.py index 021dc8dbbdc1..dcc67b4279c6 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/client.py @@ -112,7 +112,7 @@ class ToolServiceClient(metaclass=ToolServiceClientMeta): """Tool service provides APIs for interacting with CES tools.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -557,7 +561,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -654,7 +658,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -750,7 +754,7 @@ def __init__( self._universe_domain = ToolServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1114,7 +1118,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1140,8 +1144,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1150,7 +1158,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1159,7 +1167,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1173,7 +1181,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1199,8 +1207,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1209,7 +1221,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1218,7 +1230,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1232,7 +1244,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1262,8 +1274,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1272,7 +1288,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1280,7 +1296,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1288,7 +1304,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1317,8 +1333,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1327,7 +1347,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1335,7 +1355,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1343,7 +1363,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1369,8 +1389,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1379,7 +1403,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1388,7 +1412,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1402,7 +1426,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1428,8 +1452,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1438,7 +1466,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1447,7 +1475,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/README.rst index b8d87f66bcf8..7aca20302399 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ToolServiceTransport` is the ABC for all transports. -- public child `ToolServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ToolServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseToolServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ToolServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ToolServiceTransport`` is the ABC for all transports. + +- public child ``ToolServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ToolServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseToolServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ToolServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/base.py index 58a6a87c9aae..bceb86ecac24 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc.py index b84a8ce14e1b..2d78db5d7903 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc_asyncio.py index 317522e3ed8d..4ca529356621 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/rest.py index 144584b733a3..65ec5714bbbf 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/tool_service/transports/rest.py @@ -467,6 +467,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ToolServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/async_client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/async_client.py index b7b39d928c42..0285fc0ec79c 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/async_client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> WidgetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -388,7 +388,7 @@ async def sample_generate_chat_token(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -414,8 +414,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -424,7 +428,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -432,7 +436,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -443,7 +447,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -469,8 +473,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -479,7 +487,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -487,7 +495,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -498,7 +506,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -528,8 +536,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -538,7 +550,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -546,7 +558,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -554,7 +566,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -583,8 +595,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -593,7 +609,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -601,7 +617,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -609,7 +625,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -635,8 +651,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -645,7 +665,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -653,7 +673,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -664,7 +684,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -690,8 +710,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -700,7 +724,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -708,7 +732,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/client.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/client.py index a6f666f45acc..557432bbf7da 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/client.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/client.py @@ -112,7 +112,7 @@ class WidgetServiceClient(metaclass=WidgetServiceClientMeta): """Provides APIs for widgets to interact with CES APIs.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -463,7 +467,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -560,7 +564,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -656,7 +660,7 @@ def __init__( self._universe_domain = WidgetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -853,7 +857,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -879,8 +883,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -889,7 +897,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -898,7 +906,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -912,7 +920,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -938,8 +946,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -948,7 +960,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -957,7 +969,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -971,7 +983,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1001,8 +1013,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1011,7 +1027,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1019,7 +1035,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1027,7 +1043,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1056,8 +1072,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1066,7 +1086,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1074,7 +1094,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1082,7 +1102,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1108,8 +1128,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1118,7 +1142,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1127,7 +1151,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1141,7 +1165,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1167,8 +1191,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1177,7 +1205,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1186,7 +1214,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/README.rst b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/README.rst index 2c4c750cc475..64d0efec2636 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/README.rst +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WidgetServiceTransport` is the ABC for all transports. -- public child `WidgetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WidgetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWidgetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WidgetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WidgetServiceTransport`` is the ABC for all transports. + +- public child ``WidgetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WidgetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWidgetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WidgetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/base.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/base.py index e30a8b58c304..0f9a8d334090 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/base.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc.py index 211751ae6b22..87c0222f3526 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc_asyncio.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc_asyncio.py index 929f85ed1f6f..af8454af30c6 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/rest.py b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/rest.py index 4edc6e54f514..99824490a237 100644 --- a/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/rest.py +++ b/packages/google-cloud-ces/google/cloud/ces_v1beta/services/widget_service/transports/rest.py @@ -352,6 +352,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WidgetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ces/noxfile.py b/packages/google-cloud-ces/noxfile.py index ed45e75896a9..20a73a00f4cf 100644 --- a/packages/google-cloud-ces/noxfile.py +++ b/packages/google-cloud-ces/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-ces/setup.py b/packages/google-cloud-ces/setup.py index be0307f396ca..c99867d40bb0 100644 --- a/packages/google-cloud-ces/setup.py +++ b/packages/google-cloud-ces/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-ces" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-ces/testing/constraints-3.7.txt b/packages/google-cloud-ces/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-ces/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-ces/testing/constraints-3.8.txt b/packages/google-cloud-ces/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-ces/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-ces/testing/constraints-3.9.txt b/packages/google-cloud-ces/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-ces/testing/constraints-3.9.txt +++ b/packages/google-cloud-ces/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_agent_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_agent_service.py index a74875890f94..2e6cdc6d79f5 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_agent_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_agent_service.py @@ -171,6 +171,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AgentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -189,6 +190,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AgentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AgentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1309,11 +1314,13 @@ def test_agent_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -31973,8 +31980,9 @@ def test_list_apps_rest_bad_request(request_type=agent_service.ListAppsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32039,17 +32047,19 @@ def test_list_apps_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_apps" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_apps_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_apps" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_apps" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_apps_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_apps" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32100,8 +32110,9 @@ def test_get_app_rest_bad_request(request_type=agent_service.GetAppRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32184,17 +32195,17 @@ def test_get_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentServiceRestInterceptor, "pre_get_app") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32243,8 +32254,9 @@ def test_create_app_rest_bad_request(request_type=agent_service.CreateAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32505,19 +32517,20 @@ def test_create_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32566,8 +32579,9 @@ def test_update_app_rest_bad_request(request_type=agent_service.UpdateAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32854,17 +32868,19 @@ def test_update_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32913,8 +32929,9 @@ def test_delete_app_rest_bad_request(request_type=agent_service.DeleteAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32971,19 +32988,20 @@ def test_delete_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_delete_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_delete_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_delete_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_delete_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33032,8 +33050,9 @@ def test_export_app_rest_bad_request(request_type=agent_service.ExportAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33090,19 +33109,20 @@ def test_export_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_export_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_export_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_export_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_export_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_export_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_export_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33151,8 +33171,9 @@ def test_import_app_rest_bad_request(request_type=agent_service.ImportAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33209,19 +33230,20 @@ def test_import_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_import_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_import_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_import_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_import_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_import_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_import_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33270,8 +33292,9 @@ def test_list_agents_rest_bad_request(request_type=agent_service.ListAgentsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33334,17 +33357,19 @@ def test_list_agents_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_agents" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_agents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_agents" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_agents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_agents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33399,8 +33424,9 @@ def test_get_agent_rest_bad_request(request_type=agent_service.GetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33481,17 +33507,19 @@ def test_get_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_agent" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_agent" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33540,8 +33568,9 @@ def test_create_agent_rest_bad_request(request_type=agent_service.CreateAgentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33740,17 +33769,19 @@ def test_create_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_agent" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_agent" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33805,8 +33836,9 @@ def test_update_agent_rest_bad_request(request_type=agent_service.UpdateAgentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34009,17 +34041,19 @@ def test_update_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_agent" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_agent" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34072,8 +34106,9 @@ def test_delete_agent_rest_bad_request(request_type=agent_service.DeleteAgentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34132,13 +34167,13 @@ def test_delete_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_agent" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteAgentRequest.pb( agent_service.DeleteAgentRequest() @@ -34181,8 +34216,9 @@ def test_list_examples_rest_bad_request(request_type=agent_service.ListExamplesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34245,17 +34281,19 @@ def test_list_examples_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_examples" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_examples_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_examples" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_examples" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_examples_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_examples" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34310,8 +34348,9 @@ def test_get_example_rest_bad_request(request_type=agent_service.GetExampleReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34386,17 +34425,19 @@ def test_get_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_example" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_example" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34449,8 +34490,9 @@ def test_create_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34637,17 +34679,19 @@ def test_create_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_example" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_example" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34704,8 +34748,9 @@ def test_update_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34896,17 +34941,19 @@ def test_update_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_example" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_example" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34961,8 +35008,9 @@ def test_delete_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35021,13 +35069,13 @@ def test_delete_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_example" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteExampleRequest.pb( agent_service.DeleteExampleRequest() @@ -35070,8 +35118,9 @@ def test_list_tools_rest_bad_request(request_type=agent_service.ListToolsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35134,17 +35183,19 @@ def test_list_tools_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_tools" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_tools" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_tools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35197,8 +35248,9 @@ def test_get_tool_rest_bad_request(request_type=agent_service.GetToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35271,17 +35323,19 @@ def test_get_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_tool" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_tool" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35332,8 +35386,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35396,17 +35451,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_conversations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35466,8 +35524,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35548,17 +35607,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_conversation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35613,8 +35675,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35673,13 +35736,13 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_conversation" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteConversationRequest.pb( agent_service.DeleteConversationRequest() @@ -35724,8 +35787,9 @@ def test_batch_delete_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35782,20 +35846,21 @@ def test_batch_delete_conversations_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_batch_delete_conversations" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, - "post_batch_delete_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_batch_delete_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_batch_delete_conversations" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_batch_delete_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_batch_delete_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35846,8 +35911,9 @@ def test_create_tool_rest_bad_request(request_type=agent_service.CreateToolReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36198,17 +36264,19 @@ def test_create_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_tool" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_tool" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36263,8 +36331,9 @@ def test_update_tool_rest_bad_request(request_type=agent_service.UpdateToolReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36619,17 +36688,19 @@ def test_update_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_tool" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_tool" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36682,8 +36753,9 @@ def test_delete_tool_rest_bad_request(request_type=agent_service.DeleteToolReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36742,13 +36814,13 @@ def test_delete_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_tool" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteToolRequest.pb( agent_service.DeleteToolRequest() @@ -36793,8 +36865,9 @@ def test_list_guardrails_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36857,17 +36930,19 @@ def test_list_guardrails_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_guardrails" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_guardrails_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_guardrails" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_guardrails" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_guardrails_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_guardrails" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36925,8 +37000,9 @@ def test_get_guardrail_rest_bad_request(request_type=agent_service.GetGuardrailR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36999,17 +37075,19 @@ def test_get_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_guardrail" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_guardrail_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_guardrail" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_guardrail_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_guardrail" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37062,8 +37140,9 @@ def test_create_guardrail_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37257,17 +37336,20 @@ def test_create_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_guardrail" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_guardrail_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_guardrail" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_create_guardrail_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_guardrail" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37324,8 +37406,9 @@ def test_update_guardrail_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37523,17 +37606,20 @@ def test_update_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_guardrail" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_guardrail_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_guardrail" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_update_guardrail_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_guardrail" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37588,8 +37674,9 @@ def test_delete_guardrail_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37648,13 +37735,13 @@ def test_delete_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_guardrail" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteGuardrailRequest.pb( agent_service.DeleteGuardrailRequest() @@ -37699,8 +37786,9 @@ def test_list_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37763,17 +37851,20 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_list_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37833,8 +37924,9 @@ def test_get_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37905,17 +37997,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37968,8 +38062,9 @@ def test_create_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38135,17 +38230,20 @@ def test_create_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_deployment" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_deployment" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_create_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38202,8 +38300,9 @@ def test_update_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38373,17 +38472,20 @@ def test_update_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_deployment" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_deployment" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_update_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38438,8 +38540,9 @@ def test_delete_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38498,13 +38601,13 @@ def test_delete_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteDeploymentRequest.pb( agent_service.DeleteDeploymentRequest() @@ -38547,8 +38650,9 @@ def test_list_toolsets_rest_bad_request(request_type=agent_service.ListToolsetsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38611,17 +38715,19 @@ def test_list_toolsets_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_toolsets" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_toolsets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_toolsets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_toolsets" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_toolsets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_toolsets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38676,8 +38782,9 @@ def test_get_toolset_rest_bad_request(request_type=agent_service.GetToolsetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38750,17 +38857,19 @@ def test_get_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_toolset" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_toolset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_toolset" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_toolset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_toolset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38813,8 +38922,9 @@ def test_create_toolset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39024,17 +39134,19 @@ def test_create_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_toolset" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_toolset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_toolset" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_toolset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_toolset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39091,8 +39203,9 @@ def test_update_toolset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39306,17 +39419,19 @@ def test_update_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_toolset" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_toolset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_toolset" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_toolset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_toolset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39371,8 +39486,9 @@ def test_delete_toolset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39431,13 +39547,13 @@ def test_delete_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_toolset" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteToolsetRequest.pb( agent_service.DeleteToolsetRequest() @@ -39482,8 +39598,9 @@ def test_list_app_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39546,17 +39663,20 @@ def test_list_app_versions_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_app_versions" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_app_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_app_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_app_versions" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_list_app_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_app_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39616,8 +39736,9 @@ def test_get_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39690,17 +39811,19 @@ def test_get_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app_version" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app_version" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_app_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39753,8 +39876,9 @@ def test_create_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40454,17 +40578,20 @@ def test_create_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app_version" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_app_version" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_create_app_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_app_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40519,8 +40646,9 @@ def test_delete_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40579,13 +40707,13 @@ def test_delete_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_app_version" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteAppVersionRequest.pb( agent_service.DeleteAppVersionRequest() @@ -40632,8 +40760,9 @@ def test_restore_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40692,19 +40821,21 @@ def test_restore_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_restore_app_version" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_restore_app_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_restore_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_restore_app_version" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_restore_app_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_restore_app_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40757,8 +40888,9 @@ def test_list_changelogs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40821,17 +40953,19 @@ def test_list_changelogs_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_changelogs" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_changelogs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_changelogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_changelogs" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_changelogs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_changelogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40889,8 +41023,9 @@ def test_get_changelog_rest_bad_request(request_type=agent_service.GetChangelogR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40969,17 +41104,19 @@ def test_get_changelog_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_changelog" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_changelog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_changelog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_changelog" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_changelog_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_changelog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41032,8 +41169,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -41092,8 +41230,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -41154,8 +41293,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -41216,8 +41356,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -41278,8 +41419,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -41340,8 +41482,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42504,11 +42647,14 @@ def test_agent_service_base_transport(): def test_agent_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentServiceTransport( @@ -42528,9 +42674,12 @@ def test_agent_service_base_transport_with_credentials_file(): def test_agent_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentServiceTransport() @@ -42608,11 +42757,12 @@ def test_agent_service_transport_auth_gdch_credentials(transport_class): def test_agent_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -43775,6 +43925,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -43914,6 +44096,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -44059,6 +44273,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -44204,6 +44452,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -44349,6 +44631,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -44490,6 +44806,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_session_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_session_service.py index 43ccdf02d1b0..0562712a16c3 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_session_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_session_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( SessionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1283,11 +1288,13 @@ def test_session_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2029,8 +2036,9 @@ def test_run_session_rest_bad_request(request_type=session_service.RunSessionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2094,17 +2102,19 @@ def test_run_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_run_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_run_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_run_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_run_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_run_session_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_run_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2171,8 +2181,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2231,8 +2242,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2293,8 +2305,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2355,8 +2368,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2417,8 +2431,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2479,8 +2494,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2615,11 +2631,14 @@ def test_session_service_base_transport(): def test_session_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport( @@ -2639,9 +2658,12 @@ def test_session_service_base_transport_with_credentials_file(): def test_session_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport() @@ -2719,11 +2741,12 @@ def test_session_service_transport_auth_gdch_credentials(transport_class): def test_session_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3386,6 +3409,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3525,6 +3580,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3670,6 +3757,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3815,6 +3936,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3960,6 +4115,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4101,6 +4290,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_tool_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_tool_service.py index 50acc51a940c..9210fef0e348 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_tool_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_tool_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ToolServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ToolServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ToolServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1245,11 +1249,13 @@ def test_tool_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2646,8 +2652,9 @@ def test_execute_tool_rest_bad_request(request_type=tool_service.ExecuteToolRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2709,17 +2716,19 @@ def test_execute_tool_rest_interceptors(null_interceptor): ) client = ToolServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_execute_tool" - ) as post, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_execute_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolServiceRestInterceptor, "pre_execute_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_execute_tool" + ) as post, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_execute_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolServiceRestInterceptor, "pre_execute_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2774,8 +2783,9 @@ def test_retrieve_tool_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2837,17 +2847,20 @@ def test_retrieve_tool_schema_rest_interceptors(null_interceptor): ) client = ToolServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tool_schema" - ) as post, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tool_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolServiceRestInterceptor, "pre_retrieve_tool_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_retrieve_tool_schema" + ) as post, + mock.patch.object( + transports.ToolServiceRestInterceptor, + "post_retrieve_tool_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ToolServiceRestInterceptor, "pre_retrieve_tool_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2907,8 +2920,9 @@ def test_retrieve_tools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2970,17 +2984,19 @@ def test_retrieve_tools_rest_interceptors(null_interceptor): ) client = ToolServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tools" - ) as post, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolServiceRestInterceptor, "pre_retrieve_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_retrieve_tools" + ) as post, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_retrieve_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolServiceRestInterceptor, "pre_retrieve_tools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3035,8 +3051,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3095,8 +3112,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3157,8 +3175,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3219,8 +3238,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3281,8 +3301,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3343,8 +3364,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3522,11 +3544,14 @@ def test_tool_service_base_transport(): def test_tool_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolServiceTransport( @@ -3546,9 +3571,12 @@ def test_tool_service_base_transport_with_credentials_file(): def test_tool_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolServiceTransport() @@ -3626,11 +3654,12 @@ def test_tool_service_transport_auth_gdch_credentials(transport_class): def test_tool_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4304,6 +4333,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4443,6 +4504,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4588,6 +4681,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4733,6 +4860,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4878,6 +5039,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5019,6 +5214,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_widget_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_widget_service.py index 533df0435a2a..d2baa53a3b63 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_widget_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1/test_widget_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WidgetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( WidgetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + WidgetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1278,11 +1283,13 @@ def test_widget_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1896,8 +1903,9 @@ def test_generate_chat_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1962,18 +1970,20 @@ def test_generate_chat_token_rest_interceptors(null_interceptor): ) client = WidgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WidgetServiceRestInterceptor, "post_generate_chat_token" - ) as post, mock.patch.object( - transports.WidgetServiceRestInterceptor, - "post_generate_chat_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WidgetServiceRestInterceptor, "pre_generate_chat_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WidgetServiceRestInterceptor, "post_generate_chat_token" + ) as post, + mock.patch.object( + transports.WidgetServiceRestInterceptor, + "post_generate_chat_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WidgetServiceRestInterceptor, "pre_generate_chat_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2031,8 +2041,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2091,8 +2102,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2153,8 +2165,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2215,8 +2228,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2277,8 +2291,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2339,8 +2354,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2476,11 +2492,14 @@ def test_widget_service_base_transport(): def test_widget_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WidgetServiceTransport( @@ -2500,9 +2519,12 @@ def test_widget_service_base_transport_with_credentials_file(): def test_widget_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WidgetServiceTransport() @@ -2580,11 +2602,12 @@ def test_widget_service_transport_auth_gdch_credentials(transport_class): def test_widget_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3180,6 +3203,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3319,6 +3374,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3464,6 +3551,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3609,6 +3730,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3754,6 +3909,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3895,6 +4084,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_agent_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_agent_service.py index fc0456c10fb7..81209ba77d4d 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_agent_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_agent_service.py @@ -175,6 +175,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AgentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -193,6 +194,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AgentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AgentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1313,11 +1318,13 @@ def test_agent_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -33154,8 +33161,9 @@ def test_list_apps_rest_bad_request(request_type=agent_service.ListAppsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33220,17 +33228,19 @@ def test_list_apps_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_apps" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_apps_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_apps" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_apps" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_apps_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_apps" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33281,8 +33291,9 @@ def test_get_app_rest_bad_request(request_type=agent_service.GetAppRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33365,17 +33376,17 @@ def test_get_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentServiceRestInterceptor, "pre_get_app") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33424,8 +33435,9 @@ def test_create_app_rest_bad_request(request_type=agent_service.CreateAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33706,19 +33718,20 @@ def test_create_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33767,8 +33780,9 @@ def test_update_app_rest_bad_request(request_type=agent_service.UpdateAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34075,17 +34089,19 @@ def test_update_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34134,8 +34150,9 @@ def test_delete_app_rest_bad_request(request_type=agent_service.DeleteAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34192,19 +34209,20 @@ def test_delete_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_delete_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_delete_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_delete_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_delete_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34253,8 +34271,9 @@ def test_export_app_rest_bad_request(request_type=agent_service.ExportAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34311,19 +34330,20 @@ def test_export_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_export_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_export_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_export_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_export_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_export_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_export_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34372,8 +34392,9 @@ def test_import_app_rest_bad_request(request_type=agent_service.ImportAppRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34430,19 +34451,20 @@ def test_import_app_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_import_app" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_import_app_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_import_app" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_import_app" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_import_app_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_import_app" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34493,8 +34515,9 @@ def test_get_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34559,18 +34582,20 @@ def test_get_security_settings_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_security_settings" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, - "post_get_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_security_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_security_settings" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_get_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_security_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34629,8 +34654,9 @@ def test_update_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34778,18 +34804,20 @@ def test_update_security_settings_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_security_settings" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, - "post_update_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_security_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_security_settings" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_update_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_security_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34845,8 +34873,9 @@ def test_list_agents_rest_bad_request(request_type=agent_service.ListAgentsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34909,17 +34938,19 @@ def test_list_agents_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_agents" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_agents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_agents" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_agents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_agents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34974,8 +35005,9 @@ def test_get_agent_rest_bad_request(request_type=agent_service.GetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35056,17 +35088,19 @@ def test_get_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_agent" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_agent" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35115,8 +35149,9 @@ def test_create_agent_rest_bad_request(request_type=agent_service.CreateAgentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35315,17 +35350,19 @@ def test_create_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_agent" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_agent" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35380,8 +35417,9 @@ def test_update_agent_rest_bad_request(request_type=agent_service.UpdateAgentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35584,17 +35622,19 @@ def test_update_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_agent" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_agent" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35647,8 +35687,9 @@ def test_delete_agent_rest_bad_request(request_type=agent_service.DeleteAgentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35707,13 +35748,13 @@ def test_delete_agent_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_agent" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteAgentRequest.pb( agent_service.DeleteAgentRequest() @@ -35756,8 +35797,9 @@ def test_list_examples_rest_bad_request(request_type=agent_service.ListExamplesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35820,17 +35862,19 @@ def test_list_examples_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_examples" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_examples_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_examples" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_examples" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_examples_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_examples" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35885,8 +35929,9 @@ def test_get_example_rest_bad_request(request_type=agent_service.GetExampleReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35961,17 +36006,19 @@ def test_get_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_example" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_example" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36024,8 +36071,9 @@ def test_create_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36213,17 +36261,19 @@ def test_create_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_example" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_example" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36280,8 +36330,9 @@ def test_update_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36473,17 +36524,19 @@ def test_update_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_example" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_example" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36538,8 +36591,9 @@ def test_delete_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36598,13 +36652,13 @@ def test_delete_example_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_example" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteExampleRequest.pb( agent_service.DeleteExampleRequest() @@ -36647,8 +36701,9 @@ def test_list_tools_rest_bad_request(request_type=agent_service.ListToolsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36711,17 +36766,19 @@ def test_list_tools_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_tools" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_tools" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_tools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36774,8 +36831,9 @@ def test_get_tool_rest_bad_request(request_type=agent_service.GetToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36848,17 +36906,19 @@ def test_get_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_tool" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_tool" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36909,8 +36969,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36973,17 +37034,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_conversations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37043,8 +37107,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37125,17 +37190,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_conversation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37190,8 +37258,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37250,13 +37319,13 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_conversation" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteConversationRequest.pb( agent_service.DeleteConversationRequest() @@ -37301,8 +37370,9 @@ def test_batch_delete_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37359,20 +37429,21 @@ def test_batch_delete_conversations_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_batch_delete_conversations" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, - "post_batch_delete_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_batch_delete_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_batch_delete_conversations" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_batch_delete_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_batch_delete_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37423,8 +37494,9 @@ def test_create_tool_rest_bad_request(request_type=agent_service.CreateToolReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37780,17 +37852,19 @@ def test_create_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_tool" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_tool" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37845,8 +37919,9 @@ def test_update_tool_rest_bad_request(request_type=agent_service.UpdateToolReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38206,17 +38281,19 @@ def test_update_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_tool" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_tool" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38269,8 +38346,9 @@ def test_delete_tool_rest_bad_request(request_type=agent_service.DeleteToolReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38329,13 +38407,13 @@ def test_delete_tool_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_tool" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteToolRequest.pb( agent_service.DeleteToolRequest() @@ -38380,8 +38458,9 @@ def test_list_guardrails_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38444,17 +38523,19 @@ def test_list_guardrails_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_guardrails" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_guardrails_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_guardrails" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_guardrails" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_guardrails_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_guardrails" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38512,8 +38593,9 @@ def test_get_guardrail_rest_bad_request(request_type=agent_service.GetGuardrailR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38586,17 +38668,19 @@ def test_get_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_guardrail" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_guardrail_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_guardrail" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_guardrail_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_guardrail" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38649,8 +38733,9 @@ def test_create_guardrail_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38844,17 +38929,20 @@ def test_create_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_guardrail" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_guardrail_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_guardrail" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_create_guardrail_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_guardrail" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38911,8 +38999,9 @@ def test_update_guardrail_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39110,17 +39199,20 @@ def test_update_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_guardrail" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_guardrail_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_guardrail" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_update_guardrail_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_guardrail" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39175,8 +39267,9 @@ def test_delete_guardrail_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39235,13 +39328,13 @@ def test_delete_guardrail_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_guardrail" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_guardrail" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteGuardrailRequest.pb( agent_service.DeleteGuardrailRequest() @@ -39286,8 +39379,9 @@ def test_list_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39350,17 +39444,20 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_list_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39420,8 +39517,9 @@ def test_get_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39492,17 +39590,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39555,8 +39655,9 @@ def test_create_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39722,17 +39823,20 @@ def test_create_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_deployment" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_deployment" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_create_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39789,8 +39893,9 @@ def test_update_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39960,17 +40065,20 @@ def test_update_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_deployment" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_deployment" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_update_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40025,8 +40133,9 @@ def test_delete_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40085,13 +40194,13 @@ def test_delete_deployment_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteDeploymentRequest.pb( agent_service.DeleteDeploymentRequest() @@ -40134,8 +40243,9 @@ def test_list_toolsets_rest_bad_request(request_type=agent_service.ListToolsetsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40198,17 +40308,19 @@ def test_list_toolsets_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_toolsets" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_toolsets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_toolsets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_toolsets" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_toolsets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_toolsets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40263,8 +40375,9 @@ def test_get_toolset_rest_bad_request(request_type=agent_service.GetToolsetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40337,17 +40450,19 @@ def test_get_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_toolset" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_toolset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_toolset" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_toolset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_toolset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40400,8 +40515,9 @@ def test_create_toolset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40611,17 +40727,19 @@ def test_create_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_toolset" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_toolset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_toolset" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_toolset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_toolset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40678,8 +40796,9 @@ def test_update_toolset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40893,17 +41012,19 @@ def test_update_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_toolset" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_update_toolset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_update_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_toolset" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_update_toolset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_update_toolset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40958,8 +41079,9 @@ def test_delete_toolset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41018,13 +41140,13 @@ def test_delete_toolset_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_toolset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_toolset" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteToolsetRequest.pb( agent_service.DeleteToolsetRequest() @@ -41069,8 +41191,9 @@ def test_list_app_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41133,17 +41256,20 @@ def test_list_app_versions_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_app_versions" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_app_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_app_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_app_versions" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_list_app_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_app_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41203,8 +41329,9 @@ def test_get_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41277,17 +41404,19 @@ def test_get_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app_version" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_app_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app_version" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_app_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_app_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41340,8 +41469,9 @@ def test_create_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42070,17 +42200,20 @@ def test_create_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app_version" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_create_app_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_create_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_create_app_version" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_create_app_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_create_app_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42135,8 +42268,9 @@ def test_delete_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42195,13 +42329,13 @@ def test_delete_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_delete_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_delete_app_version" + ) as pre, + ): pre.assert_not_called() pb_message = agent_service.DeleteAppVersionRequest.pb( agent_service.DeleteAppVersionRequest() @@ -42248,8 +42382,9 @@ def test_restore_app_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42308,19 +42443,21 @@ def test_restore_app_version_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentServiceRestInterceptor, "post_restore_app_version" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_restore_app_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_restore_app_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_restore_app_version" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, + "post_restore_app_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_restore_app_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42373,8 +42510,9 @@ def test_list_changelogs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42437,17 +42575,19 @@ def test_list_changelogs_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_changelogs" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_list_changelogs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_list_changelogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_changelogs" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_list_changelogs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_list_changelogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42505,8 +42645,9 @@ def test_get_changelog_rest_bad_request(request_type=agent_service.GetChangelogR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42585,17 +42726,19 @@ def test_get_changelog_rest_interceptors(null_interceptor): ) client = AgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_changelog" - ) as post, mock.patch.object( - transports.AgentServiceRestInterceptor, "post_get_changelog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentServiceRestInterceptor, "pre_get_changelog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_changelog" + ) as post, + mock.patch.object( + transports.AgentServiceRestInterceptor, "post_get_changelog_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentServiceRestInterceptor, "pre_get_changelog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42648,8 +42791,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42708,8 +42852,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42770,8 +42915,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42832,8 +42978,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42894,8 +43041,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42956,8 +43104,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -44166,11 +44315,14 @@ def test_agent_service_base_transport(): def test_agent_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1beta.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1beta.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentServiceTransport( @@ -44190,9 +44342,12 @@ def test_agent_service_base_transport_with_credentials_file(): def test_agent_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1beta.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1beta.services.agent_service.transports.AgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentServiceTransport() @@ -44270,11 +44425,12 @@ def test_agent_service_transport_auth_gdch_credentials(transport_class): def test_agent_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -45466,6 +45622,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -45605,6 +45793,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -45750,6 +45970,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -45895,6 +46149,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -46040,6 +46328,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -46181,6 +46503,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_evaluation_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_evaluation_service.py index 43661236ac08..43a5a98d0414 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_evaluation_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_evaluation_service.py @@ -144,6 +144,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EvaluationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -166,6 +167,10 @@ def test__get_default_mtls_endpoint(): EvaluationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EvaluationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1343,11 +1348,13 @@ def test_evaluation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -22121,8 +22128,9 @@ def test_run_evaluation_rest_bad_request(request_type=evaluation.RunEvaluationRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22179,19 +22187,21 @@ def test_run_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_run_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_run_evaluation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_run_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_run_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_run_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_run_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22246,8 +22256,9 @@ def test_upload_evaluation_audio_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22314,18 +22325,20 @@ def test_upload_evaluation_audio_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_upload_evaluation_audio" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_upload_evaluation_audio_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_upload_evaluation_audio" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_upload_evaluation_audio" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_upload_evaluation_audio_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_upload_evaluation_audio" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22383,8 +22396,9 @@ def test_create_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22862,18 +22876,20 @@ def test_create_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_create_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_create_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_create_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_create_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22928,8 +22944,9 @@ def test_generate_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22988,20 +23005,21 @@ def test_generate_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_generate_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_generate_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_generate_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_generate_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_generate_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_generate_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23054,8 +23072,9 @@ def test_import_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23112,20 +23131,21 @@ def test_import_evaluations_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_import_evaluations" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_import_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_import_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_import_evaluations" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_import_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_import_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23178,8 +23198,9 @@ def test_create_evaluation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23362,18 +23383,21 @@ def test_create_evaluation_dataset_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_create_evaluation_dataset" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_evaluation_dataset_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_create_evaluation_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_dataset", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_create_evaluation_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23432,8 +23456,9 @@ def test_update_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23915,18 +23940,20 @@ def test_update_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_update_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_update_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_update_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_update_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_update_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23983,8 +24010,9 @@ def test_update_evaluation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24171,18 +24199,21 @@ def test_update_evaluation_dataset_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_update_evaluation_dataset" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_update_evaluation_dataset_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_update_evaluation_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_evaluation_dataset", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_evaluation_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_update_evaluation_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24239,8 +24270,9 @@ def test_delete_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24299,13 +24331,13 @@ def test_delete_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation" + ) as pre, + ): pre.assert_not_called() pb_message = evaluation_service.DeleteEvaluationRequest.pb( evaluation_service.DeleteEvaluationRequest() @@ -24352,8 +24384,9 @@ def test_delete_evaluation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24412,13 +24445,13 @@ def test_delete_evaluation_result_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_result" + ) as pre, + ): pre.assert_not_called() pb_message = evaluation_service.DeleteEvaluationResultRequest.pb( evaluation_service.DeleteEvaluationResultRequest() @@ -24465,8 +24498,9 @@ def test_delete_evaluation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24525,13 +24559,13 @@ def test_delete_evaluation_dataset_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_dataset" + ) as pre, + ): pre.assert_not_called() pb_message = evaluation_service.DeleteEvaluationDatasetRequest.pb( evaluation_service.DeleteEvaluationDatasetRequest() @@ -24578,8 +24612,9 @@ def test_delete_evaluation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24638,20 +24673,21 @@ def test_delete_evaluation_run_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_delete_evaluation_run" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_delete_evaluation_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_delete_evaluation_run" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_delete_evaluation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24706,8 +24742,9 @@ def test_get_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24790,17 +24827,20 @@ def test_get_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_get_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_get_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24855,8 +24895,9 @@ def test_get_evaluation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24941,18 +24982,20 @@ def test_get_evaluation_result_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_result" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_get_evaluation_result_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_get_evaluation_result" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25009,8 +25052,9 @@ def test_get_evaluation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25085,18 +25129,20 @@ def test_get_evaluation_dataset_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_dataset" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_get_evaluation_dataset_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_get_evaluation_dataset" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25153,8 +25199,9 @@ def test_get_evaluation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25245,18 +25292,20 @@ def test_get_evaluation_run_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_run" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_get_evaluation_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_get_evaluation_run" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25309,8 +25358,9 @@ def test_list_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25373,18 +25423,20 @@ def test_list_evaluations_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluations" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluations" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25444,8 +25496,9 @@ def test_list_evaluation_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25510,18 +25563,20 @@ def test_list_evaluation_results_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluation_results" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluation_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluation_results" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25579,8 +25634,9 @@ def test_list_evaluation_datasets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25645,18 +25701,20 @@ def test_list_evaluation_datasets_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluation_datasets" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluation_datasets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_datasets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluation_datasets" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_datasets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_datasets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25714,8 +25772,9 @@ def test_list_evaluation_runs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25778,18 +25837,20 @@ def test_list_evaluation_runs_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluation_runs" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluation_runs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluation_runs" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_runs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_runs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25847,8 +25908,9 @@ def test_list_evaluation_expectations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25913,18 +25975,22 @@ def test_list_evaluation_expectations_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluation_expectations" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluation_expectations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_expectations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_expectations", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_expectations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_list_evaluation_expectations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25984,8 +26050,9 @@ def test_get_evaluation_expectation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26056,18 +26123,22 @@ def test_get_evaluation_expectation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_expectation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_get_evaluation_expectation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation_expectation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_expectation", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_expectation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_get_evaluation_expectation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26122,8 +26193,9 @@ def test_create_evaluation_expectation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26272,19 +26344,22 @@ def test_create_evaluation_expectation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_evaluation_expectation", - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_evaluation_expectation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_create_evaluation_expectation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_expectation", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_expectation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_create_evaluation_expectation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26343,8 +26418,9 @@ def test_update_evaluation_expectation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26497,19 +26573,22 @@ def test_update_evaluation_expectation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_update_evaluation_expectation", - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_update_evaluation_expectation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_update_evaluation_expectation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_evaluation_expectation", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_evaluation_expectation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_update_evaluation_expectation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26566,8 +26645,9 @@ def test_delete_evaluation_expectation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26626,13 +26706,14 @@ def test_delete_evaluation_expectation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_delete_evaluation_expectation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_delete_evaluation_expectation", + ) as pre, + ): pre.assert_not_called() pb_message = evaluation_service.DeleteEvaluationExpectationRequest.pb( evaluation_service.DeleteEvaluationExpectationRequest() @@ -26677,8 +26758,9 @@ def test_create_scheduled_evaluation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26878,20 +26960,22 @@ def test_create_scheduled_evaluation_run_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_scheduled_evaluation_run", - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_scheduled_evaluation_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "pre_create_scheduled_evaluation_run", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_scheduled_evaluation_run", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_scheduled_evaluation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_create_scheduled_evaluation_run", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26948,8 +27032,9 @@ def test_get_scheduled_evaluation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27030,18 +27115,22 @@ def test_get_scheduled_evaluation_run_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_scheduled_evaluation_run" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_get_scheduled_evaluation_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_scheduled_evaluation_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_scheduled_evaluation_run", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_scheduled_evaluation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_get_scheduled_evaluation_run", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27096,8 +27185,9 @@ def test_list_scheduled_evaluation_runs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27162,20 +27252,22 @@ def test_list_scheduled_evaluation_runs_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_scheduled_evaluation_runs", - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_scheduled_evaluation_runs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "pre_list_scheduled_evaluation_runs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_scheduled_evaluation_runs", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_scheduled_evaluation_runs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_list_scheduled_evaluation_runs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27237,8 +27329,9 @@ def test_update_scheduled_evaluation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27442,20 +27535,22 @@ def test_update_scheduled_evaluation_run_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_update_scheduled_evaluation_run", - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_update_scheduled_evaluation_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "pre_update_scheduled_evaluation_run", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_scheduled_evaluation_run", + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_update_scheduled_evaluation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_update_scheduled_evaluation_run", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27512,8 +27607,9 @@ def test_delete_scheduled_evaluation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27572,14 +27668,14 @@ def test_delete_scheduled_evaluation_run_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "pre_delete_scheduled_evaluation_run", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "pre_delete_scheduled_evaluation_run", + ) as pre, + ): pre.assert_not_called() pb_message = evaluation_service.DeleteScheduledEvaluationRunRequest.pb( evaluation_service.DeleteScheduledEvaluationRunRequest() @@ -27624,8 +27720,9 @@ def test_test_persona_voice_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27688,18 +27785,20 @@ def test_test_persona_voice_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_test_persona_voice" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_test_persona_voice_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_test_persona_voice" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_test_persona_voice" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_test_persona_voice_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_test_persona_voice" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27757,8 +27856,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27817,8 +27917,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27879,8 +27980,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27941,8 +28043,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28003,8 +28106,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28065,8 +28169,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28908,11 +29013,14 @@ def test_evaluation_service_base_transport(): def test_evaluation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EvaluationServiceTransport( @@ -28932,9 +29040,12 @@ def test_evaluation_service_base_transport_with_credentials_file(): def test_evaluation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EvaluationServiceTransport() @@ -29012,11 +29123,12 @@ def test_evaluation_service_transport_auth_gdch_credentials(transport_class): def test_evaluation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -30102,6 +30214,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30241,6 +30385,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30386,6 +30562,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30531,6 +30741,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30676,6 +30920,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30817,6 +31095,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_session_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_session_service.py index ccf11e6ffc6b..850c393b51b9 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_session_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_session_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( SessionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1283,11 +1288,13 @@ def test_session_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2029,8 +2036,9 @@ def test_run_session_rest_bad_request(request_type=session_service.RunSessionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2094,17 +2102,19 @@ def test_run_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_run_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_run_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_run_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_run_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_run_session_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_run_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2171,8 +2181,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2231,8 +2242,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2293,8 +2305,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2355,8 +2368,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2417,8 +2431,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2479,8 +2494,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2615,11 +2631,14 @@ def test_session_service_base_transport(): def test_session_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport( @@ -2639,9 +2658,12 @@ def test_session_service_base_transport_with_credentials_file(): def test_session_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport() @@ -2719,11 +2741,12 @@ def test_session_service_transport_auth_gdch_credentials(transport_class): def test_session_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3386,6 +3409,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3525,6 +3580,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3670,6 +3757,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3815,6 +3936,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3960,6 +4115,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4101,6 +4290,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_tool_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_tool_service.py index f01fcd3235a8..2534769e89e0 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_tool_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_tool_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ToolServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ToolServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ToolServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1245,11 +1249,13 @@ def test_tool_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2646,8 +2652,9 @@ def test_execute_tool_rest_bad_request(request_type=tool_service.ExecuteToolRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2709,17 +2716,19 @@ def test_execute_tool_rest_interceptors(null_interceptor): ) client = ToolServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_execute_tool" - ) as post, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_execute_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolServiceRestInterceptor, "pre_execute_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_execute_tool" + ) as post, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_execute_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolServiceRestInterceptor, "pre_execute_tool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2774,8 +2783,9 @@ def test_retrieve_tool_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2837,17 +2847,20 @@ def test_retrieve_tool_schema_rest_interceptors(null_interceptor): ) client = ToolServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tool_schema" - ) as post, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tool_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolServiceRestInterceptor, "pre_retrieve_tool_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_retrieve_tool_schema" + ) as post, + mock.patch.object( + transports.ToolServiceRestInterceptor, + "post_retrieve_tool_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ToolServiceRestInterceptor, "pre_retrieve_tool_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2907,8 +2920,9 @@ def test_retrieve_tools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2970,17 +2984,19 @@ def test_retrieve_tools_rest_interceptors(null_interceptor): ) client = ToolServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tools" - ) as post, mock.patch.object( - transports.ToolServiceRestInterceptor, "post_retrieve_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolServiceRestInterceptor, "pre_retrieve_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_retrieve_tools" + ) as post, + mock.patch.object( + transports.ToolServiceRestInterceptor, "post_retrieve_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolServiceRestInterceptor, "pre_retrieve_tools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3035,8 +3051,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3095,8 +3112,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3157,8 +3175,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3219,8 +3238,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3281,8 +3301,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3343,8 +3364,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3522,11 +3544,14 @@ def test_tool_service_base_transport(): def test_tool_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1beta.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1beta.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolServiceTransport( @@ -3546,9 +3571,12 @@ def test_tool_service_base_transport_with_credentials_file(): def test_tool_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1beta.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1beta.services.tool_service.transports.ToolServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolServiceTransport() @@ -3626,11 +3654,12 @@ def test_tool_service_transport_auth_gdch_credentials(transport_class): def test_tool_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4335,6 +4364,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4474,6 +4535,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4619,6 +4712,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4764,6 +4891,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4909,6 +5070,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5050,6 +5245,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ToolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ToolServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ToolServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_widget_service.py b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_widget_service.py index 1042d35bb4c3..c1be686b1043 100644 --- a/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_widget_service.py +++ b/packages/google-cloud-ces/tests/unit/gapic/ces_v1beta/test_widget_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WidgetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( WidgetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + WidgetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1278,11 +1283,13 @@ def test_widget_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1896,8 +1903,9 @@ def test_generate_chat_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1962,18 +1970,20 @@ def test_generate_chat_token_rest_interceptors(null_interceptor): ) client = WidgetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WidgetServiceRestInterceptor, "post_generate_chat_token" - ) as post, mock.patch.object( - transports.WidgetServiceRestInterceptor, - "post_generate_chat_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WidgetServiceRestInterceptor, "pre_generate_chat_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WidgetServiceRestInterceptor, "post_generate_chat_token" + ) as post, + mock.patch.object( + transports.WidgetServiceRestInterceptor, + "post_generate_chat_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WidgetServiceRestInterceptor, "pre_generate_chat_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2031,8 +2041,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2091,8 +2102,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2153,8 +2165,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2215,8 +2228,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2277,8 +2291,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2339,8 +2354,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2476,11 +2492,14 @@ def test_widget_service_base_transport(): def test_widget_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ces_v1beta.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ces_v1beta.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WidgetServiceTransport( @@ -2500,9 +2519,12 @@ def test_widget_service_base_transport_with_credentials_file(): def test_widget_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ces_v1beta.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ces_v1beta.services.widget_service.transports.WidgetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WidgetServiceTransport() @@ -2580,11 +2602,12 @@ def test_widget_service_transport_auth_gdch_credentials(transport_class): def test_widget_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3180,6 +3203,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3319,6 +3374,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3464,6 +3551,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3609,6 +3730,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3754,6 +3909,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3895,6 +4084,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = WidgetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = WidgetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = WidgetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/async_client.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/async_client.py index 11fed93866d8..3448c260daf3 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/async_client.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/async_client.py @@ -217,7 +217,7 @@ def transport(self) -> CloudChannelReportsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -747,7 +747,7 @@ async def sample_list_reports(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -773,8 +773,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -783,7 +787,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -791,7 +795,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -802,7 +806,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -828,8 +832,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -838,7 +846,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -846,7 +854,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -857,7 +865,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -887,8 +895,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -897,7 +909,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -905,7 +917,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -913,7 +925,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -942,8 +954,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -952,7 +968,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -960,7 +976,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/client.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/client.py index b9f21f1ae9a9..c503a12d3190 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/client.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/client.py @@ -120,7 +120,7 @@ class CloudChannelReportsServiceClient(metaclass=CloudChannelReportsServiceClien """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = CloudChannelReportsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1180,7 +1184,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1206,8 +1210,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1216,7 +1224,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1225,7 +1233,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1239,7 +1247,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1265,8 +1273,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1275,7 +1287,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1284,7 +1296,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1298,7 +1310,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1328,8 +1340,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1338,7 +1354,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1346,7 +1362,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1354,7 +1370,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1383,8 +1399,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1393,7 +1413,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1401,7 +1421,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/README.rst b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/README.rst index d37386217265..491909f0dda8 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/README.rst +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudChannelReportsServiceTransport` is the ABC for all transports. -- public child `CloudChannelReportsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudChannelReportsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudChannelReportsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudChannelReportsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudChannelReportsServiceTransport`` is the ABC for all transports. + +- public child ``CloudChannelReportsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudChannelReportsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudChannelReportsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudChannelReportsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/base.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/base.py index a68e908dd7ce..7106b47c7145 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/base.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc.py index 6ad65e05702a..372dea963f4c 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc_asyncio.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc_asyncio.py index db9820124ef7..6b7ce0652bbf 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_reports_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/async_client.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/async_client.py index be35fbe5dfa1..7a0d9fc02a1a 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/async_client.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/async_client.py @@ -264,7 +264,7 @@ def transport(self) -> CloudChannelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -6529,7 +6529,7 @@ async def sample_list_entitlement_changes(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6555,8 +6555,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6565,7 +6569,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6573,7 +6577,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6584,7 +6588,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6610,8 +6614,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6620,7 +6628,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6628,7 +6636,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6639,7 +6647,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6669,8 +6677,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6679,7 +6691,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6687,7 +6699,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6695,7 +6707,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6724,8 +6736,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6734,7 +6750,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6742,7 +6758,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/client.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/client.py index e69c2d33b88b..13b3ebe781bd 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/client.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/client.py @@ -148,7 +148,7 @@ class CloudChannelServiceClient(metaclass=CloudChannelServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -156,7 +156,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -166,6 +166,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -657,7 +661,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -754,7 +758,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -854,7 +858,7 @@ def __init__( self._universe_domain = CloudChannelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -7042,7 +7046,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7068,8 +7072,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7078,7 +7086,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7087,7 +7095,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7101,7 +7109,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7127,8 +7135,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7137,7 +7149,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7146,7 +7158,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7160,7 +7172,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7190,8 +7202,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7200,7 +7216,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7208,7 +7224,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7216,7 +7232,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7245,8 +7261,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7255,7 +7275,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7263,7 +7283,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/README.rst b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/README.rst index e12cdd1d8a54..0ef0140ecd98 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/README.rst +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudChannelServiceTransport` is the ABC for all transports. -- public child `CloudChannelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudChannelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudChannelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudChannelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudChannelServiceTransport`` is the ABC for all transports. + +- public child ``CloudChannelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudChannelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudChannelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudChannelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py index 530fb094dc72..6473a6cf3edf 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py index 788c03bdba83..6e220899006f 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -215,6 +215,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py index ac0774aedb87..d9102fd137d6 100644 --- a/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-channel/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -266,6 +266,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-channel/noxfile.py b/packages/google-cloud-channel/noxfile.py index d83d10750124..00e0365a513e 100644 --- a/packages/google-cloud-channel/noxfile.py +++ b/packages/google-cloud-channel/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-channel/setup.py b/packages/google-cloud-channel/setup.py index cfe4b7f8d2d1..34ec687f60ca 100644 --- a/packages/google-cloud-channel/setup.py +++ b/packages/google-cloud-channel/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-channel" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-channel/testing/constraints-3.7.txt b/packages/google-cloud-channel/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-channel/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-channel/testing/constraints-3.8.txt b/packages/google-cloud-channel/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-channel/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-channel/testing/constraints-3.9.txt b/packages/google-cloud-channel/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-channel/testing/constraints-3.9.txt +++ b/packages/google-cloud-channel/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_reports_service.py b/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_reports_service.py index 706738b68ada..d7abb4c044f7 100644 --- a/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_reports_service.py +++ b/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_reports_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudChannelReportsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): CloudChannelReportsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudChannelReportsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1336,11 +1341,13 @@ def test_cloud_channel_reports_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3009,11 +3016,14 @@ def test_cloud_channel_reports_service_base_transport(): def test_cloud_channel_reports_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.channel_v1.services.cloud_channel_reports_service.transports.CloudChannelReportsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.channel_v1.services.cloud_channel_reports_service.transports.CloudChannelReportsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudChannelReportsServiceTransport( @@ -3032,9 +3042,12 @@ def test_cloud_channel_reports_service_base_transport_with_credentials_file(): def test_cloud_channel_reports_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.channel_v1.services.cloud_channel_reports_service.transports.CloudChannelReportsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.channel_v1.services.cloud_channel_reports_service.transports.CloudChannelReportsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudChannelReportsServiceTransport() @@ -3111,11 +3124,12 @@ def test_cloud_channel_reports_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3695,6 +3709,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CloudChannelReportsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudChannelReportsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CloudChannelReportsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3834,6 +3880,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CloudChannelReportsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudChannelReportsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CloudChannelReportsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3979,6 +4057,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudChannelReportsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudChannelReportsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudChannelReportsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4124,6 +4236,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudChannelReportsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudChannelReportsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CloudChannelReportsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_service.py b/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_service.py index 9c8a24eb202c..10b9646fdd4d 100644 --- a/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_service.py +++ b/packages/google-cloud-channel/tests/unit/gapic/channel_v1/test_cloud_channel_service.py @@ -139,6 +139,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudChannelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +162,10 @@ def test__get_default_mtls_endpoint(): CloudChannelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudChannelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1320,11 +1325,13 @@ def test_cloud_channel_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -21246,11 +21253,14 @@ def test_cloud_channel_service_base_transport(): def test_cloud_channel_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.channel_v1.services.cloud_channel_service.transports.CloudChannelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.channel_v1.services.cloud_channel_service.transports.CloudChannelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudChannelServiceTransport( @@ -21267,9 +21277,12 @@ def test_cloud_channel_service_base_transport_with_credentials_file(): def test_cloud_channel_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.channel_v1.services.cloud_channel_service.transports.CloudChannelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.channel_v1.services.cloud_channel_service.transports.CloudChannelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudChannelServiceTransport() @@ -21340,11 +21353,12 @@ def test_cloud_channel_service_transport_auth_gdch_credentials(transport_class): def test_cloud_channel_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -22138,6 +22152,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudChannelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CloudChannelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22277,6 +22323,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudChannelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CloudChannelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22422,6 +22500,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudChannelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudChannelServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22567,6 +22679,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudChannelServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CloudChannelServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/async_client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/async_client.py index f4e8e3e38e0b..1128c52386a1 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/async_client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> DataAccessControlServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1591,7 +1591,7 @@ async def sample_delete_data_access_scope(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1617,8 +1617,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1627,7 +1631,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1635,7 +1639,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1646,7 +1650,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1672,8 +1676,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1682,7 +1690,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1690,7 +1698,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1701,7 +1709,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1731,8 +1739,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1741,7 +1753,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1749,7 +1761,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1757,7 +1769,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1786,8 +1798,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1796,7 +1812,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1804,7 +1820,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/client.py index 5f86d5e292c0..0cbf77011760 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/client.py @@ -116,7 +116,7 @@ class DataAccessControlServiceClient(metaclass=DataAccessControlServiceClientMet """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -566,7 +570,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -668,7 +672,7 @@ def __init__( self._universe_domain = DataAccessControlServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2015,7 +2019,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2041,8 +2045,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2051,7 +2059,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2060,7 +2068,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2074,7 +2082,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2100,8 +2108,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2110,7 +2122,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2119,7 +2131,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2133,7 +2145,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2163,8 +2175,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2173,7 +2189,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2181,7 +2197,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2189,7 +2205,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2218,8 +2234,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2228,7 +2248,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2236,7 +2256,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/README.rst b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/README.rst index 9c992e6e8fc7..4b9ae87209aa 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/README.rst +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataAccessControlServiceTransport` is the ABC for all transports. -- public child `DataAccessControlServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataAccessControlServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataAccessControlServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataAccessControlServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataAccessControlServiceTransport`` is the ABC for all transports. + +- public child ``DataAccessControlServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataAccessControlServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataAccessControlServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataAccessControlServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/base.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/base.py index 4e3f631edd04..5faa6275ca40 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/base.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc.py index 254c494f03bc..904990ae9485 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc_asyncio.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc_asyncio.py index 72e806f45951..beff9a781bbc 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/rest.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/rest.py index eeeb89ba9386..165831b2e90b 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/rest.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/data_access_control_service/transports/rest.py @@ -756,6 +756,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataAccessControlServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/async_client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/async_client.py index ac1b6a70f41b..1b4b5839ebe9 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/async_client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> EntityServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -924,7 +924,7 @@ async def sample_delete_watchlist(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -950,8 +950,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -960,7 +964,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -968,7 +972,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -979,7 +983,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1005,8 +1009,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1015,7 +1023,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1023,7 +1031,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1034,7 +1042,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1064,8 +1072,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1074,7 +1086,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1082,7 +1094,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1090,7 +1102,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1119,8 +1131,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1129,7 +1145,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1137,7 +1153,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/client.py index d16afa81e708..c07de7fe3bbf 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/client.py @@ -114,7 +114,7 @@ class EntityServiceClient(metaclass=EntityServiceClientMeta): """EntityService contains apis for finding entities.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = EntityServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1354,7 +1358,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1380,8 +1384,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1390,7 +1398,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1399,7 +1407,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1413,7 +1421,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1439,8 +1447,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1449,7 +1461,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1458,7 +1470,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1472,7 +1484,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1502,8 +1514,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1512,7 +1528,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1520,7 +1536,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1528,7 +1544,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1557,8 +1573,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1567,7 +1587,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1575,7 +1595,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/README.rst b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/README.rst index 0a066d188086..b5a417752656 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/README.rst +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EntityServiceTransport` is the ABC for all transports. -- public child `EntityServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EntityServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEntityServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EntityServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EntityServiceTransport`` is the ABC for all transports. + +- public child ``EntityServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EntityServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEntityServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EntityServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/base.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/base.py index ad4e07823be3..4115a94a4048 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/base.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc.py index acaf5dcf3575..d3e624e07b5c 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc_asyncio.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc_asyncio.py index cccde9e213e0..44fb4627930c 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/rest.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/rest.py index a9abe4a6a192..9aa390b724ba 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/rest.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/entity_service/transports/rest.py @@ -469,6 +469,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EntityServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/async_client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/async_client.py index 4af1dfba2eed..905434c166d4 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/async_client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> InstanceServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -411,7 +411,7 @@ async def sample_get_instance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -437,8 +437,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -447,7 +451,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -455,7 +459,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -466,7 +470,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -492,8 +496,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -502,7 +510,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -510,7 +518,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -521,7 +529,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -551,8 +559,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -561,7 +573,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -569,7 +581,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -577,7 +589,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -606,8 +618,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -616,7 +632,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -624,7 +640,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/client.py index 459aa599fc4a..6a382e9e7747 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/client.py @@ -113,7 +113,7 @@ class InstanceServiceClient(metaclass=InstanceServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -438,7 +442,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -535,7 +539,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -633,7 +637,7 @@ def __init__( self._universe_domain = InstanceServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -851,7 +855,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -877,8 +881,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -887,7 +895,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -896,7 +904,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -910,7 +918,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -936,8 +944,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -946,7 +958,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -955,7 +967,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -969,7 +981,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -999,8 +1011,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1009,7 +1025,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1017,7 +1033,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1025,7 +1041,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1070,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1084,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1072,7 +1092,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/README.rst b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/README.rst index 2f954fd1f8fe..1cf26382bc44 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/README.rst +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceServiceTransport` is the ABC for all transports. -- public child `InstanceServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceServiceTransport`` is the ABC for all transports. + +- public child ``InstanceServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/base.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/base.py index f9aaf3982ff8..b257b5b0a745 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/base.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc.py index fa53ff6db62e..f5415bd4d216 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc_asyncio.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc_asyncio.py index 5ad003b8b197..d391a3f7030d 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/rest.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/rest.py index e27467ec92a7..eac3fcd8ca82 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/rest.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/instance_service/transports/rest.py @@ -295,6 +295,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/async_client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/async_client.py index 62f34217416a..423136ff2d90 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/async_client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> ReferenceListServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -838,7 +838,7 @@ async def sample_update_reference_list(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -864,8 +864,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -874,7 +878,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -882,7 +886,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -893,7 +897,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -919,8 +923,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -929,7 +937,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -937,7 +945,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -948,7 +956,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -978,8 +986,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -988,7 +1000,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -996,7 +1008,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1004,7 +1016,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1033,8 +1045,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1043,7 +1059,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1051,7 +1067,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/client.py index bdffa01e29d2..314cfdd5b965 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/client.py @@ -117,7 +117,7 @@ class ReferenceListServiceClient(metaclass=ReferenceListServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -641,7 +645,7 @@ def __init__( self._universe_domain = ReferenceListServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1268,7 +1272,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1294,8 +1298,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1304,7 +1312,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1313,7 +1321,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1327,7 +1335,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1353,8 +1361,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1363,7 +1375,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1372,7 +1384,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1386,7 +1398,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1416,8 +1428,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1426,7 +1442,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1434,7 +1450,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1442,7 +1458,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1471,8 +1487,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1481,7 +1501,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1489,7 +1509,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/README.rst b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/README.rst index 370ddab05f83..c070cabda974 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/README.rst +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReferenceListServiceTransport` is the ABC for all transports. -- public child `ReferenceListServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReferenceListServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReferenceListServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReferenceListServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReferenceListServiceTransport`` is the ABC for all transports. + +- public child ``ReferenceListServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReferenceListServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReferenceListServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReferenceListServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/base.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/base.py index a3f5aaf69794..82ef0d9f5776 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/base.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc.py index 79f266ee2179..8341e7e990bb 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc_asyncio.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc_asyncio.py index db9d4c4c0cab..511ee7c7007e 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/rest.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/rest.py index be673689e286..d206b72be9e8 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/rest.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/reference_list_service/transports/rest.py @@ -478,6 +478,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReferenceListServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/async_client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/async_client.py index a06600a8c7a8..457040d38b04 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/async_client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> RuleServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1772,7 +1772,7 @@ async def sample_update_rule_deployment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1798,8 +1798,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1808,7 +1812,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1816,7 +1820,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1827,7 +1831,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1853,8 +1857,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1863,7 +1871,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1871,7 +1879,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1882,7 +1890,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1912,8 +1920,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1922,7 +1934,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1930,7 +1942,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1938,7 +1950,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1967,8 +1979,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1977,7 +1993,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1985,7 +2001,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/client.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/client.py index 497d3842d96e..605b9c22b2b6 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/client.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/client.py @@ -118,7 +118,7 @@ class RuleServiceClient(metaclass=RuleServiceClientMeta): """RuleService provides interface for user-created rules.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -543,7 +547,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -640,7 +644,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -736,7 +740,7 @@ def __init__( self._universe_domain = RuleServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2268,7 +2272,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2294,8 +2298,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2304,7 +2312,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2313,7 +2321,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2327,7 +2335,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2353,8 +2361,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2363,7 +2375,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2372,7 +2384,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2386,7 +2398,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2416,8 +2428,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2426,7 +2442,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2434,7 +2450,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2442,7 +2458,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2471,8 +2487,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2481,7 +2501,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2489,7 +2509,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/README.rst b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/README.rst index 27e257c49fc6..72822ff5e04d 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/README.rst +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RuleServiceTransport` is the ABC for all transports. -- public child `RuleServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RuleServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRuleServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RuleServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RuleServiceTransport`` is the ABC for all transports. + +- public child ``RuleServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RuleServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRuleServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RuleServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/base.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/base.py index 94b95e641109..23c2cfe6417b 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/base.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc.py index 71e41a3ec547..4bcce572f009 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc_asyncio.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc_asyncio.py index 6f01668b757e..be477be82aa1 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/rest.py b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/rest.py index 43a7fe435369..ff6e904e2265 100644 --- a/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/rest.py +++ b/packages/google-cloud-chronicle/google/cloud/chronicle_v1/services/rule_service/transports/rest.py @@ -846,6 +846,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RuleServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-chronicle/noxfile.py b/packages/google-cloud-chronicle/noxfile.py index a7fc5ce9572e..bd009118b32c 100644 --- a/packages/google-cloud-chronicle/noxfile.py +++ b/packages/google-cloud-chronicle/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-chronicle/setup.py b/packages/google-cloud-chronicle/setup.py index 40ef00d5d725..8883e03c5de4 100644 --- a/packages/google-cloud-chronicle/setup.py +++ b/packages/google-cloud-chronicle/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-chronicle" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-chronicle/testing/constraints-3.7.txt b/packages/google-cloud-chronicle/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-chronicle/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-chronicle/testing/constraints-3.8.txt b/packages/google-cloud-chronicle/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-chronicle/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-chronicle/testing/constraints-3.9.txt b/packages/google-cloud-chronicle/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-chronicle/testing/constraints-3.9.txt +++ b/packages/google-cloud-chronicle/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_data_access_control_service.py b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_data_access_control_service.py index 1f3297229075..31ecade8bcf3 100644 --- a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_data_access_control_service.py +++ b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_data_access_control_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataAccessControlServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): DataAccessControlServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataAccessControlServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1356,11 +1361,13 @@ def test_data_access_control_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8153,8 +8160,9 @@ def test_create_data_access_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8305,20 +8313,22 @@ def test_create_data_access_label_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_create_data_access_label", - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_create_data_access_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_create_data_access_label", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_create_data_access_label", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_create_data_access_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_create_data_access_label", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8378,8 +8388,9 @@ def test_get_data_access_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8453,18 +8464,22 @@ def test_get_data_access_label_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, "post_get_data_access_label" - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_get_data_access_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, "pre_get_data_access_label" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_get_data_access_label", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_get_data_access_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_get_data_access_label", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8522,8 +8537,9 @@ def test_list_data_access_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8586,20 +8602,22 @@ def test_list_data_access_labels_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_list_data_access_labels", - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_list_data_access_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_list_data_access_labels", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_list_data_access_labels", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_list_data_access_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_list_data_access_labels", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8661,8 +8679,9 @@ def test_update_data_access_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8817,20 +8836,22 @@ def test_update_data_access_label_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_update_data_access_label", - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_update_data_access_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_update_data_access_label", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_update_data_access_label", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_update_data_access_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_update_data_access_label", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8890,8 +8911,9 @@ def test_delete_data_access_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8950,14 +8972,14 @@ def test_delete_data_access_label_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_delete_data_access_label", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_delete_data_access_label", + ) as pre, + ): pre.assert_not_called() pb_message = data_access_control.DeleteDataAccessLabelRequest.pb( data_access_control.DeleteDataAccessLabelRequest() @@ -9002,8 +9024,9 @@ def test_create_data_access_scope_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9168,20 +9191,22 @@ def test_create_data_access_scope_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_create_data_access_scope", - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_create_data_access_scope_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_create_data_access_scope", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_create_data_access_scope", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_create_data_access_scope_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_create_data_access_scope", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9241,8 +9266,9 @@ def test_get_data_access_scope_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9317,18 +9343,22 @@ def test_get_data_access_scope_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, "post_get_data_access_scope" - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_get_data_access_scope_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, "pre_get_data_access_scope" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_get_data_access_scope", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_get_data_access_scope_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_get_data_access_scope", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9386,8 +9416,9 @@ def test_list_data_access_scopes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9452,20 +9483,22 @@ def test_list_data_access_scopes_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_list_data_access_scopes", - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_list_data_access_scopes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_list_data_access_scopes", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_list_data_access_scopes", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_list_data_access_scopes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_list_data_access_scopes", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9527,8 +9560,9 @@ def test_update_data_access_scope_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9697,20 +9731,22 @@ def test_update_data_access_scope_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_update_data_access_scope", - ) as post, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "post_update_data_access_scope_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_update_data_access_scope", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_update_data_access_scope", + ) as post, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "post_update_data_access_scope_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_update_data_access_scope", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9770,8 +9806,9 @@ def test_delete_data_access_scope_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9830,14 +9867,14 @@ def test_delete_data_access_scope_rest_interceptors(null_interceptor): ) client = DataAccessControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAccessControlServiceRestInterceptor, - "pre_delete_data_access_scope", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAccessControlServiceRestInterceptor, + "pre_delete_data_access_scope", + ) as pre, + ): pre.assert_not_called() pb_message = data_access_control.DeleteDataAccessScopeRequest.pb( data_access_control.DeleteDataAccessScopeRequest() @@ -9887,8 +9924,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9954,8 +9992,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10021,8 +10060,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10085,8 +10125,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10427,11 +10468,14 @@ def test_data_access_control_service_base_transport(): def test_data_access_control_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.chronicle_v1.services.data_access_control_service.transports.DataAccessControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.chronicle_v1.services.data_access_control_service.transports.DataAccessControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataAccessControlServiceTransport( @@ -10448,9 +10492,12 @@ def test_data_access_control_service_base_transport_with_credentials_file(): def test_data_access_control_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.chronicle_v1.services.data_access_control_service.transports.DataAccessControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.chronicle_v1.services.data_access_control_service.transports.DataAccessControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataAccessControlServiceTransport() @@ -10524,11 +10571,12 @@ def test_data_access_control_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11156,6 +11204,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataAccessControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataAccessControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataAccessControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11295,6 +11375,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataAccessControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataAccessControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataAccessControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11440,6 +11552,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataAccessControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataAccessControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataAccessControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11585,6 +11731,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataAccessControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataAccessControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DataAccessControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_entity_service.py b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_entity_service.py index 02809183dda4..89dec9f2af54 100644 --- a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_entity_service.py +++ b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_entity_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EntityServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): assert ( EntityServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EntityServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1280,11 +1285,13 @@ def test_entity_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4558,8 +4565,9 @@ def test_get_watchlist_rest_bad_request(request_type=entity.GetWatchlistRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4630,17 +4638,19 @@ def test_get_watchlist_rest_interceptors(null_interceptor): ) client = EntityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_get_watchlist" - ) as post, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_get_watchlist_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityServiceRestInterceptor, "pre_get_watchlist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityServiceRestInterceptor, "post_get_watchlist" + ) as post, + mock.patch.object( + transports.EntityServiceRestInterceptor, "post_get_watchlist_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EntityServiceRestInterceptor, "pre_get_watchlist" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4689,8 +4699,9 @@ def test_list_watchlists_rest_bad_request(request_type=entity.ListWatchlistsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4753,17 +4764,20 @@ def test_list_watchlists_rest_interceptors(null_interceptor): ) client = EntityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_list_watchlists" - ) as post, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_list_watchlists_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityServiceRestInterceptor, "pre_list_watchlists" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityServiceRestInterceptor, "post_list_watchlists" + ) as post, + mock.patch.object( + transports.EntityServiceRestInterceptor, + "post_list_watchlists_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityServiceRestInterceptor, "pre_list_watchlists" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4814,8 +4828,9 @@ def test_create_watchlist_rest_bad_request(request_type=entity.CreateWatchlistRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4962,17 +4977,20 @@ def test_create_watchlist_rest_interceptors(null_interceptor): ) client = EntityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_create_watchlist" - ) as post, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_create_watchlist_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityServiceRestInterceptor, "pre_create_watchlist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityServiceRestInterceptor, "post_create_watchlist" + ) as post, + mock.patch.object( + transports.EntityServiceRestInterceptor, + "post_create_watchlist_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityServiceRestInterceptor, "pre_create_watchlist" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5025,8 +5043,9 @@ def test_update_watchlist_rest_bad_request(request_type=entity.UpdateWatchlistRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5177,17 +5196,20 @@ def test_update_watchlist_rest_interceptors(null_interceptor): ) client = EntityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_update_watchlist" - ) as post, mock.patch.object( - transports.EntityServiceRestInterceptor, "post_update_watchlist_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityServiceRestInterceptor, "pre_update_watchlist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityServiceRestInterceptor, "post_update_watchlist" + ) as post, + mock.patch.object( + transports.EntityServiceRestInterceptor, + "post_update_watchlist_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityServiceRestInterceptor, "pre_update_watchlist" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5238,8 +5260,9 @@ def test_delete_watchlist_rest_bad_request(request_type=entity.DeleteWatchlistRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5298,13 +5321,13 @@ def test_delete_watchlist_rest_interceptors(null_interceptor): ) client = EntityServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityServiceRestInterceptor, "pre_delete_watchlist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityServiceRestInterceptor, "pre_delete_watchlist" + ) as pre, + ): pre.assert_not_called() pb_message = entity.DeleteWatchlistRequest.pb(entity.DeleteWatchlistRequest()) transcode.return_value = { @@ -5352,8 +5375,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5419,8 +5443,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5486,8 +5511,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5550,8 +5576,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5767,11 +5794,14 @@ def test_entity_service_base_transport(): def test_entity_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.chronicle_v1.services.entity_service.transports.EntityServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.chronicle_v1.services.entity_service.transports.EntityServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityServiceTransport( @@ -5788,9 +5818,12 @@ def test_entity_service_base_transport_with_credentials_file(): def test_entity_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.chronicle_v1.services.entity_service.transports.EntityServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.chronicle_v1.services.entity_service.transports.EntityServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityServiceTransport() @@ -5862,11 +5895,12 @@ def test_entity_service_transport_auth_gdch_credentials(transport_class): def test_entity_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6442,6 +6476,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = EntityServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = EntityServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = EntityServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6581,6 +6647,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EntityServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EntityServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EntityServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6726,6 +6824,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EntityServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EntityServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EntityServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6871,6 +7003,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EntityServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EntityServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EntityServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_instance_service.py b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_instance_service.py index fcd77ed55c36..5f961e8009d5 100644 --- a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_instance_service.py +++ b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_instance_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( InstanceServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1305,11 +1310,13 @@ def test_instance_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2011,8 +2018,9 @@ def test_get_instance_rest_bad_request(request_type=instance.GetInstanceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2075,17 +2083,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = InstanceServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceServiceRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.InstanceServiceRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceServiceRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceServiceRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.InstanceServiceRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceServiceRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2141,8 +2151,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2208,8 +2219,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2275,8 +2287,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2339,8 +2352,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2472,11 +2486,14 @@ def test_instance_service_base_transport(): def test_instance_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.chronicle_v1.services.instance_service.transports.InstanceServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.chronicle_v1.services.instance_service.transports.InstanceServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceServiceTransport( @@ -2493,9 +2510,12 @@ def test_instance_service_base_transport_with_credentials_file(): def test_instance_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.chronicle_v1.services.instance_service.transports.InstanceServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.chronicle_v1.services.instance_service.transports.InstanceServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceServiceTransport() @@ -2567,11 +2587,12 @@ def test_instance_service_transport_auth_gdch_credentials(transport_class): def test_instance_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3134,6 +3155,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = InstanceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = InstanceServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = InstanceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3273,6 +3326,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = InstanceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = InstanceServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = InstanceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3418,6 +3503,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = InstanceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = InstanceServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = InstanceServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3563,6 +3682,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = InstanceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = InstanceServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = InstanceServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_reference_list_service.py b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_reference_list_service.py index 38cb9f93667f..24a2773d282e 100644 --- a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_reference_list_service.py +++ b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_reference_list_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReferenceListServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): ReferenceListServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReferenceListServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1345,11 +1350,13 @@ def test_reference_list_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4266,8 +4273,9 @@ def test_get_reference_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4345,18 +4353,20 @@ def test_get_reference_list_rest_interceptors(null_interceptor): ) client = ReferenceListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "post_get_reference_list" - ) as post, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, - "post_get_reference_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "pre_get_reference_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "post_get_reference_list" + ) as post, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, + "post_get_reference_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "pre_get_reference_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4411,8 +4421,9 @@ def test_list_reference_lists_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4475,18 +4486,20 @@ def test_list_reference_lists_rest_interceptors(null_interceptor): ) client = ReferenceListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "post_list_reference_lists" - ) as post, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, - "post_list_reference_lists_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "pre_list_reference_lists" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "post_list_reference_lists" + ) as post, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, + "post_list_reference_lists_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "pre_list_reference_lists" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4544,8 +4557,9 @@ def test_create_reference_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4705,18 +4719,20 @@ def test_create_reference_list_rest_interceptors(null_interceptor): ) client = ReferenceListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "post_create_reference_list" - ) as post, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, - "post_create_reference_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "pre_create_reference_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "post_create_reference_list" + ) as post, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, + "post_create_reference_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "pre_create_reference_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4775,8 +4791,9 @@ def test_update_reference_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4940,18 +4957,20 @@ def test_update_reference_list_rest_interceptors(null_interceptor): ) client = ReferenceListServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "post_update_reference_list" - ) as post, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, - "post_update_reference_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReferenceListServiceRestInterceptor, "pre_update_reference_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "post_update_reference_list" + ) as post, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, + "post_update_reference_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReferenceListServiceRestInterceptor, "pre_update_reference_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5011,8 +5030,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5078,8 +5098,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5145,8 +5166,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5209,8 +5231,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5413,11 +5436,14 @@ def test_reference_list_service_base_transport(): def test_reference_list_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.chronicle_v1.services.reference_list_service.transports.ReferenceListServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.chronicle_v1.services.reference_list_service.transports.ReferenceListServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReferenceListServiceTransport( @@ -5434,9 +5460,12 @@ def test_reference_list_service_base_transport_with_credentials_file(): def test_reference_list_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.chronicle_v1.services.reference_list_service.transports.ReferenceListServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.chronicle_v1.services.reference_list_service.transports.ReferenceListServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReferenceListServiceTransport() @@ -5508,11 +5537,12 @@ def test_reference_list_service_transport_auth_gdch_credentials(transport_class) def test_reference_list_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6091,6 +6121,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ReferenceListServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ReferenceListServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ReferenceListServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6230,6 +6292,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ReferenceListServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ReferenceListServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ReferenceListServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6375,6 +6469,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ReferenceListServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ReferenceListServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ReferenceListServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6520,6 +6648,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ReferenceListServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ReferenceListServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ReferenceListServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_rule_service.py b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_rule_service.py index 620fdf044788..4695c33c2e42 100644 --- a/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_rule_service.py +++ b/packages/google-cloud-chronicle/tests/unit/gapic/chronicle_v1/test_rule_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RuleServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RuleServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RuleServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1253,11 +1257,13 @@ def test_rule_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9520,8 +9526,9 @@ def test_create_rule_rest_bad_request(request_type=gcc_rule.CreateRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9705,17 +9712,19 @@ def test_create_rule_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_create_rule" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_create_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_create_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_create_rule" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_create_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_create_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9766,8 +9775,9 @@ def test_get_rule_rest_bad_request(request_type=rule.GetRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9854,17 +9864,17 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_get_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RuleServiceRestInterceptor, "pre_get_rule") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9913,8 +9923,9 @@ def test_list_rules_rest_bad_request(request_type=rule.ListRulesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9977,17 +9988,19 @@ def test_list_rules_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_rules" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_rules_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_list_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_list_rules" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_list_rules_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_list_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10040,8 +10053,9 @@ def test_update_rule_rest_bad_request(request_type=gcc_rule.UpdateRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10229,17 +10243,19 @@ def test_update_rule_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_update_rule" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_update_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_update_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_update_rule" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_update_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_update_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10290,8 +10306,9 @@ def test_delete_rule_rest_bad_request(request_type=rule.DeleteRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10350,13 +10367,13 @@ def test_delete_rule_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_delete_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_delete_rule" + ) as pre, + ): pre.assert_not_called() pb_message = rule.DeleteRuleRequest.pb(rule.DeleteRuleRequest()) transcode.return_value = { @@ -10401,8 +10418,9 @@ def test_list_rule_revisions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10467,17 +10485,20 @@ def test_list_rule_revisions_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_rule_revisions" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_rule_revisions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_list_rule_revisions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_list_rule_revisions" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, + "post_list_rule_revisions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_list_rule_revisions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10530,8 +10551,9 @@ def test_create_retrohunt_rest_bad_request(request_type=rule.CreateRetrohuntRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10667,19 +10689,20 @@ def test_create_retrohunt_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.RuleServiceRestInterceptor, "post_create_retrohunt" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_create_retrohunt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_create_retrohunt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_create_retrohunt" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_create_retrohunt_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_create_retrohunt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10730,8 +10753,9 @@ def test_get_retrohunt_rest_bad_request(request_type=rule.GetRetrohuntRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10800,17 +10824,19 @@ def test_get_retrohunt_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_get_retrohunt" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_get_retrohunt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_get_retrohunt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_get_retrohunt" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_get_retrohunt_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_get_retrohunt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10861,8 +10887,9 @@ def test_list_retrohunts_rest_bad_request(request_type=rule.ListRetrohuntsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10927,17 +10954,19 @@ def test_list_retrohunts_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_retrohunts" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_retrohunts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_list_retrohunts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_list_retrohunts" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_list_retrohunts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_list_retrohunts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10992,8 +11021,9 @@ def test_get_rule_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11072,17 +11102,20 @@ def test_get_rule_deployment_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_get_rule_deployment" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_get_rule_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_get_rule_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_get_rule_deployment" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, + "post_get_rule_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_get_rule_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11135,8 +11168,9 @@ def test_list_rule_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11201,18 +11235,20 @@ def test_list_rule_deployments_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_list_rule_deployments" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, - "post_list_rule_deployments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_list_rule_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_list_rule_deployments" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, + "post_list_rule_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_list_rule_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11271,8 +11307,9 @@ def test_update_rule_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11432,18 +11469,20 @@ def test_update_rule_deployment_rest_interceptors(null_interceptor): ) client = RuleServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleServiceRestInterceptor, "post_update_rule_deployment" - ) as post, mock.patch.object( - transports.RuleServiceRestInterceptor, - "post_update_rule_deployment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RuleServiceRestInterceptor, "pre_update_rule_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleServiceRestInterceptor, "post_update_rule_deployment" + ) as post, + mock.patch.object( + transports.RuleServiceRestInterceptor, + "post_update_rule_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleServiceRestInterceptor, "pre_update_rule_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11501,8 +11540,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11568,8 +11608,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11635,8 +11676,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11699,8 +11741,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12093,11 +12136,14 @@ def test_rule_service_base_transport(): def test_rule_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.chronicle_v1.services.rule_service.transports.RuleServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.chronicle_v1.services.rule_service.transports.RuleServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RuleServiceTransport( @@ -12114,9 +12160,12 @@ def test_rule_service_base_transport_with_credentials_file(): def test_rule_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.chronicle_v1.services.rule_service.transports.RuleServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.chronicle_v1.services.rule_service.transports.RuleServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RuleServiceTransport() @@ -12188,11 +12237,12 @@ def test_rule_service_transport_auth_gdch_credentials(transport_class): def test_rule_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12939,6 +12989,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = RuleServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = RuleServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = RuleServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13078,6 +13160,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RuleServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RuleServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RuleServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13223,6 +13337,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RuleServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RuleServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RuleServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13368,6 +13516,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RuleServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RuleServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RuleServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/async_client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/async_client.py index b50b097c6529..3c3e96677f36 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/async_client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/async_client.py @@ -234,7 +234,7 @@ def transport(self) -> CloudControlsPartnerCoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/client.py index 2c1af5775759..308a587840d4 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/client.py @@ -121,7 +121,7 @@ class CloudControlsPartnerCoreClient(metaclass=CloudControlsPartnerCoreClientMet """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -564,7 +568,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -663,7 +667,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -765,7 +769,7 @@ def __init__( self._universe_domain = CloudControlsPartnerCoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/README.rst b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/README.rst index 2e8fff6f526c..7215e726e699 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/README.rst +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudControlsPartnerCoreTransport` is the ABC for all transports. -- public child `CloudControlsPartnerCoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudControlsPartnerCoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudControlsPartnerCoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudControlsPartnerCoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudControlsPartnerCoreTransport`` is the ABC for all transports. + +- public child ``CloudControlsPartnerCoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudControlsPartnerCoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudControlsPartnerCoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudControlsPartnerCoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/base.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/base.py index 28b243ecc164..bb7bbe3fa6c1 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/base.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc.py index ea5bc98c2bbe..0d7ee1cd43bc 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc_asyncio.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc_asyncio.py index 936173fa0180..1591ca26a152 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/rest.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/rest.py index 38fb53b700b6..50678e3e5d1e 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/rest.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/rest.py @@ -730,6 +730,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudControlsPartnerCoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/async_client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/async_client.py index f188350205e2..84c4384a98d1 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/async_client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/async_client.py @@ -208,7 +208,7 @@ def transport(self) -> CloudControlsPartnerMonitoringTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/client.py index 464e67d53ec6..04b7cbad14f4 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/client.py @@ -120,7 +120,7 @@ class CloudControlsPartnerMonitoringClient( """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -453,7 +457,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -552,7 +556,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -656,7 +660,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/README.rst b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/README.rst index e47faec625c3..148cfe8b2e93 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/README.rst +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudControlsPartnerMonitoringTransport` is the ABC for all transports. -- public child `CloudControlsPartnerMonitoringGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudControlsPartnerMonitoringGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudControlsPartnerMonitoringRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudControlsPartnerMonitoringRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudControlsPartnerMonitoringTransport`` is the ABC for all transports. + +- public child ``CloudControlsPartnerMonitoringGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudControlsPartnerMonitoringGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudControlsPartnerMonitoringRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudControlsPartnerMonitoringRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/base.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/base.py index d132da0a21cc..e966eb90ff18 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/base.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc.py index b3c2aa0643f5..acafe631e15d 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py index 4ae8471f554e..765f3de2bdc4 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/rest.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/rest.py index 80beea881acb..be6f32dec2f1 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/rest.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/rest.py @@ -259,6 +259,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudControlsPartnerMonitoringRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/async_client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/async_client.py index 5fa9d69911bb..7c3572e6a9b3 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/async_client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/async_client.py @@ -234,7 +234,7 @@ def transport(self) -> CloudControlsPartnerCoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/client.py index 99df982544ab..d76900a29ccc 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/client.py @@ -121,7 +121,7 @@ class CloudControlsPartnerCoreClient(metaclass=CloudControlsPartnerCoreClientMet """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -564,7 +568,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -663,7 +667,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -765,7 +769,7 @@ def __init__( self._universe_domain = CloudControlsPartnerCoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/README.rst b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/README.rst index 2e8fff6f526c..7215e726e699 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/README.rst +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudControlsPartnerCoreTransport` is the ABC for all transports. -- public child `CloudControlsPartnerCoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudControlsPartnerCoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudControlsPartnerCoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudControlsPartnerCoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudControlsPartnerCoreTransport`` is the ABC for all transports. + +- public child ``CloudControlsPartnerCoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudControlsPartnerCoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudControlsPartnerCoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudControlsPartnerCoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/base.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/base.py index aaee1524e8a4..2a332c3c008e 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/base.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc.py index ec73460e8b8c..97eb9db5c834 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc_asyncio.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc_asyncio.py index 46428aeb36a6..c42a517e1cfc 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/rest.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/rest.py index 7631542f2a9d..ad7352068d71 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/rest.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/rest.py @@ -730,6 +730,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudControlsPartnerCoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/async_client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/async_client.py index cb727541ff34..e9e0361b4828 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/async_client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/async_client.py @@ -208,7 +208,7 @@ def transport(self) -> CloudControlsPartnerMonitoringTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/client.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/client.py index 16b12d6e5745..4adbb2f23fc9 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/client.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/client.py @@ -120,7 +120,7 @@ class CloudControlsPartnerMonitoringClient( """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -453,7 +457,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -552,7 +556,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -656,7 +660,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/README.rst b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/README.rst index e47faec625c3..148cfe8b2e93 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/README.rst +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudControlsPartnerMonitoringTransport` is the ABC for all transports. -- public child `CloudControlsPartnerMonitoringGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudControlsPartnerMonitoringGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudControlsPartnerMonitoringRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudControlsPartnerMonitoringRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudControlsPartnerMonitoringTransport`` is the ABC for all transports. + +- public child ``CloudControlsPartnerMonitoringGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudControlsPartnerMonitoringGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudControlsPartnerMonitoringRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudControlsPartnerMonitoringRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/base.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/base.py index 43c836078926..f71ce8309106 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/base.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc.py index 76b17116f731..2ba4d8ed77ea 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py index 4d382f41e2c2..d2726f7c7360 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/rest.py b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/rest.py index 1da4a7e933c6..e60009bc3b6e 100644 --- a/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/rest.py +++ b/packages/google-cloud-cloudcontrolspartner/google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/rest.py @@ -259,6 +259,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudControlsPartnerMonitoringRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudcontrolspartner/noxfile.py b/packages/google-cloud-cloudcontrolspartner/noxfile.py index 0094d85f10a7..68de2a6a37b2 100644 --- a/packages/google-cloud-cloudcontrolspartner/noxfile.py +++ b/packages/google-cloud-cloudcontrolspartner/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-cloudcontrolspartner/setup.py b/packages/google-cloud-cloudcontrolspartner/setup.py index 70f148b6f7e2..d8dd6adeab7d 100644 --- a/packages/google-cloud-cloudcontrolspartner/setup.py +++ b/packages/google-cloud-cloudcontrolspartner/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-cloudcontrolspartner" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.7.txt b/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.8.txt b/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.9.txt b/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.9.txt +++ b/packages/google-cloud-cloudcontrolspartner/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_core.py b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_core.py index 8fb03fa54cf9..d37af8b73040 100644 --- a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_core.py +++ b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_core.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudControlsPartnerCoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): CloudControlsPartnerCoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudControlsPartnerCoreClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1362,11 +1367,13 @@ def test_cloud_controls_partner_core_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8691,8 +8698,9 @@ def test_get_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8772,18 +8780,20 @@ def test_get_workload_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_workload" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_get_workload" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8840,8 +8850,9 @@ def test_list_workloads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8908,18 +8919,20 @@ def test_list_workloads_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_list_workloads" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_workloads_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_workloads" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_list_workloads" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_workloads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_workloads" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8975,8 +8988,9 @@ def test_get_customer_rest_bad_request(request_type=customers.GetCustomerRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9045,18 +9059,20 @@ def test_get_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_customer" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_customer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_get_customer" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_customer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_customer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9105,8 +9121,9 @@ def test_list_customers_rest_bad_request(request_type=customers.ListCustomersReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9171,18 +9188,20 @@ def test_list_customers_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_list_customers" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_customers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_customers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_list_customers" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_customers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_customers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9237,8 +9256,9 @@ def test_get_ekm_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9303,18 +9323,22 @@ def test_get_ekm_connections_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_ekm_connections" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_ekm_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_ekm_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_ekm_connections", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_ekm_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "pre_get_ekm_connections", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9371,8 +9395,9 @@ def test_get_partner_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9443,20 +9468,22 @@ def test_get_partner_permissions_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_partner_permissions", - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_partner_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "pre_get_partner_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_partner_permissions", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_partner_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "pre_get_partner_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9516,8 +9543,9 @@ def test_list_access_approval_requests_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9586,20 +9614,22 @@ def test_list_access_approval_requests_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_access_approval_requests", - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_access_approval_requests_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "pre_list_access_approval_requests", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_access_approval_requests", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_access_approval_requests_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "pre_list_access_approval_requests", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9659,8 +9689,9 @@ def test_get_partner_rest_bad_request(request_type=partners.GetPartnerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9727,18 +9758,20 @@ def test_get_partner_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_partner" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_partner_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_partner" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_get_partner" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_partner_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_partner" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9787,8 +9820,9 @@ def test_create_customer_rest_bad_request(request_type=customers.CreateCustomerR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9940,18 +9974,20 @@ def test_create_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_create_customer" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_create_customer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_create_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_create_customer" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_create_customer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_create_customer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10006,8 +10042,9 @@ def test_update_customer_rest_bad_request(request_type=customers.UpdateCustomerR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10163,18 +10200,20 @@ def test_update_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_update_customer" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_update_customer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_update_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_update_customer" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_update_customer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_update_customer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10225,8 +10264,9 @@ def test_delete_customer_rest_bad_request(request_type=customers.DeleteCustomerR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10283,13 +10323,13 @@ def test_delete_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_delete_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_delete_customer" + ) as pre, + ): pre.assert_not_called() pb_message = customers.DeleteCustomerRequest.pb( customers.DeleteCustomerRequest() @@ -10619,11 +10659,14 @@ def test_cloud_controls_partner_core_base_transport(): def test_cloud_controls_partner_core_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerCoreTransport( @@ -10640,9 +10683,12 @@ def test_cloud_controls_partner_core_base_transport_with_credentials_file(): def test_cloud_controls_partner_core_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerCoreTransport() @@ -10716,11 +10762,12 @@ def test_cloud_controls_partner_core_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_monitoring.py b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_monitoring.py index 779feac281a4..5e026eca8a8e 100644 --- a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_monitoring.py +++ b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1/test_cloud_controls_partner_monitoring.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudControlsPartnerMonitoringClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): CloudControlsPartnerMonitoringClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudControlsPartnerMonitoringClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1407,11 +1412,13 @@ def test_cloud_controls_partner_monitoring_client_create_channel_credentials_fil ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2989,8 +2996,9 @@ def test_list_violations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3057,18 +3065,22 @@ def test_list_violations_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerMonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "post_list_violations" - ) as post, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, - "post_list_violations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "pre_list_violations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_list_violations", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_list_violations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "pre_list_violations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3123,8 +3135,9 @@ def test_get_violation_rest_bad_request(request_type=violations.GetViolationRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3199,18 +3212,22 @@ def test_get_violation_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerMonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "post_get_violation" - ) as post, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, - "post_get_violation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "pre_get_violation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_get_violation", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_get_violation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "pre_get_violation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3351,11 +3368,14 @@ def test_cloud_controls_partner_monitoring_base_transport(): def test_cloud_controls_partner_monitoring_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerMonitoringTransport( @@ -3372,9 +3392,12 @@ def test_cloud_controls_partner_monitoring_base_transport_with_credentials_file( def test_cloud_controls_partner_monitoring_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerMonitoringTransport() @@ -3453,11 +3476,12 @@ def test_cloud_controls_partner_monitoring_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_core.py b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_core.py index d4c560c92536..dbc1e7e4a769 100644 --- a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_core.py +++ b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_core.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudControlsPartnerCoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): CloudControlsPartnerCoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudControlsPartnerCoreClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1362,11 +1367,13 @@ def test_cloud_controls_partner_core_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8692,8 +8699,9 @@ def test_get_workload_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8773,18 +8781,20 @@ def test_get_workload_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_workload" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_workload_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_workload" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_get_workload" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_workload_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_workload" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8841,8 +8851,9 @@ def test_list_workloads_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8909,18 +8920,20 @@ def test_list_workloads_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_list_workloads" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_workloads_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_workloads" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_list_workloads" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_workloads_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_workloads" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8976,8 +8989,9 @@ def test_get_customer_rest_bad_request(request_type=customers.GetCustomerRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9046,18 +9060,20 @@ def test_get_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_customer" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_customer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_get_customer" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_customer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_customer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9106,8 +9122,9 @@ def test_list_customers_rest_bad_request(request_type=customers.ListCustomersReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9172,18 +9189,20 @@ def test_list_customers_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_list_customers" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_customers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_customers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_list_customers" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_customers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_list_customers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9238,8 +9257,9 @@ def test_get_ekm_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9304,18 +9324,22 @@ def test_get_ekm_connections_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_ekm_connections" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_ekm_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_ekm_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_ekm_connections", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_ekm_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "pre_get_ekm_connections", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9372,8 +9396,9 @@ def test_get_partner_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9444,20 +9469,22 @@ def test_get_partner_permissions_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_partner_permissions", - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_partner_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "pre_get_partner_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_partner_permissions", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_partner_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "pre_get_partner_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9517,8 +9544,9 @@ def test_list_access_approval_requests_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9587,20 +9615,22 @@ def test_list_access_approval_requests_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_access_approval_requests", - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_list_access_approval_requests_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "pre_list_access_approval_requests", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_access_approval_requests", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_list_access_approval_requests_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "pre_list_access_approval_requests", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9660,8 +9690,9 @@ def test_get_partner_rest_bad_request(request_type=partners.GetPartnerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9728,18 +9759,20 @@ def test_get_partner_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_get_partner" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_get_partner_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_partner" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_get_partner" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_get_partner_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_get_partner" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9788,8 +9821,9 @@ def test_create_customer_rest_bad_request(request_type=customers.CreateCustomerR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9941,18 +9975,20 @@ def test_create_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_create_customer" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_create_customer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_create_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_create_customer" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_create_customer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_create_customer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10007,8 +10043,9 @@ def test_update_customer_rest_bad_request(request_type=customers.UpdateCustomerR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10164,18 +10201,20 @@ def test_update_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "post_update_customer" - ) as post, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, - "post_update_customer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_update_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "post_update_customer" + ) as post, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, + "post_update_customer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_update_customer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10226,8 +10265,9 @@ def test_delete_customer_rest_bad_request(request_type=customers.DeleteCustomerR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10284,13 +10324,13 @@ def test_delete_customer_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerCoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerCoreRestInterceptor, "pre_delete_customer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerCoreRestInterceptor, "pre_delete_customer" + ) as pre, + ): pre.assert_not_called() pb_message = customers.DeleteCustomerRequest.pb( customers.DeleteCustomerRequest() @@ -10620,11 +10660,14 @@ def test_cloud_controls_partner_core_base_transport(): def test_cloud_controls_partner_core_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerCoreTransport( @@ -10641,9 +10684,12 @@ def test_cloud_controls_partner_core_base_transport_with_credentials_file(): def test_cloud_controls_partner_core_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_core.transports.CloudControlsPartnerCoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerCoreTransport() @@ -10717,11 +10763,12 @@ def test_cloud_controls_partner_core_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_monitoring.py b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_monitoring.py index 636835f5a80b..9d65509e985b 100644 --- a/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_monitoring.py +++ b/packages/google-cloud-cloudcontrolspartner/tests/unit/gapic/cloudcontrolspartner_v1beta/test_cloud_controls_partner_monitoring.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudControlsPartnerMonitoringClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): CloudControlsPartnerMonitoringClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudControlsPartnerMonitoringClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1407,11 +1412,13 @@ def test_cloud_controls_partner_monitoring_client_create_channel_credentials_fil ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2989,8 +2996,9 @@ def test_list_violations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3057,18 +3065,22 @@ def test_list_violations_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerMonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "post_list_violations" - ) as post, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, - "post_list_violations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "pre_list_violations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_list_violations", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_list_violations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "pre_list_violations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3123,8 +3135,9 @@ def test_get_violation_rest_bad_request(request_type=violations.GetViolationRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3199,18 +3212,22 @@ def test_get_violation_rest_interceptors(null_interceptor): ) client = CloudControlsPartnerMonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "post_get_violation" - ) as post, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, - "post_get_violation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudControlsPartnerMonitoringRestInterceptor, "pre_get_violation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_get_violation", + ) as post, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "post_get_violation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudControlsPartnerMonitoringRestInterceptor, + "pre_get_violation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3351,11 +3368,14 @@ def test_cloud_controls_partner_monitoring_base_transport(): def test_cloud_controls_partner_monitoring_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerMonitoringTransport( @@ -3372,9 +3392,12 @@ def test_cloud_controls_partner_monitoring_base_transport_with_credentials_file( def test_cloud_controls_partner_monitoring_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudcontrolspartner_v1beta.services.cloud_controls_partner_monitoring.transports.CloudControlsPartnerMonitoringTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudControlsPartnerMonitoringTransport() @@ -3453,11 +3476,12 @@ def test_cloud_controls_partner_monitoring_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/async_client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/async_client.py index 75b8619ab0f2..74d9add71c64 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/async_client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> AuditTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -843,7 +843,7 @@ async def sample_get_framework_audit(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -869,8 +869,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -879,7 +883,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -887,7 +891,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -898,7 +902,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -924,8 +928,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -934,7 +942,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -942,7 +950,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -953,7 +961,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -983,8 +991,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -993,7 +1005,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1001,7 +1013,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1009,7 +1021,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1038,8 +1050,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1048,7 +1064,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1056,7 +1072,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1064,7 +1080,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1090,8 +1106,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1100,7 +1120,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1108,7 +1128,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1119,7 +1139,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1145,8 +1165,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1155,7 +1179,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1163,7 +1187,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/client.py index 42fa10554449..4f78f8626c85 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/client.py @@ -115,7 +115,7 @@ class AuditClient(metaclass=AuditClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -561,7 +565,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -657,7 +661,7 @@ def __init__( self._universe_domain = AuditClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1301,7 +1305,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1327,8 +1331,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1337,7 +1345,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1346,7 +1354,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1360,7 +1368,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1386,8 +1394,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1396,7 +1408,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1405,7 +1417,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1419,7 +1431,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1449,8 +1461,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1459,7 +1475,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1467,7 +1483,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1475,7 +1491,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1504,8 +1520,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1514,7 +1534,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1522,7 +1542,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1530,7 +1550,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1556,8 +1576,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1566,7 +1590,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1575,7 +1599,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1589,7 +1613,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1615,8 +1639,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1625,7 +1653,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1634,7 +1662,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/README.rst b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/README.rst index 59f784f5654c..86ab210dc185 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/README.rst +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AuditTransport` is the ABC for all transports. -- public child `AuditGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AuditGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAuditRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AuditRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AuditTransport`` is the ABC for all transports. + +- public child ``AuditGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AuditGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAuditRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AuditRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/base.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/base.py index f33f0e9a19e3..ddc81c5479ef 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/base.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc.py index 8f3dd685a75e..0556341073ca 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc_asyncio.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc_asyncio.py index 17ba0374dfbb..1ac350b3b5e5 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/rest.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/rest.py index 542b16924bd7..046e99ee24ed 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/rest.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/audit/transports/rest.py @@ -521,6 +521,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AuditRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/async_client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/async_client.py index a3c827952747..2da6ffa7fb22 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/async_client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> CmEnrollmentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -563,7 +563,7 @@ async def sample_calculate_effective_cm_enrollment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -589,8 +589,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -599,7 +603,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -607,7 +611,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -618,7 +622,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -644,8 +648,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -654,7 +662,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -662,7 +670,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -673,7 +681,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -703,8 +711,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -713,7 +725,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -721,7 +733,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -729,7 +741,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -758,8 +770,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -768,7 +784,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -776,7 +792,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -784,7 +800,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -810,8 +826,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -820,7 +840,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -828,7 +848,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -839,7 +859,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -865,8 +885,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -875,7 +899,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -883,7 +907,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/client.py index c1d0a12e6d3b..8a98b339b7f4 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/client.py @@ -114,7 +114,7 @@ class CmEnrollmentServiceClient(metaclass=CmEnrollmentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = CmEnrollmentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -997,7 +1001,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1023,8 +1027,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1033,7 +1041,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1042,7 +1050,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1056,7 +1064,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1082,8 +1090,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1092,7 +1104,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1101,7 +1113,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1115,7 +1127,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1145,8 +1157,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1155,7 +1171,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1163,7 +1179,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1171,7 +1187,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1200,8 +1216,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1210,7 +1230,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1218,7 +1238,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1226,7 +1246,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1252,8 +1272,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1262,7 +1286,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1271,7 +1295,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1285,7 +1309,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1311,8 +1335,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1321,7 +1349,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1330,7 +1358,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/README.rst b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/README.rst index fcad50d7316c..a793f97008bd 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/README.rst +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CmEnrollmentServiceTransport` is the ABC for all transports. -- public child `CmEnrollmentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CmEnrollmentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCmEnrollmentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CmEnrollmentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CmEnrollmentServiceTransport`` is the ABC for all transports. + +- public child ``CmEnrollmentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CmEnrollmentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCmEnrollmentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CmEnrollmentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/base.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/base.py index 8d6dcc1b0e0c..0a3b7179a25e 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/base.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc.py index 96bb7da3013c..8d30f6ce6ca1 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc_asyncio.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc_asyncio.py index 21665322f67e..9f946e2b9573 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/rest.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/rest.py index dfa49d57ee1a..76532a2c43e0 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/rest.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/cm_enrollment_service/transports/rest.py @@ -413,6 +413,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CmEnrollmentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/async_client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/async_client.py index cc7d738b49d5..c3dcf4645681 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/async_client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> ConfigTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1581,7 +1581,7 @@ async def sample_delete_cloud_control(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1607,8 +1607,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1617,7 +1621,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1625,7 +1629,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1636,7 +1640,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1662,8 +1666,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1672,7 +1680,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1680,7 +1688,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1691,7 +1699,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1721,8 +1729,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1731,7 +1743,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1739,7 +1751,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1747,7 +1759,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1776,8 +1788,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1786,7 +1802,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1794,7 +1810,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1802,7 +1818,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1828,8 +1844,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1838,7 +1858,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1846,7 +1866,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1857,7 +1877,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1883,8 +1903,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1893,7 +1917,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1901,7 +1925,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/client.py index 2fcf5bbcc970..62bbc083c406 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/client.py @@ -116,7 +116,7 @@ class ConfigClient(metaclass=ConfigClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -463,7 +467,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -560,7 +564,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -656,7 +660,7 @@ def __init__( self._universe_domain = ConfigClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2021,7 +2025,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2047,8 +2051,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2057,7 +2065,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2066,7 +2074,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2080,7 +2088,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2106,8 +2114,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2116,7 +2128,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2125,7 +2137,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2139,7 +2151,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2169,8 +2181,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2179,7 +2195,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2187,7 +2203,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2195,7 +2211,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2224,8 +2240,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2234,7 +2254,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2242,7 +2262,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2250,7 +2270,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2276,8 +2296,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2286,7 +2310,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2295,7 +2319,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2309,7 +2333,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2335,8 +2359,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2345,7 +2373,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2354,7 +2382,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/README.rst b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/README.rst index 78e592f08a90..87549ba61f67 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/README.rst +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfigTransport` is the ABC for all transports. -- public child `ConfigGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfigGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfigRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfigRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfigTransport`` is the ABC for all transports. + +- public child ``ConfigGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfigGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfigRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfigRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/base.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/base.py index 308d0d170df1..85eb13e61514 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/base.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc.py index 5726ec7905b8..0ca2f5522189 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc_asyncio.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc_asyncio.py index e134cedd1a80..ea4d3ef573dd 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/rest.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/rest.py index 5604c92fd2e3..3a5ae09643e6 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/rest.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/config/transports/rest.py @@ -763,6 +763,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConfigRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/async_client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/async_client.py index bb53aa3ec27f..55c9c967baf1 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/async_client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> DeploymentTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1097,7 +1097,7 @@ async def sample_list_cloud_control_deployments(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1123,8 +1123,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1133,7 +1137,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1141,7 +1145,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1152,7 +1156,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1178,8 +1182,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1188,7 +1196,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1196,7 +1204,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1207,7 +1215,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1237,8 +1245,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1247,7 +1259,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1255,7 +1267,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1263,7 +1275,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1292,8 +1304,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1302,7 +1318,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1310,7 +1326,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1318,7 +1334,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1344,8 +1360,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1354,7 +1374,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1362,7 +1382,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1373,7 +1393,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1399,8 +1419,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1409,7 +1433,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1417,7 +1441,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/client.py index 3b319ebf9de8..c50f7612f07d 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/client.py @@ -118,7 +118,7 @@ class DeploymentClient(metaclass=DeploymentClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -487,7 +491,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -584,7 +588,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -680,7 +684,7 @@ def __init__( self._universe_domain = DeploymentClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1569,7 +1573,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1595,8 +1599,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1605,7 +1613,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1614,7 +1622,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1628,7 +1636,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1654,8 +1662,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1664,7 +1676,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1673,7 +1685,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1687,7 +1699,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1717,8 +1729,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1727,7 +1743,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1735,7 +1751,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1743,7 +1759,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1772,8 +1788,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1782,7 +1802,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1790,7 +1810,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1798,7 +1818,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1824,8 +1844,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1834,7 +1858,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1843,7 +1867,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1857,7 +1881,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1883,8 +1907,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1893,7 +1921,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1902,7 +1930,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/README.rst b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/README.rst index 04b895aa491c..4fbdd65c56ec 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/README.rst +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeploymentTransport` is the ABC for all transports. -- public child `DeploymentGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeploymentGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeploymentRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeploymentRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeploymentTransport`` is the ABC for all transports. + +- public child ``DeploymentGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeploymentGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeploymentRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeploymentRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/base.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/base.py index fdb5743d604b..6df3f0e392a0 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/base.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc.py index e2053013e715..25f5e9cb5e97 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc_asyncio.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc_asyncio.py index 7b6c55380bfe..b1fe98db34e3 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/rest.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/rest.py index 3c7cf1570c25..f314956e91b7 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/rest.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/deployment/transports/rest.py @@ -644,6 +644,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeploymentRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/async_client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/async_client.py index eeaa4b2325a8..5f2a51fd7a34 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/async_client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> MonitoringTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -929,7 +929,7 @@ async def sample_aggregate_framework_compliance_report(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -955,8 +955,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -965,7 +969,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -973,7 +977,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -984,7 +988,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1010,8 +1014,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1020,7 +1028,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1028,7 +1036,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1039,7 +1047,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1069,8 +1077,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1079,7 +1091,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1087,7 +1099,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1095,7 +1107,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1124,8 +1136,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1134,7 +1150,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1142,7 +1158,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1150,7 +1166,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1176,8 +1192,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1186,7 +1206,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1194,7 +1214,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1205,7 +1225,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1231,8 +1251,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1241,7 +1265,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1249,7 +1273,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/client.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/client.py index 28893ee9ac60..a8f30a56604c 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/client.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/client.py @@ -113,7 +113,7 @@ class MonitoringClient(metaclass=MonitoringClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -506,7 +510,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -603,7 +607,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -699,7 +703,7 @@ def __init__( self._universe_domain = MonitoringClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1416,7 +1420,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1442,8 +1446,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1452,7 +1460,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1461,7 +1469,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1475,7 +1483,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1501,8 +1509,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1511,7 +1523,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1520,7 +1532,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1534,7 +1546,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1564,8 +1576,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1574,7 +1590,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1582,7 +1598,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1590,7 +1606,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1619,8 +1635,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1629,7 +1649,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1637,7 +1657,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1645,7 +1665,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1671,8 +1691,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1681,7 +1705,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1690,7 +1714,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1704,7 +1728,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1730,8 +1754,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1740,7 +1768,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1749,7 +1777,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/README.rst b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/README.rst index 5c05c5143cb9..9b25fd7adf3d 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/README.rst +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MonitoringTransport` is the ABC for all transports. -- public child `MonitoringGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MonitoringGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMonitoringRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MonitoringRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MonitoringTransport`` is the ABC for all transports. + +- public child ``MonitoringGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MonitoringGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMonitoringRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MonitoringRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/base.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/base.py index 0c6fd1d42bce..5f990ad55467 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/base.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc.py index d387a1a32b82..e1151b722252 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc_asyncio.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc_asyncio.py index 268d9946ecc5..e941393a716e 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc_asyncio.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/rest.py b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/rest.py index c165e20eb839..80e6dd9bdf49 100644 --- a/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/rest.py +++ b/packages/google-cloud-cloudsecuritycompliance/google/cloud/cloudsecuritycompliance_v1/services/monitoring/transports/rest.py @@ -590,6 +590,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MonitoringRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-cloudsecuritycompliance/noxfile.py b/packages/google-cloud-cloudsecuritycompliance/noxfile.py index 2262a87de86c..cdfbb2dffba2 100644 --- a/packages/google-cloud-cloudsecuritycompliance/noxfile.py +++ b/packages/google-cloud-cloudsecuritycompliance/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-cloudsecuritycompliance/setup.py b/packages/google-cloud-cloudsecuritycompliance/setup.py index 247653e48926..ab183593f2a2 100644 --- a/packages/google-cloud-cloudsecuritycompliance/setup.py +++ b/packages/google-cloud-cloudsecuritycompliance/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-cloudsecuritycompliance" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.7.txt b/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.8.txt b/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.9.txt b/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.9.txt +++ b/packages/google-cloud-cloudsecuritycompliance/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_audit.py b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_audit.py index 3cbf52b2a703..6cb0293947aa 100644 --- a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_audit.py +++ b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_audit.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AuditClient._get_default_mtls_endpoint(None) is None assert AuditClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -141,6 +142,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AuditClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AuditClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1215,11 +1217,13 @@ def test_audit_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4096,8 +4100,9 @@ def test_generate_framework_audit_scope_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4161,18 +4166,21 @@ def test_generate_framework_audit_scope_report_rest_interceptors(null_intercepto ) client = AuditClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditRestInterceptor, "post_generate_framework_audit_scope_report" - ) as post, mock.patch.object( - transports.AuditRestInterceptor, - "post_generate_framework_audit_scope_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AuditRestInterceptor, "pre_generate_framework_audit_scope_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditRestInterceptor, + "post_generate_framework_audit_scope_report", + ) as post, + mock.patch.object( + transports.AuditRestInterceptor, + "post_generate_framework_audit_scope_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AuditRestInterceptor, "pre_generate_framework_audit_scope_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4230,8 +4238,9 @@ def test_create_framework_audit_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4419,19 +4428,20 @@ def test_create_framework_audit_rest_interceptors(null_interceptor): ) client = AuditClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AuditRestInterceptor, "post_create_framework_audit" - ) as post, mock.patch.object( - transports.AuditRestInterceptor, "post_create_framework_audit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditRestInterceptor, "pre_create_framework_audit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AuditRestInterceptor, "post_create_framework_audit" + ) as post, + mock.patch.object( + transports.AuditRestInterceptor, "post_create_framework_audit_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AuditRestInterceptor, "pre_create_framework_audit" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4484,8 +4494,9 @@ def test_list_framework_audits_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4546,17 +4557,19 @@ def test_list_framework_audits_rest_interceptors(null_interceptor): ) client = AuditClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditRestInterceptor, "post_list_framework_audits" - ) as post, mock.patch.object( - transports.AuditRestInterceptor, "post_list_framework_audits_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditRestInterceptor, "pre_list_framework_audits" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditRestInterceptor, "post_list_framework_audits" + ) as post, + mock.patch.object( + transports.AuditRestInterceptor, "post_list_framework_audits_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AuditRestInterceptor, "pre_list_framework_audits" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4613,8 +4626,9 @@ def test_get_framework_audit_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4689,17 +4703,19 @@ def test_get_framework_audit_rest_interceptors(null_interceptor): ) client = AuditClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AuditRestInterceptor, "post_get_framework_audit" - ) as post, mock.patch.object( - transports.AuditRestInterceptor, "post_get_framework_audit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AuditRestInterceptor, "pre_get_framework_audit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AuditRestInterceptor, "post_get_framework_audit" + ) as post, + mock.patch.object( + transports.AuditRestInterceptor, "post_get_framework_audit_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AuditRestInterceptor, "pre_get_framework_audit" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4750,8 +4766,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4810,8 +4827,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "organizations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4872,8 +4890,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4936,8 +4955,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5000,8 +5020,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5064,8 +5085,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5292,11 +5314,14 @@ def test_audit_base_transport(): def test_audit_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.audit.transports.AuditTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.audit.transports.AuditTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuditTransport( @@ -5313,9 +5338,12 @@ def test_audit_base_transport_with_credentials_file(): def test_audit_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.audit.transports.AuditTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.audit.transports.AuditTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AuditTransport() @@ -5387,11 +5415,12 @@ def test_audit_transport_auth_gdch_credentials(transport_class): def test_audit_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6010,6 +6039,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AuditClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AuditAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AuditClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6149,6 +6210,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AuditClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AuditAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AuditClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6294,6 +6387,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AuditClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AuditAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AuditClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6439,6 +6566,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AuditClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AuditAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AuditClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6584,6 +6745,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AuditClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AuditAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AuditClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6725,6 +6920,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AuditClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AuditAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AuditClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_cm_enrollment_service.py b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_cm_enrollment_service.py index 865b68456611..f2bef3ca7dec 100644 --- a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_cm_enrollment_service.py +++ b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_cm_enrollment_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CmEnrollmentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): CmEnrollmentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CmEnrollmentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1342,11 +1347,13 @@ def test_cm_enrollment_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2697,8 +2704,9 @@ def test_update_cm_enrollment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2841,18 +2849,20 @@ def test_update_cm_enrollment_rest_interceptors(null_interceptor): ) client = CmEnrollmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmEnrollmentServiceRestInterceptor, "post_update_cm_enrollment" - ) as post, mock.patch.object( - transports.CmEnrollmentServiceRestInterceptor, - "post_update_cm_enrollment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmEnrollmentServiceRestInterceptor, "pre_update_cm_enrollment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmEnrollmentServiceRestInterceptor, "post_update_cm_enrollment" + ) as post, + mock.patch.object( + transports.CmEnrollmentServiceRestInterceptor, + "post_update_cm_enrollment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmEnrollmentServiceRestInterceptor, "pre_update_cm_enrollment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2907,8 +2917,9 @@ def test_calculate_effective_cm_enrollment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2972,20 +2983,22 @@ def test_calculate_effective_cm_enrollment_rest_interceptors(null_interceptor): ) client = CmEnrollmentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmEnrollmentServiceRestInterceptor, - "post_calculate_effective_cm_enrollment", - ) as post, mock.patch.object( - transports.CmEnrollmentServiceRestInterceptor, - "post_calculate_effective_cm_enrollment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmEnrollmentServiceRestInterceptor, - "pre_calculate_effective_cm_enrollment", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmEnrollmentServiceRestInterceptor, + "post_calculate_effective_cm_enrollment", + ) as post, + mock.patch.object( + transports.CmEnrollmentServiceRestInterceptor, + "post_calculate_effective_cm_enrollment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmEnrollmentServiceRestInterceptor, + "pre_calculate_effective_cm_enrollment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3047,8 +3060,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3107,8 +3121,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "organizations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3169,8 +3184,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3233,8 +3249,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3297,8 +3314,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3361,8 +3379,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3521,11 +3540,14 @@ def test_cm_enrollment_service_base_transport(): def test_cm_enrollment_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.cm_enrollment_service.transports.CmEnrollmentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.cm_enrollment_service.transports.CmEnrollmentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmEnrollmentServiceTransport( @@ -3542,9 +3564,12 @@ def test_cm_enrollment_service_base_transport_with_credentials_file(): def test_cm_enrollment_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.cm_enrollment_service.transports.CmEnrollmentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.cm_enrollment_service.transports.CmEnrollmentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmEnrollmentServiceTransport() @@ -3616,11 +3641,12 @@ def test_cm_enrollment_service_transport_auth_gdch_credentials(transport_class): def test_cm_enrollment_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4185,6 +4211,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CmEnrollmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CmEnrollmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CmEnrollmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4324,6 +4382,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CmEnrollmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CmEnrollmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CmEnrollmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4469,6 +4559,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CmEnrollmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CmEnrollmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CmEnrollmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4614,6 +4738,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CmEnrollmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CmEnrollmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CmEnrollmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4759,6 +4917,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CmEnrollmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CmEnrollmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CmEnrollmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4902,6 +5094,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CmEnrollmentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CmEnrollmentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CmEnrollmentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_config.py b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_config.py index 82e05d7d14eb..8cd73de2d1e1 100644 --- a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_config.py +++ b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_config.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigClient._get_default_mtls_endpoint(None) is None assert ConfigClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -138,6 +139,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ConfigClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ConfigClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1216,11 +1218,13 @@ def test_config_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7994,8 +7998,9 @@ def test_list_frameworks_rest_bad_request(request_type=config.ListFrameworksRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8056,17 +8061,19 @@ def test_list_frameworks_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_frameworks" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_frameworks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_frameworks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_frameworks" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_frameworks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_frameworks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8119,8 +8126,9 @@ def test_get_framework_rest_bad_request(request_type=config.GetFrameworkRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8203,17 +8211,17 @@ def test_get_framework_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_framework" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_framework_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_framework" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_framework" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_framework_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ConfigRestInterceptor, "pre_get_framework") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8262,8 +8270,9 @@ def test_create_framework_rest_bad_request(request_type=config.CreateFrameworkRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8442,17 +8451,19 @@ def test_create_framework_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_create_framework" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_create_framework_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_create_framework" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_framework" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_framework_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_create_framework" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8505,8 +8516,9 @@ def test_update_framework_rest_bad_request(request_type=config.UpdateFrameworkRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8689,17 +8701,19 @@ def test_update_framework_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_update_framework" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_update_framework_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_update_framework" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_framework" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_framework_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_update_framework" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8750,8 +8764,9 @@ def test_delete_framework_rest_bad_request(request_type=config.DeleteFrameworkRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8808,13 +8823,13 @@ def test_delete_framework_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "pre_delete_framework" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_delete_framework" + ) as pre, + ): pre.assert_not_called() pb_message = config.DeleteFrameworkRequest.pb(config.DeleteFrameworkRequest()) transcode.return_value = { @@ -8857,8 +8872,9 @@ def test_list_cloud_controls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8919,17 +8935,19 @@ def test_list_cloud_controls_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_cloud_controls" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_cloud_controls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_cloud_controls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_cloud_controls" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_cloud_controls_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_cloud_controls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8984,8 +9002,9 @@ def test_get_cloud_control_rest_bad_request(request_type=config.GetCloudControlR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9076,17 +9095,19 @@ def test_get_cloud_control_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_cloud_control" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_cloud_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_cloud_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_cloud_control" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_cloud_control_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_get_cloud_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9137,8 +9158,9 @@ def test_create_cloud_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9352,17 +9374,19 @@ def test_create_cloud_control_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_create_cloud_control" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_create_cloud_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_create_cloud_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_cloud_control" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_cloud_control_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_create_cloud_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9419,8 +9443,9 @@ def test_update_cloud_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9638,17 +9663,19 @@ def test_update_cloud_control_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_update_cloud_control" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_update_cloud_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_update_cloud_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_cloud_control" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_cloud_control_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_update_cloud_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9703,8 +9730,9 @@ def test_delete_cloud_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9761,13 +9789,13 @@ def test_delete_cloud_control_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "pre_delete_cloud_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_delete_cloud_control" + ) as pre, + ): pre.assert_not_called() pb_message = config.DeleteCloudControlRequest.pb( config.DeleteCloudControlRequest() @@ -9812,8 +9840,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9872,8 +9901,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "organizations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9934,8 +9964,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9998,8 +10029,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10062,8 +10094,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10126,8 +10159,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10460,11 +10494,14 @@ def test_config_base_transport(): def test_config_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigTransport( @@ -10481,9 +10518,12 @@ def test_config_base_transport_with_credentials_file(): def test_config_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigTransport() @@ -10555,11 +10595,12 @@ def test_config_transport_auth_gdch_credentials(transport_class): def test_config_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11164,6 +11205,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11303,6 +11376,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11448,6 +11553,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11593,6 +11732,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11738,6 +11911,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11879,6 +12086,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_deployment.py b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_deployment.py index 28be523220a8..7c7006eaf873 100644 --- a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_deployment.py +++ b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_deployment.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeploymentClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DeploymentClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DeploymentClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1247,11 +1251,13 @@ def test_deployment_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5580,8 +5586,9 @@ def test_create_framework_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5760,20 +5767,21 @@ def test_create_framework_deployment_rest_interceptors(null_interceptor): ) client = DeploymentClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeploymentRestInterceptor, "post_create_framework_deployment" - ) as post, mock.patch.object( - transports.DeploymentRestInterceptor, - "post_create_framework_deployment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeploymentRestInterceptor, "pre_create_framework_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeploymentRestInterceptor, "post_create_framework_deployment" + ) as post, + mock.patch.object( + transports.DeploymentRestInterceptor, + "post_create_framework_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentRestInterceptor, "pre_create_framework_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5828,8 +5836,9 @@ def test_delete_framework_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5888,20 +5897,21 @@ def test_delete_framework_deployment_rest_interceptors(null_interceptor): ) client = DeploymentClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeploymentRestInterceptor, "post_delete_framework_deployment" - ) as post, mock.patch.object( - transports.DeploymentRestInterceptor, - "post_delete_framework_deployment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeploymentRestInterceptor, "pre_delete_framework_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeploymentRestInterceptor, "post_delete_framework_deployment" + ) as post, + mock.patch.object( + transports.DeploymentRestInterceptor, + "post_delete_framework_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentRestInterceptor, "pre_delete_framework_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5956,8 +5966,9 @@ def test_get_framework_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6035,18 +6046,20 @@ def test_get_framework_deployment_rest_interceptors(null_interceptor): ) client = DeploymentClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentRestInterceptor, "post_get_framework_deployment" - ) as post, mock.patch.object( - transports.DeploymentRestInterceptor, - "post_get_framework_deployment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeploymentRestInterceptor, "pre_get_framework_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentRestInterceptor, "post_get_framework_deployment" + ) as post, + mock.patch.object( + transports.DeploymentRestInterceptor, + "post_get_framework_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentRestInterceptor, "pre_get_framework_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6101,8 +6114,9 @@ def test_list_framework_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6165,18 +6179,20 @@ def test_list_framework_deployments_rest_interceptors(null_interceptor): ) client = DeploymentClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentRestInterceptor, "post_list_framework_deployments" - ) as post, mock.patch.object( - transports.DeploymentRestInterceptor, - "post_list_framework_deployments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeploymentRestInterceptor, "pre_list_framework_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentRestInterceptor, "post_list_framework_deployments" + ) as post, + mock.patch.object( + transports.DeploymentRestInterceptor, + "post_list_framework_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentRestInterceptor, "pre_list_framework_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6236,8 +6252,9 @@ def test_get_cloud_control_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6315,18 +6332,20 @@ def test_get_cloud_control_deployment_rest_interceptors(null_interceptor): ) client = DeploymentClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentRestInterceptor, "post_get_cloud_control_deployment" - ) as post, mock.patch.object( - transports.DeploymentRestInterceptor, - "post_get_cloud_control_deployment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeploymentRestInterceptor, "pre_get_cloud_control_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentRestInterceptor, "post_get_cloud_control_deployment" + ) as post, + mock.patch.object( + transports.DeploymentRestInterceptor, + "post_get_cloud_control_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentRestInterceptor, "pre_get_cloud_control_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6381,8 +6400,9 @@ def test_list_cloud_control_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6445,18 +6465,20 @@ def test_list_cloud_control_deployments_rest_interceptors(null_interceptor): ) client = DeploymentClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentRestInterceptor, "post_list_cloud_control_deployments" - ) as post, mock.patch.object( - transports.DeploymentRestInterceptor, - "post_list_cloud_control_deployments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeploymentRestInterceptor, "pre_list_cloud_control_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentRestInterceptor, "post_list_cloud_control_deployments" + ) as post, + mock.patch.object( + transports.DeploymentRestInterceptor, + "post_list_cloud_control_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentRestInterceptor, "pre_list_cloud_control_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6514,8 +6536,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6574,8 +6597,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "organizations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6636,8 +6660,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6700,8 +6725,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6764,8 +6790,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6828,8 +6855,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7102,11 +7130,14 @@ def test_deployment_base_transport(): def test_deployment_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.deployment.transports.DeploymentTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.deployment.transports.DeploymentTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeploymentTransport( @@ -7123,9 +7154,12 @@ def test_deployment_base_transport_with_credentials_file(): def test_deployment_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.deployment.transports.DeploymentTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.deployment.transports.DeploymentTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeploymentTransport() @@ -7197,11 +7231,12 @@ def test_deployment_transport_auth_gdch_credentials(transport_class): def test_deployment_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7858,6 +7893,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DeploymentClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DeploymentAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DeploymentClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7997,6 +8064,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DeploymentClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DeploymentAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DeploymentClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8142,6 +8241,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DeploymentClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DeploymentAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DeploymentClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8287,6 +8420,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DeploymentClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DeploymentAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DeploymentClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8432,6 +8599,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DeploymentClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DeploymentAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DeploymentClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8573,6 +8774,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DeploymentClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DeploymentAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DeploymentClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_monitoring.py b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_monitoring.py index 7a5d86c77846..f3af1de65ee2 100644 --- a/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_monitoring.py +++ b/packages/google-cloud-cloudsecuritycompliance/tests/unit/gapic/cloudsecuritycompliance_v1/test_monitoring.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MonitoringClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MonitoringClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MonitoringClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_monitoring_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5275,8 +5281,9 @@ def test_list_framework_compliance_summaries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5341,18 +5348,22 @@ def test_list_framework_compliance_summaries_rest_interceptors(null_interceptor) ) client = MonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MonitoringRestInterceptor, "post_list_framework_compliance_summaries" - ) as post, mock.patch.object( - transports.MonitoringRestInterceptor, - "post_list_framework_compliance_summaries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MonitoringRestInterceptor, "pre_list_framework_compliance_summaries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_list_framework_compliance_summaries", + ) as post, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_list_framework_compliance_summaries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MonitoringRestInterceptor, + "pre_list_framework_compliance_summaries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5410,8 +5421,9 @@ def test_list_finding_summaries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5474,18 +5486,20 @@ def test_list_finding_summaries_rest_interceptors(null_interceptor): ) client = MonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MonitoringRestInterceptor, "post_list_finding_summaries" - ) as post, mock.patch.object( - transports.MonitoringRestInterceptor, - "post_list_finding_summaries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MonitoringRestInterceptor, "pre_list_finding_summaries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MonitoringRestInterceptor, "post_list_finding_summaries" + ) as post, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_list_finding_summaries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MonitoringRestInterceptor, "pre_list_finding_summaries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5545,8 +5559,9 @@ def test_fetch_framework_compliance_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5629,18 +5644,22 @@ def test_fetch_framework_compliance_report_rest_interceptors(null_interceptor): ) client = MonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MonitoringRestInterceptor, "post_fetch_framework_compliance_report" - ) as post, mock.patch.object( - transports.MonitoringRestInterceptor, - "post_fetch_framework_compliance_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MonitoringRestInterceptor, "pre_fetch_framework_compliance_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_fetch_framework_compliance_report", + ) as post, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_fetch_framework_compliance_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MonitoringRestInterceptor, + "pre_fetch_framework_compliance_report", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5700,8 +5719,9 @@ def test_list_control_compliance_summaries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5768,18 +5788,22 @@ def test_list_control_compliance_summaries_rest_interceptors(null_interceptor): ) client = MonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MonitoringRestInterceptor, "post_list_control_compliance_summaries" - ) as post, mock.patch.object( - transports.MonitoringRestInterceptor, - "post_list_control_compliance_summaries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MonitoringRestInterceptor, "pre_list_control_compliance_summaries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_list_control_compliance_summaries", + ) as post, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_list_control_compliance_summaries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MonitoringRestInterceptor, + "pre_list_control_compliance_summaries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5839,8 +5863,9 @@ def test_aggregate_framework_compliance_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5904,20 +5929,22 @@ def test_aggregate_framework_compliance_report_rest_interceptors(null_intercepto ) client = MonitoringClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MonitoringRestInterceptor, - "post_aggregate_framework_compliance_report", - ) as post, mock.patch.object( - transports.MonitoringRestInterceptor, - "post_aggregate_framework_compliance_report_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MonitoringRestInterceptor, - "pre_aggregate_framework_compliance_report", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_aggregate_framework_compliance_report", + ) as post, + mock.patch.object( + transports.MonitoringRestInterceptor, + "post_aggregate_framework_compliance_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MonitoringRestInterceptor, + "pre_aggregate_framework_compliance_report", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5975,8 +6002,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6035,8 +6063,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "organizations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6097,8 +6126,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6161,8 +6191,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6225,8 +6256,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6289,8 +6321,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6518,11 +6551,14 @@ def test_monitoring_base_transport(): def test_monitoring_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.monitoring.transports.MonitoringTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.monitoring.transports.MonitoringTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MonitoringTransport( @@ -6539,9 +6575,12 @@ def test_monitoring_base_transport_with_credentials_file(): def test_monitoring_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.cloudsecuritycompliance_v1.services.monitoring.transports.MonitoringTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.cloudsecuritycompliance_v1.services.monitoring.transports.MonitoringTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MonitoringTransport() @@ -6613,11 +6652,12 @@ def test_monitoring_transport_auth_gdch_credentials(transport_class): def test_monitoring_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7268,6 +7308,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = MonitoringClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = MonitoringAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = MonitoringClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7407,6 +7479,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = MonitoringClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = MonitoringAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = MonitoringClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7552,6 +7656,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = MonitoringClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = MonitoringAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = MonitoringClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7697,6 +7835,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = MonitoringClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = MonitoringAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = MonitoringClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7842,6 +8014,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = MonitoringClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = MonitoringAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = MonitoringClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7983,6 +8189,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = MonitoringClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = MonitoringAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = MonitoringClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/async_client.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/async_client.py index 38273bb95496..e2145f8a475f 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/async_client.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> ConsumerProcurementServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -945,7 +945,7 @@ async def sample_cancel_order(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -971,8 +971,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -981,7 +985,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -989,7 +993,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/client.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/client.py index 9b8175faf341..6d7bec4668b2 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/client.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/client.py @@ -129,7 +129,7 @@ class ConsumerProcurementServiceClient(metaclass=ConsumerProcurementServiceClien """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -137,7 +137,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -147,6 +147,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = ConsumerProcurementServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1379,7 +1383,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1405,8 +1409,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1415,7 +1423,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1424,7 +1432,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/README.rst b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/README.rst index 771c9092beea..9f6f483d1acb 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/README.rst +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConsumerProcurementServiceTransport` is the ABC for all transports. -- public child `ConsumerProcurementServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConsumerProcurementServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConsumerProcurementServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConsumerProcurementServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConsumerProcurementServiceTransport`` is the ABC for all transports. + +- public child ``ConsumerProcurementServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConsumerProcurementServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConsumerProcurementServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConsumerProcurementServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/base.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/base.py index ba85d1d22e1d..c3c9db58894c 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/base.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc.py index c61ace9496de..574955ceb4d1 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc_asyncio.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc_asyncio.py index 690d1357aaba..f6747c0bdfe1 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -248,6 +248,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/rest.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/rest.py index 94d15bba1223..46c7aa2c777c 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/rest.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/consumer_procurement_service/transports/rest.py @@ -461,6 +461,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConsumerProcurementServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/async_client.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/async_client.py index ceab3bb3e9cc..b3e8b54ebd13 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/async_client.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/async_client.py @@ -206,7 +206,7 @@ def transport(self) -> LicenseManagementServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -923,7 +923,7 @@ async def sample_enumerate_licensed_users(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -949,8 +949,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -959,7 +963,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -967,7 +971,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/client.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/client.py index d01d5d9aab88..902b13a78998 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/client.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/client.py @@ -118,7 +118,7 @@ class LicenseManagementServiceClient(metaclass=LicenseManagementServiceClientMet """Service for managing licenses.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -642,7 +646,7 @@ def __init__( self._universe_domain = LicenseManagementServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1346,7 +1350,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1372,8 +1376,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1382,7 +1390,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1391,7 +1399,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/README.rst b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/README.rst index 534c9eb571ae..8d92d16054f0 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/README.rst +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LicenseManagementServiceTransport` is the ABC for all transports. -- public child `LicenseManagementServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LicenseManagementServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLicenseManagementServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LicenseManagementServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LicenseManagementServiceTransport`` is the ABC for all transports. + +- public child ``LicenseManagementServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LicenseManagementServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLicenseManagementServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LicenseManagementServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/base.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/base.py index 535448dcab45..100f369497ff 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/base.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc.py index 399b1548d3bd..5141ac860b02 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc_asyncio.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc_asyncio.py index 3d64e26ef8e7..63daaa3af220 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/rest.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/rest.py index f1a4e4c1c747..03c914eab7ef 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/rest.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1/services/license_management_service/transports/rest.py @@ -471,6 +471,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LicenseManagementServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/async_client.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/async_client.py index a1165c51f93b..72093c981250 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/async_client.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> ConsumerProcurementServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -717,7 +717,7 @@ async def sample_list_orders(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -743,8 +743,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -753,7 +757,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -761,7 +765,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/client.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/client.py index 416661f058e3..ecd0f4724eb5 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/client.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/client.py @@ -129,7 +129,7 @@ class ConsumerProcurementServiceClient(metaclass=ConsumerProcurementServiceClien """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -137,7 +137,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -147,6 +147,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = ConsumerProcurementServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1155,7 +1159,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1181,8 +1185,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1191,7 +1199,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1200,7 +1208,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/README.rst b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/README.rst index 771c9092beea..9f6f483d1acb 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/README.rst +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConsumerProcurementServiceTransport` is the ABC for all transports. -- public child `ConsumerProcurementServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConsumerProcurementServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConsumerProcurementServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConsumerProcurementServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConsumerProcurementServiceTransport`` is the ABC for all transports. + +- public child ``ConsumerProcurementServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConsumerProcurementServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConsumerProcurementServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConsumerProcurementServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/base.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/base.py index ba86469dd3cc..866b13867756 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/base.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc.py index 22a991bd96fe..b7a7f41c06f0 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc_asyncio.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc_asyncio.py index 277ea13d647b..8879350cbef6 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -248,6 +248,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/rest.py b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/rest.py index 641b4f0b2b91..deaeac849c74 100644 --- a/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/rest.py +++ b/packages/google-cloud-commerce-consumer-procurement/google/cloud/commerce_consumer_procurement_v1alpha1/services/consumer_procurement_service/transports/rest.py @@ -349,6 +349,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConsumerProcurementServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-commerce-consumer-procurement/noxfile.py b/packages/google-cloud-commerce-consumer-procurement/noxfile.py index 76e79fb5029e..74402fc580a3 100644 --- a/packages/google-cloud-commerce-consumer-procurement/noxfile.py +++ b/packages/google-cloud-commerce-consumer-procurement/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-commerce-consumer-procurement/setup.py b/packages/google-cloud-commerce-consumer-procurement/setup.py index 6f67a43f94ca..e7f7f8ef148f 100644 --- a/packages/google-cloud-commerce-consumer-procurement/setup.py +++ b/packages/google-cloud-commerce-consumer-procurement/setup.py @@ -43,7 +43,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -51,7 +51,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-commerce-consumer-procurement" @@ -83,8 +83,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -96,7 +94,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.7.txt b/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.8.txt b/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.9.txt b/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.9.txt +++ b/packages/google-cloud-commerce-consumer-procurement/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_consumer_procurement_service.py b/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_consumer_procurement_service.py index aec55c4fc5cb..5327ef9054ec 100644 --- a/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_consumer_procurement_service.py +++ b/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_consumer_procurement_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConsumerProcurementServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): ConsumerProcurementServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConsumerProcurementServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1380,11 +1385,13 @@ def test_consumer_procurement_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4181,8 +4188,9 @@ def test_place_order_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4239,20 +4247,21 @@ def test_place_order_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_place_order" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_place_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_place_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_place_order" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_place_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_place_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4303,8 +4312,9 @@ def test_get_order_rest_bad_request(request_type=procurement_service.GetOrderReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4371,18 +4381,20 @@ def test_get_order_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_get_order" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_get_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_get_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_get_order" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_get_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_get_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4435,8 +4447,9 @@ def test_list_orders_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4499,18 +4512,20 @@ def test_list_orders_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_list_orders" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_list_orders_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_list_orders" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_list_orders" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_list_orders_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_list_orders" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4568,8 +4583,9 @@ def test_modify_order_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4626,20 +4642,21 @@ def test_modify_order_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_modify_order" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_modify_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_modify_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_modify_order" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_modify_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_modify_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4692,8 +4709,9 @@ def test_cancel_order_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4750,20 +4768,21 @@ def test_cancel_order_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_cancel_order" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_cancel_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_cancel_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_cancel_order" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_cancel_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_cancel_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4818,8 +4837,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5054,11 +5074,14 @@ def test_consumer_procurement_service_base_transport(): def test_consumer_procurement_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.commerce_consumer_procurement_v1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.commerce_consumer_procurement_v1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConsumerProcurementServiceTransport( @@ -5075,9 +5098,12 @@ def test_consumer_procurement_service_base_transport_with_credentials_file(): def test_consumer_procurement_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.commerce_consumer_procurement_v1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.commerce_consumer_procurement_v1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConsumerProcurementServiceTransport() @@ -5151,11 +5177,12 @@ def test_consumer_procurement_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5796,6 +5823,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConsumerProcurementServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConsumerProcurementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = ConsumerProcurementServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_license_management_service.py b/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_license_management_service.py index 1cbd7b2a811e..da3469a15cf3 100644 --- a/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_license_management_service.py +++ b/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1/test_license_management_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LicenseManagementServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): LicenseManagementServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LicenseManagementServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1357,11 +1362,13 @@ def test_license_management_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4700,8 +4707,9 @@ def test_get_license_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4768,18 +4776,20 @@ def test_get_license_pool_rest_interceptors(null_interceptor): ) client = LicenseManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "post_get_license_pool" - ) as post, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, - "post_get_license_pool_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "pre_get_license_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, "post_get_license_pool" + ) as post, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_get_license_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, "pre_get_license_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4839,8 +4849,9 @@ def test_update_license_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4989,18 +5000,22 @@ def test_update_license_pool_rest_interceptors(null_interceptor): ) client = LicenseManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "post_update_license_pool" - ) as post, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, - "post_update_license_pool_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "pre_update_license_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_update_license_pool", + ) as post, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_update_license_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "pre_update_license_pool", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5056,8 +5071,9 @@ def test_assign_rest_bad_request(request_type=license_management_service.AssignR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5117,17 +5133,20 @@ def test_assign_rest_interceptors(null_interceptor): ) client = LicenseManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "post_assign" - ) as post, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "post_assign_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "pre_assign" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, "post_assign" + ) as post, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_assign_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, "pre_assign" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5185,8 +5204,9 @@ def test_unassign_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5246,18 +5266,20 @@ def test_unassign_rest_interceptors(null_interceptor): ) client = LicenseManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "post_unassign" - ) as post, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, - "post_unassign_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, "pre_unassign" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, "post_unassign" + ) as post, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_unassign_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, "pre_unassign" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5315,8 +5337,9 @@ def test_enumerate_licensed_users_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5381,20 +5404,22 @@ def test_enumerate_licensed_users_rest_interceptors(null_interceptor): ) client = LicenseManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, - "post_enumerate_licensed_users", - ) as post, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, - "post_enumerate_licensed_users_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagementServiceRestInterceptor, - "pre_enumerate_licensed_users", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_enumerate_licensed_users", + ) as post, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "post_enumerate_licensed_users_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagementServiceRestInterceptor, + "pre_enumerate_licensed_users", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5456,8 +5481,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5674,11 +5700,14 @@ def test_license_management_service_base_transport(): def test_license_management_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.commerce_consumer_procurement_v1.services.license_management_service.transports.LicenseManagementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.commerce_consumer_procurement_v1.services.license_management_service.transports.LicenseManagementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseManagementServiceTransport( @@ -5695,9 +5724,12 @@ def test_license_management_service_base_transport_with_credentials_file(): def test_license_management_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.commerce_consumer_procurement_v1.services.license_management_service.transports.LicenseManagementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.commerce_consumer_procurement_v1.services.license_management_service.transports.LicenseManagementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseManagementServiceTransport() @@ -5771,11 +5803,12 @@ def test_license_management_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6355,6 +6388,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = LicenseManagementServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LicenseManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = LicenseManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1alpha1/test_consumer_procurement_service.py b/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1alpha1/test_consumer_procurement_service.py index 4909dcc03b4f..9192d26c3ebe 100644 --- a/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1alpha1/test_consumer_procurement_service.py +++ b/packages/google-cloud-commerce-consumer-procurement/tests/unit/gapic/commerce_consumer_procurement_v1alpha1/test_consumer_procurement_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConsumerProcurementServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): ConsumerProcurementServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConsumerProcurementServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1380,11 +1385,13 @@ def test_consumer_procurement_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3351,8 +3358,9 @@ def test_place_order_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3409,20 +3417,21 @@ def test_place_order_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_place_order" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_place_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_place_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_place_order" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_place_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_place_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3473,8 +3482,9 @@ def test_get_order_rest_bad_request(request_type=procurement_service.GetOrderReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3541,18 +3551,20 @@ def test_get_order_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_get_order" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_get_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_get_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_get_order" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_get_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_get_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3605,8 +3617,9 @@ def test_list_orders_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3669,18 +3682,20 @@ def test_list_orders_rest_interceptors(null_interceptor): ) client = ConsumerProcurementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "post_list_orders" - ) as post, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, - "post_list_orders_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConsumerProcurementServiceRestInterceptor, "pre_list_orders" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "post_list_orders" + ) as post, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, + "post_list_orders_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConsumerProcurementServiceRestInterceptor, "pre_list_orders" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3740,8 +3755,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3934,11 +3950,14 @@ def test_consumer_procurement_service_base_transport(): def test_consumer_procurement_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.commerce_consumer_procurement_v1alpha1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.commerce_consumer_procurement_v1alpha1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConsumerProcurementServiceTransport( @@ -3955,9 +3974,12 @@ def test_consumer_procurement_service_base_transport_with_credentials_file(): def test_consumer_procurement_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.commerce_consumer_procurement_v1alpha1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.commerce_consumer_procurement_v1alpha1.services.consumer_procurement_service.transports.ConsumerProcurementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConsumerProcurementServiceTransport() @@ -4031,11 +4053,12 @@ def test_consumer_procurement_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4670,6 +4693,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConsumerProcurementServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConsumerProcurementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = ConsumerProcurementServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-common/noxfile.py b/packages/google-cloud-common/noxfile.py index ef0e12841802..687588926b9d 100644 --- a/packages/google-cloud-common/noxfile.py +++ b/packages/google-cloud-common/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-common/setup.py b/packages/google-cloud-common/setup.py index f4cad79fa020..42858dac2453 100644 --- a/packages/google-cloud-common/setup.py +++ b/packages/google-cloud-common/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-common" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-common/testing/constraints-3.7.txt b/packages/google-cloud-common/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-common/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-common/testing/constraints-3.8.txt b/packages/google-cloud-common/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-common/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-common/testing/constraints-3.9.txt b/packages/google-cloud-common/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-common/testing/constraints-3.9.txt +++ b/packages/google-cloud-common/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/client.py index 5341bdc9302c..c5f013f8b054 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/client.py @@ -108,7 +108,7 @@ class AcceleratorTypesClient(metaclass=AcceleratorTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = AcceleratorTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/README.rst index 492c43918897..805d1f1f9012 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AcceleratorTypesTransport` is the ABC for all transports. -- public child `AcceleratorTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AcceleratorTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAcceleratorTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AcceleratorTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AcceleratorTypesTransport`` is the ABC for all transports. + +- public child ``AcceleratorTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AcceleratorTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAcceleratorTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AcceleratorTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/base.py index d0679ddf7ea4..9089047d33cd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/rest.py index 5d4e3e6e5ffa..0989be295574 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/accelerator_types/transports/rest.py @@ -320,6 +320,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AcceleratorTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/client.py index 059152ebe477..da10169a9d2b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/client.py @@ -108,7 +108,7 @@ class AddressesClient(metaclass=AddressesClientMeta): """The Addresses API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = AddressesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/README.rst index 0868b903ae5f..2d0323b5454b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AddressesTransport` is the ABC for all transports. -- public child `AddressesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AddressesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAddressesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AddressesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AddressesTransport`` is the ABC for all transports. + +- public child ``AddressesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AddressesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAddressesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AddressesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/base.py index e0c5ee1361ed..65911b744850 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/rest.py index 8aad6ff5593b..9c84a0c1383e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/addresses/transports/rest.py @@ -578,6 +578,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AddressesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/client.py index 454d51f652d1..378d2e924a3c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/client.py @@ -104,7 +104,7 @@ class AdviceClient(metaclass=AdviceClientMeta): """The Advice API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -603,7 +607,7 @@ def __init__( self._universe_domain = AdviceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/README.rst index 6cad73a5252f..3f748e33c131 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AdviceTransport` is the ABC for all transports. -- public child `AdviceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AdviceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAdviceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AdviceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AdviceTransport`` is the ABC for all transports. + +- public child ``AdviceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AdviceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAdviceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AdviceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/base.py index d89153f62492..b483b859ea75 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/rest.py index 341fddb4f2b8..ce4ba8230688 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/advice/transports/rest.py @@ -207,6 +207,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AdviceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/client.py index 91cb3f7f4302..8d6a702caecf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/client.py @@ -108,7 +108,7 @@ class AutoscalersClient(metaclass=AutoscalersClientMeta): """The Autoscalers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = AutoscalersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/README.rst index efb6ecaee833..b10ff5a35b68 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutoscalersTransport` is the ABC for all transports. -- public child `AutoscalersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutoscalersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutoscalersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutoscalersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutoscalersTransport`` is the ABC for all transports. + +- public child ``AutoscalersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutoscalersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutoscalersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutoscalersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/base.py index b358d38200ba..a2271682e62c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/rest.py index b724f976d1bb..9fd950933707 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/autoscalers/transports/rest.py @@ -585,6 +585,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutoscalersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/client.py index 91a307a4d02b..8dc229953b13 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/client.py @@ -108,7 +108,7 @@ class BackendBucketsClient(metaclass=BackendBucketsClientMeta): """The BackendBuckets API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = BackendBucketsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/README.rst index 30026928229f..24a46fc1cf4c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackendBucketsTransport` is the ABC for all transports. -- public child `BackendBucketsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackendBucketsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackendBucketsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackendBucketsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackendBucketsTransport`` is the ABC for all transports. + +- public child ``BackendBucketsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackendBucketsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackendBucketsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackendBucketsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/base.py index fa965dc86df2..ddc3bd44cc95 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/rest.py index c4cebaed5cf6..088074d60a50 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_buckets/transports/rest.py @@ -930,6 +930,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackendBucketsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/client.py index f60c8d66fe9a..49ef72f3695c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/client.py @@ -108,7 +108,7 @@ class BackendServicesClient(metaclass=BackendServicesClientMeta): """The BackendServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = BackendServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/README.rst index ecdf9985b784..9cbb59449d41 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackendServicesTransport` is the ABC for all transports. -- public child `BackendServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackendServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackendServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackendServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackendServicesTransport`` is the ABC for all transports. + +- public child ``BackendServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackendServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackendServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackendServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/base.py index 82f8967c4712..bfee522cf566 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/rest.py index 6318b19a3918..bac4a8b0c77d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/backend_services/transports/rest.py @@ -1106,6 +1106,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackendServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/client.py index f7ea42c3f7fa..691db7265b5d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/client.py @@ -108,7 +108,7 @@ class CrossSiteNetworksClient(metaclass=CrossSiteNetworksClientMeta): """The CrossSiteNetworks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = CrossSiteNetworksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/README.rst index 361c1232c685..2552c9613c60 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CrossSiteNetworksTransport` is the ABC for all transports. -- public child `CrossSiteNetworksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CrossSiteNetworksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCrossSiteNetworksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CrossSiteNetworksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CrossSiteNetworksTransport`` is the ABC for all transports. + +- public child ``CrossSiteNetworksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CrossSiteNetworksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCrossSiteNetworksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CrossSiteNetworksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/base.py index a5a1cba520d6..2d903d8ee9cf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/rest.py index 8eecc5537db1..9fd857d5a472 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/cross_site_networks/transports/rest.py @@ -421,6 +421,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CrossSiteNetworksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/client.py index c115d6399f01..d8ba648951f7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/client.py @@ -107,7 +107,7 @@ class DiskSettingsServiceClient(metaclass=DiskSettingsServiceClientMeta): """The DiskSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = DiskSettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/README.rst index ad6ea544d475..0229d9eb8c0e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiskSettingsServiceTransport` is the ABC for all transports. -- public child `DiskSettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiskSettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiskSettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiskSettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiskSettingsServiceTransport`` is the ABC for all transports. + +- public child ``DiskSettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiskSettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiskSettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiskSettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/base.py index a58f437b2968..5e9d9f2c7d73 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/rest.py index 65fb107d07de..160672d2419a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_settings_service/transports/rest.py @@ -255,6 +255,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiskSettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/client.py index a85dea4b4acd..190e3adf570e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/client.py @@ -105,7 +105,7 @@ class DiskTypesClient(metaclass=DiskTypesClientMeta): """The DiskTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = DiskTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/README.rst index c9e4d5b0d18a..172851742cb6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiskTypesTransport` is the ABC for all transports. -- public child `DiskTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiskTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiskTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiskTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiskTypesTransport`` is the ABC for all transports. + +- public child ``DiskTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiskTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiskTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiskTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/base.py index 1aa08ed51ab4..e26dfa0b9a78 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/rest.py index 1e2f6908d564..b886b3d403fb 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disk_types/transports/rest.py @@ -309,6 +309,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiskTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/client.py index 51d409d8a1fa..45d6fe58ae2e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/client.py @@ -108,7 +108,7 @@ class DisksClient(metaclass=DisksClientMeta): """The Disks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = DisksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/README.rst index ee30b21ca95a..32f77cc14043 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DisksTransport` is the ABC for all transports. -- public child `DisksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DisksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDisksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DisksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DisksTransport`` is the ABC for all transports. + +- public child ``DisksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DisksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDisksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DisksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/base.py index e87dad2be4f1..3ec5f0a4dbf8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/rest.py index 8166a6b0c451..c9862884f992 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/disks/transports/rest.py @@ -1176,6 +1176,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DisksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/client.py index dd7f739d2f07..92c1356a1aa8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/client.py @@ -108,7 +108,7 @@ class ExternalVpnGatewaysClient(metaclass=ExternalVpnGatewaysClientMeta): """The ExternalVpnGateways API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ExternalVpnGatewaysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/README.rst index cd3c299d7402..320610bc2897 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ExternalVpnGatewaysTransport` is the ABC for all transports. -- public child `ExternalVpnGatewaysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ExternalVpnGatewaysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseExternalVpnGatewaysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ExternalVpnGatewaysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ExternalVpnGatewaysTransport`` is the ABC for all transports. + +- public child ``ExternalVpnGatewaysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ExternalVpnGatewaysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseExternalVpnGatewaysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ExternalVpnGatewaysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/base.py index 9bf4f577d636..2daea3a317d3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/rest.py index 13f47d46437b..76a0327c0a9c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/external_vpn_gateways/transports/rest.py @@ -483,6 +483,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ExternalVpnGatewaysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/client.py index 8da2bb1a85b4..de3e31897918 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/client.py @@ -108,7 +108,7 @@ class FirewallPoliciesClient(metaclass=FirewallPoliciesClientMeta): """The FirewallPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = FirewallPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/README.rst index da518d84e3bc..9d5ff4de4201 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirewallPoliciesTransport` is the ABC for all transports. -- public child `FirewallPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirewallPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirewallPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirewallPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirewallPoliciesTransport`` is the ABC for all transports. + +- public child ``FirewallPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirewallPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirewallPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirewallPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/base.py index ca999aed4c70..47375e041d90 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/rest.py index a18536d420d3..3396c22aaf9d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewall_policies/transports/rest.py @@ -1373,6 +1373,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirewallPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/client.py index 29bbf1dccaed..ed2a2e43d28d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/client.py @@ -108,7 +108,7 @@ class FirewallsClient(metaclass=FirewallsClientMeta): """The Firewalls API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = FirewallsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/README.rst index 530e5fd90230..96ec573ff8db 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirewallsTransport` is the ABC for all transports. -- public child `FirewallsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirewallsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirewallsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirewallsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirewallsTransport`` is the ABC for all transports. + +- public child ``FirewallsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirewallsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirewallsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirewallsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/base.py index c3247911f2d9..b9ab0de54adb 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/rest.py index e5e70e45cf3c..7f243ada071c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/firewalls/transports/rest.py @@ -520,6 +520,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirewallsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/client.py index 89f866614e41..bd4687ad49a7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/client.py @@ -108,7 +108,7 @@ class ForwardingRulesClient(metaclass=ForwardingRulesClientMeta): """The ForwardingRules API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ForwardingRulesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/README.rst index 2031ab456efd..a0f5ffb4d25e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ForwardingRulesTransport` is the ABC for all transports. -- public child `ForwardingRulesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ForwardingRulesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseForwardingRulesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ForwardingRulesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ForwardingRulesTransport`` is the ABC for all transports. + +- public child ``ForwardingRulesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ForwardingRulesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseForwardingRulesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ForwardingRulesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/base.py index 42a3af5c528c..7a32fd652cfa 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/rest.py index 02a3b791ce42..bc42b91cfe95 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/forwarding_rules/transports/rest.py @@ -647,6 +647,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ForwardingRulesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/client.py index 46544d32a628..afbb3bf6b0f0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/client.py @@ -108,7 +108,7 @@ class FutureReservationsClient(metaclass=FutureReservationsClientMeta): """The FutureReservations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = FutureReservationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/README.rst index 1ad7099aa56e..f24ce6af2984 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FutureReservationsTransport` is the ABC for all transports. -- public child `FutureReservationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FutureReservationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFutureReservationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FutureReservationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FutureReservationsTransport`` is the ABC for all transports. + +- public child ``FutureReservationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FutureReservationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFutureReservationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FutureReservationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/base.py index ee71f25a9697..975634d98f47 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/rest.py index dd4e10d579e6..2c348d9540dd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/future_reservations/transports/rest.py @@ -539,6 +539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FutureReservationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/client.py index e11db81db7e9..fff853114634 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/client.py @@ -108,7 +108,7 @@ class GlobalAddressesClient(metaclass=GlobalAddressesClientMeta): """The GlobalAddresses API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = GlobalAddressesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/README.rst index 7b9ed8452847..fde4fceeffc0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalAddressesTransport` is the ABC for all transports. -- public child `GlobalAddressesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalAddressesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalAddressesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalAddressesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalAddressesTransport`` is the ABC for all transports. + +- public child ``GlobalAddressesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalAddressesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalAddressesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalAddressesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/base.py index 649bdda4617d..d2bd1b1f9217 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/rest.py index e75b3416d7f0..0a9efef902e6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_addresses/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalAddressesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/client.py index 29b6d23a7c9b..d90d319ecce8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/client.py @@ -108,7 +108,7 @@ class GlobalForwardingRulesClient(metaclass=GlobalForwardingRulesClientMeta): """The GlobalForwardingRules API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = GlobalForwardingRulesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/README.rst index 41f595a75512..932a36928fd4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalForwardingRulesTransport` is the ABC for all transports. -- public child `GlobalForwardingRulesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalForwardingRulesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalForwardingRulesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalForwardingRulesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalForwardingRulesTransport`` is the ABC for all transports. + +- public child ``GlobalForwardingRulesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalForwardingRulesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalForwardingRulesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalForwardingRulesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/base.py index e7d4f5345a16..42cbcb12ee41 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/rest.py index 1e6f2e678813..ea5723ddc6d3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_forwarding_rules/transports/rest.py @@ -594,6 +594,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalForwardingRulesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/client.py index 9be8bcdf970d..cbe7c8442c7c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/client.py @@ -110,7 +110,7 @@ class GlobalNetworkEndpointGroupsClient( """The GlobalNetworkEndpointGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = GlobalNetworkEndpointGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/README.rst index 1ef884d89ba4..40166d97f8f0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalNetworkEndpointGroupsTransport` is the ABC for all transports. -- public child `GlobalNetworkEndpointGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalNetworkEndpointGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalNetworkEndpointGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalNetworkEndpointGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalNetworkEndpointGroupsTransport`` is the ABC for all transports. + +- public child ``GlobalNetworkEndpointGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalNetworkEndpointGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalNetworkEndpointGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalNetworkEndpointGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/base.py index 7fbc860f2433..18b971dd64cc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/rest.py index a3d3d73022aa..d7dec9dffb6b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_network_endpoint_groups/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalNetworkEndpointGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/client.py index 0b83c38fa210..9dc0d7643cca 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/client.py @@ -105,7 +105,7 @@ class GlobalOperationsClient(metaclass=GlobalOperationsClientMeta): """The GlobalOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = GlobalOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/README.rst index 53a0a6ba4b78..709065f32a00 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalOperationsTransport` is the ABC for all transports. -- public child `GlobalOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalOperationsTransport`` is the ABC for all transports. + +- public child ``GlobalOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/base.py index 80e859753755..182f1e203978 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/rest.py index bb7092572823..721737eee482 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_operations/transports/rest.py @@ -428,6 +428,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/client.py index 3070466fc1fe..956cba090503 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/client.py @@ -107,7 +107,7 @@ class GlobalOrganizationOperationsClient( """The GlobalOrganizationOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -414,7 +418,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -513,7 +517,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -618,7 +622,7 @@ def __init__( self._universe_domain = GlobalOrganizationOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/README.rst index be5a7191aa48..4a1267b5e4bf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalOrganizationOperationsTransport` is the ABC for all transports. -- public child `GlobalOrganizationOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalOrganizationOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalOrganizationOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalOrganizationOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalOrganizationOperationsTransport`` is the ABC for all transports. + +- public child ``GlobalOrganizationOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalOrganizationOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalOrganizationOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalOrganizationOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/base.py index 97be6001281c..9248dc0a0012 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/rest.py index cdd3fe0ead36..6b24814bd460 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_organization_operations/transports/rest.py @@ -321,6 +321,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalOrganizationOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/client.py index 19f04060cff3..574f37814ef9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/client.py @@ -110,7 +110,7 @@ class GlobalPublicDelegatedPrefixesClient( """The GlobalPublicDelegatedPrefixes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/README.rst index b7dd1788312e..0531b7ff843c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalPublicDelegatedPrefixesTransport` is the ABC for all transports. -- public child `GlobalPublicDelegatedPrefixesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalPublicDelegatedPrefixesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalPublicDelegatedPrefixesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalPublicDelegatedPrefixesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalPublicDelegatedPrefixesTransport`` is the ABC for all transports. + +- public child ``GlobalPublicDelegatedPrefixesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalPublicDelegatedPrefixesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalPublicDelegatedPrefixesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalPublicDelegatedPrefixesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/base.py index 45bca8831598..cefae91c427a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/rest.py index 3dc5da4cb9cc..36c320c339ed 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_public_delegated_prefixes/transports/rest.py @@ -432,6 +432,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalPublicDelegatedPrefixesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/client.py index e5c3c37b7ea3..a6d3195b4271 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/client.py @@ -108,7 +108,7 @@ class GlobalVmExtensionPoliciesClient(metaclass=GlobalVmExtensionPoliciesClientM """The GlobalVmExtensionPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = GlobalVmExtensionPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/README.rst index 9218325d008a..e35d3b2af007 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalVmExtensionPoliciesTransport` is the ABC for all transports. -- public child `GlobalVmExtensionPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalVmExtensionPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalVmExtensionPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalVmExtensionPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalVmExtensionPoliciesTransport`` is the ABC for all transports. + +- public child ``GlobalVmExtensionPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalVmExtensionPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalVmExtensionPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalVmExtensionPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/base.py index b6949bd46b92..336a967c6f44 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/rest.py index f7ab88808d62..94a4637f56cd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/global_vm_extension_policies/transports/rest.py @@ -494,6 +494,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalVmExtensionPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/client.py index 3be7c317556b..a47e5fc502ff 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/client.py @@ -108,7 +108,7 @@ class HealthChecksClient(metaclass=HealthChecksClientMeta): """The HealthChecks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = HealthChecksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/README.rst index 3b5402d90312..efebd296f212 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HealthChecksTransport` is the ABC for all transports. -- public child `HealthChecksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HealthChecksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHealthChecksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HealthChecksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HealthChecksTransport`` is the ABC for all transports. + +- public child ``HealthChecksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HealthChecksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHealthChecksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HealthChecksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/base.py index 68beab9ce499..ed6559b720b1 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/rest.py index 727c6f035e47..3445f061c121 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/health_checks/transports/rest.py @@ -589,6 +589,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[HealthChecksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/client.py index 702c979806d0..3218f81d3f2b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/client.py @@ -104,7 +104,7 @@ class ImageFamilyViewsClient(metaclass=ImageFamilyViewsClientMeta): """The ImageFamilyViews API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -605,7 +609,7 @@ def __init__( self._universe_domain = ImageFamilyViewsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/README.rst index c62510ee57ac..2fc816570f86 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ImageFamilyViewsTransport` is the ABC for all transports. -- public child `ImageFamilyViewsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ImageFamilyViewsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseImageFamilyViewsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ImageFamilyViewsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ImageFamilyViewsTransport`` is the ABC for all transports. + +- public child ``ImageFamilyViewsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ImageFamilyViewsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseImageFamilyViewsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ImageFamilyViewsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/base.py index 6d6294cbb1d3..498e4d77fd90 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/rest.py index 9d5f374eeeba..1cf1a91e8175 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/image_family_views/transports/rest.py @@ -203,6 +203,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ImageFamilyViewsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/client.py index 43deb27934ae..03a4bef20298 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/client.py @@ -108,7 +108,7 @@ class ImagesClient(metaclass=ImagesClientMeta): """The Images API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = ImagesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/README.rst index 4d4c30630dc1..dd9e3b477504 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ImagesTransport` is the ABC for all transports. -- public child `ImagesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ImagesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseImagesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ImagesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ImagesTransport`` is the ABC for all transports. + +- public child ``ImagesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ImagesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseImagesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ImagesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/base.py index ca759197dbcd..22949c465d67 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/rest.py index 021a34206139..35f81c0253d8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/images/transports/rest.py @@ -729,6 +729,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ImagesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/client.py index 47e85065a52f..e5ccc155572a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/client.py @@ -115,7 +115,7 @@ class InstanceGroupManagerResizeRequestsClient( """The InstanceGroupManagerResizeRequests API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -422,7 +426,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -523,7 +527,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -630,7 +634,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/README.rst index a0e4e899d30c..7eeef33a7059 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceGroupManagerResizeRequestsTransport` is the ABC for all transports. -- public child `InstanceGroupManagerResizeRequestsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceGroupManagerResizeRequestsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceGroupManagerResizeRequestsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceGroupManagerResizeRequestsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceGroupManagerResizeRequestsTransport`` is the ABC for all transports. + +- public child ``InstanceGroupManagerResizeRequestsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceGroupManagerResizeRequestsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceGroupManagerResizeRequestsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceGroupManagerResizeRequestsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/base.py index 6d2e88b88c49..099616310618 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/rest.py index c18424ebbd0c..4677fdede2b8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_manager_resize_requests/transports/rest.py @@ -436,6 +436,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceGroupManagerResizeRequestsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/client.py index e381cb5c1737..1913be379764 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/client.py @@ -108,7 +108,7 @@ class InstanceGroupManagersClient(metaclass=InstanceGroupManagersClientMeta): """The InstanceGroupManagers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = InstanceGroupManagersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/README.rst index dd9373c3ddf2..ecbbc1f2cc32 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceGroupManagersTransport` is the ABC for all transports. -- public child `InstanceGroupManagersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceGroupManagersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceGroupManagersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceGroupManagersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceGroupManagersTransport`` is the ABC for all transports. + +- public child ``InstanceGroupManagersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceGroupManagersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceGroupManagersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceGroupManagersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/base.py index c3babbcdb2dd..7d4e973532c7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/rest.py index ba7b436f02e2..067da322141c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_group_managers/transports/rest.py @@ -1848,6 +1848,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceGroupManagersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/client.py index 9b1ef41eeab5..b58a9ae072d5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/client.py @@ -108,7 +108,7 @@ class InstanceGroupsClient(metaclass=InstanceGroupsClientMeta): """The InstanceGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = InstanceGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/README.rst index a8d509774e2e..c977e93b2874 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceGroupsTransport` is the ABC for all transports. -- public child `InstanceGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceGroupsTransport`` is the ABC for all transports. + +- public child ``InstanceGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/base.py index 425b2b809e29..5ed46d96d61e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/rest.py index ea96de5889e2..90775477e623 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_groups/transports/rest.py @@ -709,6 +709,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/client.py index 5b2bc2a269d4..573b4a5fe6fd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/client.py @@ -107,7 +107,7 @@ class InstanceSettingsServiceClient(metaclass=InstanceSettingsServiceClientMeta) """The InstanceSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = InstanceSettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/README.rst index 886a1d3cc987..f3e4963e3c9a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceSettingsServiceTransport` is the ABC for all transports. -- public child `InstanceSettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceSettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceSettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceSettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceSettingsServiceTransport`` is the ABC for all transports. + +- public child ``InstanceSettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceSettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceSettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceSettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/base.py index 44c3d3220024..aed41dc5a14d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/rest.py index 6d915a6c52dd..c7abf480a8a3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_settings_service/transports/rest.py @@ -257,6 +257,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceSettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/client.py index 8c33afb9c075..532b33990941 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/client.py @@ -108,7 +108,7 @@ class InstanceTemplatesClient(metaclass=InstanceTemplatesClientMeta): """The InstanceTemplates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = InstanceTemplatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/README.rst index 804386249c2b..c6f61c70b033 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceTemplatesTransport` is the ABC for all transports. -- public child `InstanceTemplatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceTemplatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceTemplatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceTemplatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceTemplatesTransport`` is the ABC for all transports. + +- public child ``InstanceTemplatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceTemplatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceTemplatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceTemplatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/base.py index ef636dfc680c..2004a667663a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/rest.py index a485090c7f5e..e57a6fa58fea 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instance_templates/transports/rest.py @@ -595,6 +595,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceTemplatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/client.py index 711e1d9f56ec..6732f3de9b45 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/client.py @@ -108,7 +108,7 @@ class InstancesClient(metaclass=InstancesClientMeta): """The Instances API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = InstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/README.rst index 452ca471f507..2834efc80854 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstancesTransport` is the ABC for all transports. -- public child `InstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstancesTransport`` is the ABC for all transports. + +- public child ``InstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/base.py index d0dd15a395d0..3b67c7778003 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/rest.py index b3183e68f714..0fd12eb84c87 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instances/transports/rest.py @@ -3256,6 +3256,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/client.py index f85298796262..5312ec7fcf26 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/client.py @@ -108,7 +108,7 @@ class InstantSnapshotGroupsClient(metaclass=InstantSnapshotGroupsClientMeta): """The InstantSnapshotGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = InstantSnapshotGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/README.rst index 0c729827bd2b..d02edc26ae2d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstantSnapshotGroupsTransport` is the ABC for all transports. -- public child `InstantSnapshotGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstantSnapshotGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstantSnapshotGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstantSnapshotGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstantSnapshotGroupsTransport`` is the ABC for all transports. + +- public child ``InstantSnapshotGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstantSnapshotGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstantSnapshotGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstantSnapshotGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/base.py index 836d044c64fc..bdf5c9d6a3d4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/rest.py index 55baed71ab81..f7d84f6eb3b2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshot_groups/transports/rest.py @@ -543,6 +543,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstantSnapshotGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/client.py index 4d56326549f8..b274984aedc2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/client.py @@ -108,7 +108,7 @@ class InstantSnapshotsClient(metaclass=InstantSnapshotsClientMeta): """The InstantSnapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = InstantSnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/README.rst index 8d75b3145d2e..48a2bb891830 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstantSnapshotsTransport` is the ABC for all transports. -- public child `InstantSnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstantSnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstantSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstantSnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstantSnapshotsTransport`` is the ABC for all transports. + +- public child ``InstantSnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstantSnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstantSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstantSnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/base.py index 4f0d6791aa6d..092487f0ebe7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/rest.py index 26102b1c112e..8768dd172fb5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/instant_snapshots/transports/rest.py @@ -649,6 +649,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstantSnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/client.py index 4d0d2ac74771..2946247ecd86 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/client.py @@ -110,7 +110,7 @@ class InterconnectAttachmentGroupsClient( """The InterconnectAttachmentGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -621,7 +625,7 @@ def __init__( self._universe_domain = InterconnectAttachmentGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/README.rst index 0834929c9de6..df645cdecc7f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectAttachmentGroupsTransport` is the ABC for all transports. -- public child `InterconnectAttachmentGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectAttachmentGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectAttachmentGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectAttachmentGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectAttachmentGroupsTransport`` is the ABC for all transports. + +- public child ``InterconnectAttachmentGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectAttachmentGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectAttachmentGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectAttachmentGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/base.py index 92c04197faf6..8ef060f94795 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/rest.py index dd9a525ddc18..aa1bbaa2bf66 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachment_groups/transports/rest.py @@ -664,6 +664,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectAttachmentGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/client.py index 15334e936f1b..44cb0d1a6868 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/client.py @@ -108,7 +108,7 @@ class InterconnectAttachmentsClient(metaclass=InterconnectAttachmentsClientMeta) """The InterconnectAttachments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = InterconnectAttachmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/README.rst index 39532a50c7e0..6fb7b9a998f3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectAttachmentsTransport` is the ABC for all transports. -- public child `InterconnectAttachmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectAttachmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectAttachmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectAttachmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectAttachmentsTransport`` is the ABC for all transports. + +- public child ``InterconnectAttachmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectAttachmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectAttachmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectAttachmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/base.py index 53863dec5d54..92d3e38bfb91 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/rest.py index c72f302b9ec0..486df6183f24 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_attachments/transports/rest.py @@ -604,6 +604,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectAttachmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/client.py index e7c76ea128c7..57fc5d02308f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/client.py @@ -108,7 +108,7 @@ class InterconnectGroupsClient(metaclass=InterconnectGroupsClientMeta): """The InterconnectGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = InterconnectGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/README.rst index aff13520eab7..9d1ce51d663d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectGroupsTransport` is the ABC for all transports. -- public child `InterconnectGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectGroupsTransport`` is the ABC for all transports. + +- public child ``InterconnectGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/base.py index 337dd510e3ba..7deadfe95ca4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/rest.py index c5d8a9bfcfe2..733659c4b0db 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_groups/transports/rest.py @@ -709,6 +709,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/client.py index 823ebe395a60..05703929b099 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/client.py @@ -105,7 +105,7 @@ class InterconnectLocationsClient(metaclass=InterconnectLocationsClientMeta): """The InterconnectLocations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = InterconnectLocationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/README.rst index a98caceeb490..50aad743a229 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectLocationsTransport` is the ABC for all transports. -- public child `InterconnectLocationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectLocationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectLocationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectLocationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectLocationsTransport`` is the ABC for all transports. + +- public child ``InterconnectLocationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectLocationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectLocationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectLocationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/base.py index 79b431a08f2e..c4cf52ae0b8f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/rest.py index 297bfff8ba44..c31467bfa8d5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_locations/transports/rest.py @@ -264,6 +264,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectLocationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/client.py index 3f46306686d2..01f444cee90b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/client.py @@ -107,7 +107,7 @@ class InterconnectRemoteLocationsClient( """The InterconnectRemoteLocations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = InterconnectRemoteLocationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/README.rst index 403edd2aacf5..15b3e70d7286 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectRemoteLocationsTransport` is the ABC for all transports. -- public child `InterconnectRemoteLocationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectRemoteLocationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectRemoteLocationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectRemoteLocationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectRemoteLocationsTransport`` is the ABC for all transports. + +- public child ``InterconnectRemoteLocationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectRemoteLocationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectRemoteLocationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectRemoteLocationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/base.py index ccb029cc6478..65291a67b4fa 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/rest.py index 23091f01e8b0..b9dd70cc70ee 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnect_remote_locations/transports/rest.py @@ -269,6 +269,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectRemoteLocationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/client.py index a53e1e8c49da..9cb95b2e58ff 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/client.py @@ -108,7 +108,7 @@ class InterconnectsClient(metaclass=InterconnectsClientMeta): """The Interconnects API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = InterconnectsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/README.rst index a4959f4e15f6..8593d0e6cbae 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectsTransport` is the ABC for all transports. -- public child `InterconnectsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectsTransport`` is the ABC for all transports. + +- public child ``InterconnectsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/base.py index f1dca2553178..7fe2efb1b0c7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/rest.py index 75699ff0287a..2e7605f4cb50 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/interconnects/transports/rest.py @@ -650,6 +650,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/client.py index aed43dddcb3c..42d138642751 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/client.py @@ -104,7 +104,7 @@ class LicenseCodesClient(metaclass=LicenseCodesClientMeta): """The LicenseCodes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -603,7 +607,7 @@ def __init__( self._universe_domain = LicenseCodesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/README.rst index d23b8f4b2467..bc2b0d3463ea 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LicenseCodesTransport` is the ABC for all transports. -- public child `LicenseCodesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LicenseCodesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLicenseCodesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LicenseCodesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LicenseCodesTransport`` is the ABC for all transports. + +- public child ``LicenseCodesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LicenseCodesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLicenseCodesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LicenseCodesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/base.py index ecbb685fa746..12dbe3878b0a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/rest.py index a02b75a0fdd8..1f097603d0d1 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/license_codes/transports/rest.py @@ -260,6 +260,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LicenseCodesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/client.py index 63811581f2aa..8a0e50d22735 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/client.py @@ -108,7 +108,7 @@ class LicensesClient(metaclass=LicensesClientMeta): """The Licenses API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = LicensesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/README.rst index 58d11e1a7eb5..310e46bc9c74 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LicensesTransport` is the ABC for all transports. -- public child `LicensesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LicensesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLicensesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LicensesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LicensesTransport`` is the ABC for all transports. + +- public child ``LicensesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LicensesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLicensesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LicensesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/base.py index 34ce938f3903..3b5ffb241110 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/rest.py index 50c032aff193..a09e2ef54e51 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/licenses/transports/rest.py @@ -578,6 +578,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LicensesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/client.py index 34825d5cb508..12b4d7af86f7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/client.py @@ -108,7 +108,7 @@ class MachineImagesClient(metaclass=MachineImagesClientMeta): """The MachineImages API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = MachineImagesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/README.rst index ddd13a3780af..91e0c8aae5aa 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MachineImagesTransport` is the ABC for all transports. -- public child `MachineImagesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MachineImagesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMachineImagesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MachineImagesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MachineImagesTransport`` is the ABC for all transports. + +- public child ``MachineImagesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MachineImagesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMachineImagesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MachineImagesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/base.py index ede1b208fc34..c296e47cea54 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/rest.py index 4a41b202b625..dbdac0d12b00 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_images/transports/rest.py @@ -584,6 +584,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MachineImagesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/client.py index 8b40a1edfdbf..a20be80b5bd9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/client.py @@ -105,7 +105,7 @@ class MachineTypesClient(metaclass=MachineTypesClientMeta): """The MachineTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = MachineTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/README.rst index ed40ee8f5462..4dcfe7c23385 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MachineTypesTransport` is the ABC for all transports. -- public child `MachineTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MachineTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMachineTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MachineTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MachineTypesTransport`` is the ABC for all transports. + +- public child ``MachineTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MachineTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMachineTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MachineTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/base.py index 815995aede1a..d3664241422c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/rest.py index a377bc05fb8c..dd70ee65c73a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/machine_types/transports/rest.py @@ -314,6 +314,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MachineTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/client.py index 2c97a475dea5..b0e58d88d523 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/client.py @@ -108,7 +108,7 @@ class NetworkAttachmentsClient(metaclass=NetworkAttachmentsClientMeta): """The NetworkAttachments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = NetworkAttachmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/README.rst index 597522afb370..77bc6885baed 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkAttachmentsTransport` is the ABC for all transports. -- public child `NetworkAttachmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkAttachmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkAttachmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkAttachmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkAttachmentsTransport`` is the ABC for all transports. + +- public child ``NetworkAttachmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkAttachmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkAttachmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkAttachmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/base.py index 8fbd31a40b80..d919cdd2c3b9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/rest.py index 9f2465f59252..bf5e3c0c1a8e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_attachments/transports/rest.py @@ -651,6 +651,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkAttachmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/client.py index 04bfd1e87760..60281c796bea 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/client.py @@ -110,7 +110,7 @@ class NetworkEdgeSecurityServicesClient( """The NetworkEdgeSecurityServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = NetworkEdgeSecurityServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/README.rst index 3c603c1b90cc..b5262a6b51cd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkEdgeSecurityServicesTransport` is the ABC for all transports. -- public child `NetworkEdgeSecurityServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkEdgeSecurityServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkEdgeSecurityServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkEdgeSecurityServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkEdgeSecurityServicesTransport`` is the ABC for all transports. + +- public child ``NetworkEdgeSecurityServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkEdgeSecurityServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkEdgeSecurityServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkEdgeSecurityServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/base.py index 440ed7459719..7ad47fe593ed 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/rest.py index bd958fe3779b..80c53f86f2f2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_edge_security_services/transports/rest.py @@ -435,6 +435,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkEdgeSecurityServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/client.py index ab0a7aa8e0fe..ea5d4dc8881b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/client.py @@ -108,7 +108,7 @@ class NetworkEndpointGroupsClient(metaclass=NetworkEndpointGroupsClientMeta): """The NetworkEndpointGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = NetworkEndpointGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/README.rst index 172d7d0b7d8d..eb3be0b4093d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkEndpointGroupsTransport` is the ABC for all transports. -- public child `NetworkEndpointGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkEndpointGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkEndpointGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkEndpointGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkEndpointGroupsTransport`` is the ABC for all transports. + +- public child ``NetworkEndpointGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkEndpointGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkEndpointGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkEndpointGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/base.py index 481add0b92a0..c7f511924dc6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/rest.py index bf2010cbccf3..ba1982b9aa31 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_endpoint_groups/transports/rest.py @@ -667,6 +667,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkEndpointGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/client.py index 4f05f9a8093f..3df45d16ee0e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/client.py @@ -108,7 +108,7 @@ class NetworkFirewallPoliciesClient(metaclass=NetworkFirewallPoliciesClientMeta) """The NetworkFirewallPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = NetworkFirewallPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/README.rst index 9b286ee5b8d1..03ed2a3e73c4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkFirewallPoliciesTransport` is the ABC for all transports. -- public child `NetworkFirewallPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkFirewallPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkFirewallPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkFirewallPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkFirewallPoliciesTransport`` is the ABC for all transports. + +- public child ``NetworkFirewallPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkFirewallPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkFirewallPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkFirewallPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/base.py index 9e3413b89fb7..851662fd847d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/rest.py index 7ee791c6f994..24808e8b1ab1 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_firewall_policies/transports/rest.py @@ -1328,6 +1328,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkFirewallPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/client.py index 9bd8a8441c9a..1d0dbb4aeb7d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/client.py @@ -105,7 +105,7 @@ class NetworkProfilesClient(metaclass=NetworkProfilesClientMeta): """The NetworkProfiles API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = NetworkProfilesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/README.rst index a640a3575956..b9ee5bdc47e7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkProfilesTransport` is the ABC for all transports. -- public child `NetworkProfilesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkProfilesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkProfilesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkProfilesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkProfilesTransport`` is the ABC for all transports. + +- public child ``NetworkProfilesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkProfilesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkProfilesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkProfilesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/base.py index 50a7d181f3bb..f3f197d235bd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/rest.py index e4643603c432..3a50bca95c37 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/network_profiles/transports/rest.py @@ -261,6 +261,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkProfilesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/client.py index 2ced20a899cc..7431a82a69c5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/client.py @@ -108,7 +108,7 @@ class NetworksClient(metaclass=NetworksClientMeta): """The Networks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = NetworksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/README.rst index d6735c6e0f0f..9eeb5d9187c7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworksTransport` is the ABC for all transports. -- public child `NetworksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworksTransport`` is the ABC for all transports. + +- public child ``NetworksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/base.py index 76cbd44fa0b0..55f74ac8d513 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/rest.py index da2552a18c43..907dc83f97d4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/networks/transports/rest.py @@ -920,6 +920,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/client.py index 893282afc36c..fa196d131cdf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/client.py @@ -108,7 +108,7 @@ class NodeGroupsClient(metaclass=NodeGroupsClientMeta): """The NodeGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = NodeGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/README.rst index 12d7d0818a62..f87033a02559 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeGroupsTransport` is the ABC for all transports. -- public child `NodeGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeGroupsTransport`` is the ABC for all transports. + +- public child ``NodeGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/base.py index c9a7a551613b..b7b1449099a6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/rest.py index 63ffcf0ef1f2..a8fed9b475e4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_groups/transports/rest.py @@ -966,6 +966,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/client.py index e23fbce9422b..3993f670de93 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/client.py @@ -108,7 +108,7 @@ class NodeTemplatesClient(metaclass=NodeTemplatesClientMeta): """The NodeTemplates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = NodeTemplatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/README.rst index f7d8910f07ec..ca407846760d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeTemplatesTransport` is the ABC for all transports. -- public child `NodeTemplatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeTemplatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeTemplatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeTemplatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeTemplatesTransport`` is the ABC for all transports. + +- public child ``NodeTemplatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeTemplatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeTemplatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeTemplatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/base.py index ba2411aa4d37..40249ff24551 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/rest.py index f239fbf10ca2..31d0b1a69ed8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_templates/transports/rest.py @@ -589,6 +589,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeTemplatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/client.py index f96737839a3a..5250adf64a0a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/client.py @@ -105,7 +105,7 @@ class NodeTypesClient(metaclass=NodeTypesClientMeta): """The NodeTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = NodeTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/README.rst index 1053ced918d8..8e0a48dd683f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeTypesTransport` is the ABC for all transports. -- public child `NodeTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeTypesTransport`` is the ABC for all transports. + +- public child ``NodeTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/base.py index f6046695285d..f29b8420cd7f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/rest.py index 48dc5e9fb300..e5c8d6ba5a39 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/node_types/transports/rest.py @@ -309,6 +309,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/client.py index 79d4b459464d..c3c505c12fa8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/client.py @@ -110,7 +110,7 @@ class OrganizationSecurityPoliciesClient( """The OrganizationSecurityPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -621,7 +625,7 @@ def __init__( self._universe_domain = OrganizationSecurityPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/README.rst index 1985deee532e..ecefdbba5679 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`OrganizationSecurityPoliciesTransport` is the ABC for all transports. -- public child `OrganizationSecurityPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `OrganizationSecurityPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseOrganizationSecurityPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `OrganizationSecurityPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``OrganizationSecurityPoliciesTransport`` is the ABC for all transports. + +- public child ``OrganizationSecurityPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``OrganizationSecurityPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseOrganizationSecurityPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``OrganizationSecurityPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/base.py index 0fa8bf0b753e..0a9c6a0d86c0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/rest.py index ef9186f191c7..2bc8047b3fd0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/organization_security_policies/transports/rest.py @@ -1049,6 +1049,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[OrganizationSecurityPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/client.py index cbb1a30275cf..2c64a23e0b74 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/client.py @@ -108,7 +108,7 @@ class PacketMirroringsClient(metaclass=PacketMirroringsClientMeta): """The PacketMirrorings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = PacketMirroringsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/README.rst index 969577889999..a6bfdd7b1fdc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PacketMirroringsTransport` is the ABC for all transports. -- public child `PacketMirroringsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PacketMirroringsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePacketMirroringsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PacketMirroringsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PacketMirroringsTransport`` is the ABC for all transports. + +- public child ``PacketMirroringsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PacketMirroringsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePacketMirroringsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PacketMirroringsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/base.py index f6ca21b53c50..02ead19b9bb4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/rest.py index b7a6403ca27b..6dae7e86504a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/packet_mirrorings/transports/rest.py @@ -539,6 +539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PacketMirroringsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/client.py index fd830359ad6c..ffb49862f396 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/client.py @@ -108,7 +108,7 @@ class PreviewFeaturesClient(metaclass=PreviewFeaturesClientMeta): """The PreviewFeatures API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = PreviewFeaturesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/README.rst index 808797795f8f..842e5308bb7a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PreviewFeaturesTransport` is the ABC for all transports. -- public child `PreviewFeaturesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PreviewFeaturesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePreviewFeaturesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PreviewFeaturesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PreviewFeaturesTransport`` is the ABC for all transports. + +- public child ``PreviewFeaturesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PreviewFeaturesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePreviewFeaturesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PreviewFeaturesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/base.py index fc36ea26f1bf..d3bb0cf612a9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/rest.py index 9476b1eea30c..408fc00a6f75 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/preview_features/transports/rest.py @@ -313,6 +313,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PreviewFeaturesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/client.py index 0943c1327265..b2c0f50dcc2d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/client.py @@ -108,7 +108,7 @@ class ProjectsClient(metaclass=ProjectsClientMeta): """The Projects API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = ProjectsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/README.rst index e832f0d51f32..ed2db28f745e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProjectsTransport` is the ABC for all transports. -- public child `ProjectsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProjectsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProjectsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProjectsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProjectsTransport`` is the ABC for all transports. + +- public child ``ProjectsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProjectsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProjectsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProjectsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/base.py index aa6352fcdfc0..3ee72b630f04 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/rest.py index 261f79b78548..923a3d151b2d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/projects/transports/rest.py @@ -978,6 +978,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProjectsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/client.py index 60c0be4083cb..5e128efa8dee 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/client.py @@ -108,7 +108,7 @@ class PublicAdvertisedPrefixesClient(metaclass=PublicAdvertisedPrefixesClientMet """The PublicAdvertisedPrefixes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = PublicAdvertisedPrefixesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/README.rst index 58df8e61afd1..49134c3896db 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PublicAdvertisedPrefixesTransport` is the ABC for all transports. -- public child `PublicAdvertisedPrefixesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PublicAdvertisedPrefixesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePublicAdvertisedPrefixesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PublicAdvertisedPrefixesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PublicAdvertisedPrefixesTransport`` is the ABC for all transports. + +- public child ``PublicAdvertisedPrefixesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PublicAdvertisedPrefixesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePublicAdvertisedPrefixesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PublicAdvertisedPrefixesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/base.py index 9050a6faa16e..e7abc348f23d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/rest.py index 8a1ea5907a71..e9740a955849 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_advertised_prefixes/transports/rest.py @@ -540,6 +540,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PublicAdvertisedPrefixesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/client.py index aa48306790e1..86ad183380a6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/client.py @@ -108,7 +108,7 @@ class PublicDelegatedPrefixesClient(metaclass=PublicDelegatedPrefixesClientMeta) """The PublicDelegatedPrefixes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = PublicDelegatedPrefixesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/README.rst index bf9786004e2f..802b7328bf16 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PublicDelegatedPrefixesTransport` is the ABC for all transports. -- public child `PublicDelegatedPrefixesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PublicDelegatedPrefixesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePublicDelegatedPrefixesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PublicDelegatedPrefixesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PublicDelegatedPrefixesTransport`` is the ABC for all transports. + +- public child ``PublicDelegatedPrefixesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PublicDelegatedPrefixesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePublicDelegatedPrefixesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PublicDelegatedPrefixesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/base.py index 8653f3868e91..3507bfa9f097 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/rest.py index 68d98ff07150..092e520359da 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/public_delegated_prefixes/transports/rest.py @@ -600,6 +600,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PublicDelegatedPrefixesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/client.py index 0e009cdba8e2..2515cd34e9c9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/client.py @@ -108,7 +108,7 @@ class RegionAutoscalersClient(metaclass=RegionAutoscalersClientMeta): """The RegionAutoscalers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionAutoscalersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/README.rst index baedafa8805e..e8ea3fe9ab18 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionAutoscalersTransport` is the ABC for all transports. -- public child `RegionAutoscalersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionAutoscalersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionAutoscalersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionAutoscalersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionAutoscalersTransport`` is the ABC for all transports. + +- public child ``RegionAutoscalersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionAutoscalersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionAutoscalersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionAutoscalersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/base.py index 6b3b8872d14f..2434dfa3941e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/rest.py index c67651c2892c..ec7b2df7b029 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_autoscalers/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionAutoscalersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/client.py index 36c1becffeb7..6693d609576a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/client.py @@ -108,7 +108,7 @@ class RegionBackendBucketsClient(metaclass=RegionBackendBucketsClientMeta): """The RegionBackendBuckets API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionBackendBucketsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/README.rst index a2c52d83d838..e7e3f32be99b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionBackendBucketsTransport` is the ABC for all transports. -- public child `RegionBackendBucketsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionBackendBucketsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionBackendBucketsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionBackendBucketsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionBackendBucketsTransport`` is the ABC for all transports. + +- public child ``RegionBackendBucketsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionBackendBucketsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionBackendBucketsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionBackendBucketsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/base.py index 987c4c068712..ecd0cc964c02 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/rest.py index 082243b4e1d4..dfa56c0f00a6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_buckets/transports/rest.py @@ -651,6 +651,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionBackendBucketsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/client.py index fdb6302453b6..98953ff34bcf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/client.py @@ -108,7 +108,7 @@ class RegionBackendServicesClient(metaclass=RegionBackendServicesClientMeta): """The RegionBackendServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionBackendServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/README.rst index 99f43788575c..6efaddab1d5c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionBackendServicesTransport` is the ABC for all transports. -- public child `RegionBackendServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionBackendServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionBackendServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionBackendServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionBackendServicesTransport`` is the ABC for all transports. + +- public child ``RegionBackendServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionBackendServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionBackendServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionBackendServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/base.py index d5c72f965819..b95068151871 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/rest.py index 96121de7b46c..3b7f3259f6f9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_backend_services/transports/rest.py @@ -824,6 +824,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionBackendServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/client.py index 9997dea6447f..9f1fd110cac2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/client.py @@ -108,7 +108,7 @@ class RegionCommitmentsClient(metaclass=RegionCommitmentsClientMeta): """The RegionCommitments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionCommitmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/README.rst index ce87aa795eac..568a06ef3572 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionCommitmentsTransport` is the ABC for all transports. -- public child `RegionCommitmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionCommitmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionCommitmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionCommitmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionCommitmentsTransport`` is the ABC for all transports. + +- public child ``RegionCommitmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionCommitmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionCommitmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionCommitmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/base.py index 6073ffeac6be..41a3710af36c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/rest.py index b085e048bbe2..929d87fe3db6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_commitments/transports/rest.py @@ -540,6 +540,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionCommitmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/client.py index 4f7ac8a93275..20192ea81f12 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/client.py @@ -110,7 +110,7 @@ class RegionCompositeHealthChecksClient( """The RegionCompositeHealthChecks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionCompositeHealthChecksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/README.rst index 97612e7c69fa..c671f10ebb42 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionCompositeHealthChecksTransport` is the ABC for all transports. -- public child `RegionCompositeHealthChecksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionCompositeHealthChecksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionCompositeHealthChecksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionCompositeHealthChecksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionCompositeHealthChecksTransport`` is the ABC for all transports. + +- public child ``RegionCompositeHealthChecksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionCompositeHealthChecksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionCompositeHealthChecksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionCompositeHealthChecksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/base.py index 825ed67501fc..60a048547b90 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/rest.py index b2c5a3d85b22..d744772076d3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_composite_health_checks/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionCompositeHealthChecksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/client.py index 784d97f5898d..fe5973880da8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/client.py @@ -107,7 +107,7 @@ class RegionDiskSettingsClient(metaclass=RegionDiskSettingsClientMeta): """The RegionDiskSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = RegionDiskSettingsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/README.rst index b927e04ecf26..fc1d6f9d951f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionDiskSettingsTransport` is the ABC for all transports. -- public child `RegionDiskSettingsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionDiskSettingsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionDiskSettingsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionDiskSettingsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionDiskSettingsTransport`` is the ABC for all transports. + +- public child ``RegionDiskSettingsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionDiskSettingsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionDiskSettingsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionDiskSettingsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/base.py index 54620a49aa73..db8eb39ba728 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/rest.py index a50ef25d058f..74550f0162dc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_settings/transports/rest.py @@ -257,6 +257,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionDiskSettingsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/client.py index 23e2767120e0..346917fef275 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/client.py @@ -105,7 +105,7 @@ class RegionDiskTypesClient(metaclass=RegionDiskTypesClientMeta): """The RegionDiskTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = RegionDiskTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/README.rst index aab6392320a5..4bc73728d645 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionDiskTypesTransport` is the ABC for all transports. -- public child `RegionDiskTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionDiskTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionDiskTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionDiskTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionDiskTypesTransport`` is the ABC for all transports. + +- public child ``RegionDiskTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionDiskTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionDiskTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionDiskTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/base.py index 74c789455e65..9af27d0c0590 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/rest.py index cd0850a2c1a0..651f7feb3d53 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disk_types/transports/rest.py @@ -259,6 +259,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionDiskTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/client.py index 7fffc4191304..d4b240551945 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/client.py @@ -108,7 +108,7 @@ class RegionDisksClient(metaclass=RegionDisksClientMeta): """The RegionDisks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RegionDisksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/README.rst index e9e430ff6f3d..9845c29f10e3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionDisksTransport` is the ABC for all transports. -- public child `RegionDisksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionDisksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionDisksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionDisksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionDisksTransport`` is the ABC for all transports. + +- public child ``RegionDisksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionDisksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionDisksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionDisksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/base.py index cf4e8c051bdf..187789b56352 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/rest.py index 16b52175c210..774134308b45 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_disks/transports/rest.py @@ -1081,6 +1081,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionDisksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/client.py index 3375966bccf2..66f4407d3aa7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/client.py @@ -115,7 +115,7 @@ class RegionHealthAggregationPoliciesClient( """The RegionHealthAggregationPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -422,7 +426,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -521,7 +525,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/README.rst index 09c62d1c2230..6ee13339bc2e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthAggregationPoliciesTransport` is the ABC for all transports. -- public child `RegionHealthAggregationPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthAggregationPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthAggregationPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthAggregationPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthAggregationPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionHealthAggregationPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthAggregationPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthAggregationPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthAggregationPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/base.py index 5f6fc026b54f..b341b4f03279 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/rest.py index 3608fb4f7555..28293f19fde4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_aggregation_policies/transports/rest.py @@ -553,6 +553,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthAggregationPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/client.py index 1639a22248b7..4e4e06c7cb60 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/client.py @@ -108,7 +108,7 @@ class RegionHealthCheckServicesClient(metaclass=RegionHealthCheckServicesClientM """The RegionHealthCheckServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionHealthCheckServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/README.rst index d6dfc409ab15..8dbfe234aade 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthCheckServicesTransport` is the ABC for all transports. -- public child `RegionHealthCheckServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthCheckServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthCheckServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthCheckServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthCheckServicesTransport`` is the ABC for all transports. + +- public child ``RegionHealthCheckServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthCheckServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthCheckServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthCheckServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/base.py index 68f909c83f98..f1e81124ca7b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/rest.py index 8e09f0bdfad0..ed2615199e40 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_check_services/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthCheckServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/client.py index 45d0ac000ba5..8a5e8feaa357 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/client.py @@ -108,7 +108,7 @@ class RegionHealthChecksClient(metaclass=RegionHealthChecksClientMeta): """The RegionHealthChecks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionHealthChecksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/README.rst index 2f361d99ebbc..77fd6d188bc6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthChecksTransport` is the ABC for all transports. -- public child `RegionHealthChecksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthChecksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthChecksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthChecksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthChecksTransport`` is the ABC for all transports. + +- public child ``RegionHealthChecksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthChecksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthChecksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthChecksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/base.py index 8e1f20c03ba6..503d4dc6695a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/rest.py index baa6ff4a9f5c..24f6d81d0033 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_checks/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthChecksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/client.py index ff81a08b21bc..f883fc64b578 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/client.py @@ -108,7 +108,7 @@ class RegionHealthSourcesClient(metaclass=RegionHealthSourcesClientMeta): """The RegionHealthSources API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionHealthSourcesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/README.rst index 8365e0728465..b098080ff5bc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthSourcesTransport` is the ABC for all transports. -- public child `RegionHealthSourcesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthSourcesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthSourcesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthSourcesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthSourcesTransport`` is the ABC for all transports. + +- public child ``RegionHealthSourcesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthSourcesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthSourcesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthSourcesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/base.py index 69ebf9b7eeaf..e190cefbbc29 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/rest.py index be72767136f9..d4c1b986568b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_health_sources/transports/rest.py @@ -537,6 +537,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthSourcesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/client.py index f6cd8782d495..7dd04d155bbf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/client.py @@ -115,7 +115,7 @@ class RegionInstanceGroupManagerResizeRequestsClient( """The RegionInstanceGroupManagerResizeRequests API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -422,7 +426,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -525,7 +529,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -632,7 +636,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/README.rst index 4440a5138aa0..ac5841a6d546 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceGroupManagerResizeRequestsTransport` is the ABC for all transports. -- public child `RegionInstanceGroupManagerResizeRequestsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceGroupManagerResizeRequestsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceGroupManagerResizeRequestsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceGroupManagerResizeRequestsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceGroupManagerResizeRequestsTransport`` is the ABC for all transports. + +- public child ``RegionInstanceGroupManagerResizeRequestsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceGroupManagerResizeRequestsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceGroupManagerResizeRequestsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceGroupManagerResizeRequestsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/base.py index 507118a68db2..3383a8460339 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/rest.py index 931d7f62983d..370748153851 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_manager_resize_requests/transports/rest.py @@ -438,6 +438,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceGroupManagerResizeRequestsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/client.py index 3e686f0fb68e..a87b286c018c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/client.py @@ -110,7 +110,7 @@ class RegionInstanceGroupManagersClient( """The RegionInstanceGroupManagers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionInstanceGroupManagersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/README.rst index 57ef26008635..a3f74cd30679 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceGroupManagersTransport` is the ABC for all transports. -- public child `RegionInstanceGroupManagersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceGroupManagersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceGroupManagersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceGroupManagersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceGroupManagersTransport`` is the ABC for all transports. + +- public child ``RegionInstanceGroupManagersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceGroupManagersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceGroupManagersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceGroupManagersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/base.py index 550c6ef4287d..b47af65d6fb1 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/rest.py index 1fd91783d38e..9b79168835ee 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_group_managers/transports/rest.py @@ -1728,6 +1728,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceGroupManagersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/client.py index 86bd8306ce92..6d23cc647676 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/client.py @@ -108,7 +108,7 @@ class RegionInstanceGroupsClient(metaclass=RegionInstanceGroupsClientMeta): """The RegionInstanceGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionInstanceGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/README.rst index d6a6c7775f98..b798bb2438f0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceGroupsTransport` is the ABC for all transports. -- public child `RegionInstanceGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceGroupsTransport`` is the ABC for all transports. + +- public child ``RegionInstanceGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/base.py index 7193e2955a5b..22104ccecb82 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/rest.py index 912eb722fb7a..519f147366ea 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_groups/transports/rest.py @@ -435,6 +435,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/client.py index d0092c8099a7..471a8edd0f64 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/client.py @@ -108,7 +108,7 @@ class RegionInstanceTemplatesClient(metaclass=RegionInstanceTemplatesClientMeta) """The RegionInstanceTemplates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionInstanceTemplatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/README.rst index 261e60771474..ea64dd44f8cc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceTemplatesTransport` is the ABC for all transports. -- public child `RegionInstanceTemplatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceTemplatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceTemplatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceTemplatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceTemplatesTransport`` is the ABC for all transports. + +- public child ``RegionInstanceTemplatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceTemplatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceTemplatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceTemplatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/base.py index 759f1f9e9f56..36ca6588410a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/rest.py index 0669461af948..a9e4bb951083 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instance_templates/transports/rest.py @@ -371,6 +371,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceTemplatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/client.py index 78c874bffb1e..03106bf20599 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/client.py @@ -107,7 +107,7 @@ class RegionInstancesClient(metaclass=RegionInstancesClientMeta): """The RegionInstances API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = RegionInstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/README.rst index d32a0b4eca29..7dfbb6d5199c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstancesTransport` is the ABC for all transports. -- public child `RegionInstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstancesTransport`` is the ABC for all transports. + +- public child ``RegionInstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/base.py index 0de37a2675d8..84256dade808 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/rest.py index b092b954e7a0..6db2f79c4643 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instances/transports/rest.py @@ -203,6 +203,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/client.py index 56ecdc0964df..c460571b2354 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/client.py @@ -110,7 +110,7 @@ class RegionInstantSnapshotGroupsClient( """The RegionInstantSnapshotGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionInstantSnapshotGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/README.rst index d97f862b7aab..c91ce3084e01 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstantSnapshotGroupsTransport` is the ABC for all transports. -- public child `RegionInstantSnapshotGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstantSnapshotGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstantSnapshotGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstantSnapshotGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstantSnapshotGroupsTransport`` is the ABC for all transports. + +- public child ``RegionInstantSnapshotGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstantSnapshotGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstantSnapshotGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstantSnapshotGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/base.py index 1981c7f4a361..3f4eaf4538ef 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/rest.py index c5a2a3659ba8..feadf0d11b4d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshot_groups/transports/rest.py @@ -546,6 +546,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstantSnapshotGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/client.py index d1125192f096..db69f06859d5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/client.py @@ -108,7 +108,7 @@ class RegionInstantSnapshotsClient(metaclass=RegionInstantSnapshotsClientMeta): """The RegionInstantSnapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionInstantSnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/README.rst index d91f1e70c759..5c5dfbef391a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstantSnapshotsTransport` is the ABC for all transports. -- public child `RegionInstantSnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstantSnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstantSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstantSnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstantSnapshotsTransport`` is the ABC for all transports. + +- public child ``RegionInstantSnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstantSnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstantSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstantSnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/base.py index 9f7cba7b284c..83452f94ac71 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/rest.py index c306dbdae13b..6cbfb2b89cec 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_instant_snapshots/transports/rest.py @@ -594,6 +594,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstantSnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/client.py index 4c190f9cf00e..b7a4a65b7fc2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/client.py @@ -105,7 +105,7 @@ class RegionMultiMigMembersClient(metaclass=RegionMultiMigMembersClientMeta): """The RegionMultiMigMembers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = RegionMultiMigMembersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/README.rst index c73a4e65516a..417206c11789 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionMultiMigMembersTransport` is the ABC for all transports. -- public child `RegionMultiMigMembersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionMultiMigMembersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionMultiMigMembersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionMultiMigMembersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionMultiMigMembersTransport`` is the ABC for all transports. + +- public child ``RegionMultiMigMembersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionMultiMigMembersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionMultiMigMembersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionMultiMigMembersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/base.py index f6a127d47661..9fc622e16f0c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/rest.py index e0b5963d8a03..dd632294b89d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_mig_members/transports/rest.py @@ -260,6 +260,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionMultiMigMembersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/client.py index 81a95ca0810c..ec71ed546294 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/client.py @@ -108,7 +108,7 @@ class RegionMultiMigsClient(metaclass=RegionMultiMigsClientMeta): """The RegionMultiMigs API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = RegionMultiMigsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/README.rst index f2417981d0ba..163e59c8c819 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionMultiMigsTransport` is the ABC for all transports. -- public child `RegionMultiMigsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionMultiMigsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionMultiMigsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionMultiMigsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionMultiMigsTransport`` is the ABC for all transports. + +- public child ``RegionMultiMigsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionMultiMigsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionMultiMigsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionMultiMigsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/base.py index 205e8a327589..683f8aaf8ca7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/rest.py index 7206c9754484..936af2d733c8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_multi_migs/transports/rest.py @@ -365,6 +365,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionMultiMigsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/client.py index ace18e7a84cc..b48f366286ce 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/client.py @@ -110,7 +110,7 @@ class RegionNetworkEndpointGroupsClient( """The RegionNetworkEndpointGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionNetworkEndpointGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/README.rst index 219c26060241..e8571d46b424 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNetworkEndpointGroupsTransport` is the ABC for all transports. -- public child `RegionNetworkEndpointGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNetworkEndpointGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNetworkEndpointGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNetworkEndpointGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNetworkEndpointGroupsTransport`` is the ABC for all transports. + +- public child ``RegionNetworkEndpointGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNetworkEndpointGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNetworkEndpointGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNetworkEndpointGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/base.py index b728d4f962ae..c734ecbe7bdf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/rest.py index b927ded1678d..e37094fcccaa 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_endpoint_groups/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNetworkEndpointGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/client.py index e60afcb1c663..2a38a1159882 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/client.py @@ -110,7 +110,7 @@ class RegionNetworkFirewallPoliciesClient( """The RegionNetworkFirewallPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/README.rst index c1f92c8931dc..681974e0a1be 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNetworkFirewallPoliciesTransport` is the ABC for all transports. -- public child `RegionNetworkFirewallPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNetworkFirewallPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNetworkFirewallPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNetworkFirewallPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNetworkFirewallPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionNetworkFirewallPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNetworkFirewallPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNetworkFirewallPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNetworkFirewallPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/base.py index 3a54b34d9652..aea3902c6b4a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/rest.py index 74b70562f3c6..c2c73a172b47 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_firewall_policies/transports/rest.py @@ -1159,6 +1159,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNetworkFirewallPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/client.py index 608a75ce5384..3889acececcc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/client.py @@ -108,7 +108,7 @@ class RegionNetworkPoliciesClient(metaclass=RegionNetworkPoliciesClientMeta): """The RegionNetworkPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionNetworkPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/README.rst index 6caf6fb7e221..1263826ebd29 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNetworkPoliciesTransport` is the ABC for all transports. -- public child `RegionNetworkPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNetworkPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNetworkPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNetworkPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNetworkPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionNetworkPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNetworkPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNetworkPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNetworkPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/base.py index f55aabcd7ef8..63e1562196fc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/rest.py index f034385a2448..0330e262800b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_network_policies/transports/rest.py @@ -883,6 +883,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNetworkPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/client.py index d8ea9d8165be..0a40994f81e9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/client.py @@ -110,7 +110,7 @@ class RegionNotificationEndpointsClient( """The RegionNotificationEndpoints API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionNotificationEndpointsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/README.rst index 306a49513d33..fce4db242cf4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNotificationEndpointsTransport` is the ABC for all transports. -- public child `RegionNotificationEndpointsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNotificationEndpointsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNotificationEndpointsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNotificationEndpointsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNotificationEndpointsTransport`` is the ABC for all transports. + +- public child ``RegionNotificationEndpointsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNotificationEndpointsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNotificationEndpointsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNotificationEndpointsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/base.py index f1d910926de7..f74920375c5a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/rest.py index bf8c74bc75b8..9b7dfdf2b833 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_notification_endpoints/transports/rest.py @@ -496,6 +496,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNotificationEndpointsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/client.py index ec2fd1aad787..2d3efc0c22c4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/client.py @@ -105,7 +105,7 @@ class RegionOperationsClient(metaclass=RegionOperationsClientMeta): """The RegionOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = RegionOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/README.rst index aba34e5181d4..1c7b7c6c6452 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionOperationsTransport` is the ABC for all transports. -- public child `RegionOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionOperationsTransport`` is the ABC for all transports. + +- public child ``RegionOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/base.py index 14bc76304227..c2cb3375d447 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/rest.py index cb977b5a50a4..676a8221a7be 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_operations/transports/rest.py @@ -369,6 +369,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/client.py index 0db08f0f23fa..bd386a428a58 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/client.py @@ -108,7 +108,7 @@ class RegionSecurityPoliciesClient(metaclass=RegionSecurityPoliciesClientMeta): """The RegionSecurityPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionSecurityPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/README.rst index bc650e76362b..5310bdd303a6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSecurityPoliciesTransport` is the ABC for all transports. -- public child `RegionSecurityPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSecurityPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSecurityPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSecurityPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSecurityPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionSecurityPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSecurityPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSecurityPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSecurityPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/base.py index a69983268bdc..2c8d2acb01b7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/rest.py index c3396ee63556..a02e167f0d72 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_security_policies/transports/rest.py @@ -702,6 +702,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSecurityPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/client.py index 21d400d3a720..112a65a3f850 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/client.py @@ -107,7 +107,7 @@ class RegionSnapshotSettingsClient(metaclass=RegionSnapshotSettingsClientMeta): """The RegionSnapshotSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -612,7 +616,7 @@ def __init__( self._universe_domain = RegionSnapshotSettingsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/README.rst index e038678325da..05c3038f9214 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSnapshotSettingsTransport` is the ABC for all transports. -- public child `RegionSnapshotSettingsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSnapshotSettingsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSnapshotSettingsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSnapshotSettingsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSnapshotSettingsTransport`` is the ABC for all transports. + +- public child ``RegionSnapshotSettingsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSnapshotSettingsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSnapshotSettingsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSnapshotSettingsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/base.py index 9e019faad1c6..16ac70b3a26b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/rest.py index f132455e41c5..0037c228c1c7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshot_settings/transports/rest.py @@ -258,6 +258,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSnapshotSettingsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/client.py index 92810547913a..6a415b6d4fbf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/client.py @@ -108,7 +108,7 @@ class RegionSnapshotsClient(metaclass=RegionSnapshotsClientMeta): """The RegionSnapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = RegionSnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/README.rst index 6e6d48822512..cf2b3e5d77f5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSnapshotsTransport` is the ABC for all transports. -- public child `RegionSnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSnapshotsTransport`` is the ABC for all transports. + +- public child ``RegionSnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/base.py index fb019bd837e4..a4bfd784cb40 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/rest.py index 644b9d7566e5..b18f58591d1c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_snapshots/transports/rest.py @@ -588,6 +588,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/client.py index 2dccd5c3d7be..d4ad234ea98e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/client.py @@ -108,7 +108,7 @@ class RegionSslCertificatesClient(metaclass=RegionSslCertificatesClientMeta): """The RegionSslCertificates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionSslCertificatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/README.rst index 54eded552b4b..c9bc987092c7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSslCertificatesTransport` is the ABC for all transports. -- public child `RegionSslCertificatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSslCertificatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSslCertificatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSslCertificatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSslCertificatesTransport`` is the ABC for all transports. + +- public child ``RegionSslCertificatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSslCertificatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSslCertificatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSslCertificatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/base.py index dd9d49c9c709..c8a15074f9c0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/rest.py index 1437f44663c3..58287390419a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_certificates/transports/rest.py @@ -429,6 +429,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSslCertificatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/client.py index df15b91bdf21..997c145ef16e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/client.py @@ -108,7 +108,7 @@ class RegionSslPoliciesClient(metaclass=RegionSslPoliciesClientMeta): """The RegionSslPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionSslPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/README.rst index 807618502323..38caef77a5db 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSslPoliciesTransport` is the ABC for all transports. -- public child `RegionSslPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSslPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSslPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSslPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSslPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionSslPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSslPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSslPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSslPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/base.py index a4c4e350bcab..0356e8d5847f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/rest.py index 79727b5743cb..2f40f2b1b6b5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_ssl_policies/transports/rest.py @@ -538,6 +538,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSslPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/client.py index 9f6445a362e2..6dc65a3d1b68 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/client.py @@ -108,7 +108,7 @@ class RegionTargetHttpProxiesClient(metaclass=RegionTargetHttpProxiesClientMeta) """The RegionTargetHttpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionTargetHttpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/README.rst index 23946266929c..4b4a06daf2cf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionTargetHttpProxiesTransport` is the ABC for all transports. -- public child `RegionTargetHttpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionTargetHttpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionTargetHttpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionTargetHttpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionTargetHttpProxiesTransport`` is the ABC for all transports. + +- public child ``RegionTargetHttpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionTargetHttpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionTargetHttpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionTargetHttpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/base.py index 53e9dd239391..0abd71b54bec 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/rest.py index 0c4343a11935..5b2f031efd2a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_http_proxies/transports/rest.py @@ -484,6 +484,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionTargetHttpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/client.py index 98a227092e67..f423622b8f90 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/client.py @@ -108,7 +108,7 @@ class RegionTargetHttpsProxiesClient(metaclass=RegionTargetHttpsProxiesClientMet """The RegionTargetHttpsProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionTargetHttpsProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/README.rst index cf57d11919f8..cf8b6e9c5d95 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionTargetHttpsProxiesTransport` is the ABC for all transports. -- public child `RegionTargetHttpsProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionTargetHttpsProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionTargetHttpsProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionTargetHttpsProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionTargetHttpsProxiesTransport`` is the ABC for all transports. + +- public child ``RegionTargetHttpsProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionTargetHttpsProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionTargetHttpsProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionTargetHttpsProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/base.py index 3517c711a1ba..5700aa8804c5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/rest.py index 341325a67d16..b330aef2765e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_https_proxies/transports/rest.py @@ -597,6 +597,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionTargetHttpsProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/client.py index 0a168ee33795..f48c3753e245 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/client.py @@ -108,7 +108,7 @@ class RegionTargetTcpProxiesClient(metaclass=RegionTargetTcpProxiesClientMeta): """The RegionTargetTcpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionTargetTcpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/README.rst index 1885a11205b3..ada713b1429e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionTargetTcpProxiesTransport` is the ABC for all transports. -- public child `RegionTargetTcpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionTargetTcpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionTargetTcpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionTargetTcpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionTargetTcpProxiesTransport`` is the ABC for all transports. + +- public child ``RegionTargetTcpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionTargetTcpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionTargetTcpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionTargetTcpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/base.py index 2dd288939a95..4b304a34515e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/rest.py index 6e12bb39d7b4..3b185de3f166 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_target_tcp_proxies/transports/rest.py @@ -429,6 +429,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionTargetTcpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/client.py index 7ee4ce7ca2e9..512547d13e1d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/client.py @@ -108,7 +108,7 @@ class RegionUrlMapsClient(metaclass=RegionUrlMapsClientMeta): """The RegionUrlMaps API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RegionUrlMapsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/README.rst index 1720d990b31c..ac5b043653cb 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionUrlMapsTransport` is the ABC for all transports. -- public child `RegionUrlMapsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionUrlMapsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionUrlMapsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionUrlMapsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionUrlMapsTransport`` is the ABC for all transports. + +- public child ``RegionUrlMapsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionUrlMapsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionUrlMapsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionUrlMapsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/base.py index 1dd002632051..c050adc875d7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/rest.py index 7cccfadf9b2c..d6e5ac915a9a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_url_maps/transports/rest.py @@ -643,6 +643,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionUrlMapsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/client.py index 1e1fcbb3a936..7753a1e7b035 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/client.py @@ -105,7 +105,7 @@ class RegionZonesClient(metaclass=RegionZonesClientMeta): """The RegionZones API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = RegionZonesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/README.rst index a1291ba0f15f..9cdcc421a8f8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionZonesTransport` is the ABC for all transports. -- public child `RegionZonesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionZonesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionZonesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionZonesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionZonesTransport`` is the ABC for all transports. + +- public child ``RegionZonesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionZonesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionZonesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionZonesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/base.py index dad6754d1b1b..a3910dc8e5ad 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/rest.py index 2a10d3463614..a7fef41069cf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/region_zones/transports/rest.py @@ -201,6 +201,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionZonesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/client.py index 3a3e7591774d..b534eaeb930d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/client.py @@ -105,7 +105,7 @@ class RegionsClient(metaclass=RegionsClientMeta): """The Regions API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = RegionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/README.rst index 2dc13d2da1b9..d0dde73d6fe7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionsTransport` is the ABC for all transports. -- public child `RegionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionsTransport`` is the ABC for all transports. + +- public child ``RegionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/base.py index 9ea7a665a0df..ce63f4111aa9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/rest.py index 75a2520efa4b..56d91b0c6910 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/regions/transports/rest.py @@ -253,6 +253,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/client.py index fafd42da14f7..d8ff820c6bbc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/client.py @@ -108,7 +108,7 @@ class ReservationBlocksClient(metaclass=ReservationBlocksClientMeta): """The ReservationBlocks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ReservationBlocksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/README.rst index ead61ffe03c8..98651b5a7928 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationBlocksTransport` is the ABC for all transports. -- public child `ReservationBlocksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationBlocksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationBlocksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationBlocksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationBlocksTransport`` is the ABC for all transports. + +- public child ``ReservationBlocksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationBlocksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationBlocksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationBlocksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/base.py index 3ac48360fc4e..77381bb05ba3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/rest.py index 20242a326dcc..e375ca70addf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_blocks/transports/rest.py @@ -491,6 +491,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationBlocksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/client.py index e831a1a30950..ef8802d98972 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/client.py @@ -108,7 +108,7 @@ class ReservationSlotsClient(metaclass=ReservationSlotsClientMeta): """The ReservationSlots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ReservationSlotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/README.rst index 3e36921f3fe9..a67caf4b207b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationSlotsTransport` is the ABC for all transports. -- public child `ReservationSlotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationSlotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationSlotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationSlotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationSlotsTransport`` is the ABC for all transports. + +- public child ``ReservationSlotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationSlotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationSlotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationSlotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/base.py index 7c363e67a367..124e7f638968 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/rest.py index ddc8112fe60e..1539e808c0f9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_slots/transports/rest.py @@ -374,6 +374,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationSlotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/client.py index 55a0973f9692..d617c1522743 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/client.py @@ -108,7 +108,7 @@ class ReservationSubBlocksClient(metaclass=ReservationSubBlocksClientMeta): """The ReservationSubBlocks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ReservationSubBlocksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/README.rst index 5c23b59d8c44..30d2fda9b293 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationSubBlocksTransport` is the ABC for all transports. -- public child `ReservationSubBlocksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationSubBlocksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationSubBlocksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationSubBlocksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationSubBlocksTransport`` is the ABC for all transports. + +- public child ``ReservationSubBlocksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationSubBlocksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationSubBlocksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationSubBlocksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/base.py index 27342c4cf95b..219a03f085e6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/rest.py index eec0a9c414e6..f62c24939b1b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservation_sub_blocks/transports/rest.py @@ -602,6 +602,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationSubBlocksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/client.py index bb69c14f6eea..31037adef1a8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/client.py @@ -108,7 +108,7 @@ class ReservationsClient(metaclass=ReservationsClientMeta): """The Reservations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = ReservationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/README.rst index 26061ab20fdb..09fa3f67538b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationsTransport` is the ABC for all transports. -- public child `ReservationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationsTransport`` is the ABC for all transports. + +- public child ``ReservationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/base.py index 26e84fcb2a4c..7373603b9af8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/rest.py index 9aa9109408c3..f3645999a0bb 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/reservations/transports/rest.py @@ -754,6 +754,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/client.py index dddf05fc6bad..27815cb9da9c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/client.py @@ -108,7 +108,7 @@ class ResourcePoliciesClient(metaclass=ResourcePoliciesClientMeta): """The ResourcePolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ResourcePoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/README.rst index e08e21143072..3ee061bde40b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ResourcePoliciesTransport` is the ABC for all transports. -- public child `ResourcePoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ResourcePoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseResourcePoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ResourcePoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ResourcePoliciesTransport`` is the ABC for all transports. + +- public child ``ResourcePoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ResourcePoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseResourcePoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ResourcePoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/base.py index f8249734730e..e36af0abc7b6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/rest.py index 3c510c59f5e2..c348af982f28 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/resource_policies/transports/rest.py @@ -649,6 +649,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ResourcePoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/client.py index 3ef688f3cd81..f5cff82faf21 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/client.py @@ -108,7 +108,7 @@ class RolloutPlansClient(metaclass=RolloutPlansClientMeta): """The RolloutPlans API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RolloutPlansClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/README.rst index 3be1f939604c..f6c299524dec 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RolloutPlansTransport` is the ABC for all transports. -- public child `RolloutPlansGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RolloutPlansGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRolloutPlansRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RolloutPlansRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RolloutPlansTransport`` is the ABC for all transports. + +- public child ``RolloutPlansGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RolloutPlansGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRolloutPlansRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RolloutPlansRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/base.py index 24d69ca61bb9..c77f18dffc2b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/rest.py index 28edb8d58009..fc98d022d94a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollout_plans/transports/rest.py @@ -367,6 +367,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RolloutPlansRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/client.py index 3d0cc78d5d6f..acc19eac0ebd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/client.py @@ -108,7 +108,7 @@ class RolloutsClient(metaclass=RolloutsClientMeta): """The Rollouts API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RolloutsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/README.rst index 425b888bfbc9..b5936eb0a6d1 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RolloutsTransport` is the ABC for all transports. -- public child `RolloutsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RolloutsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRolloutsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RolloutsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RolloutsTransport`` is the ABC for all transports. + +- public child ``RolloutsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RolloutsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRolloutsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RolloutsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/base.py index 7186635924b3..b8cc0c8b0215 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/rest.py index c9fba8beafea..b9362a13955d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/rollouts/transports/rest.py @@ -359,6 +359,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RolloutsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/client.py index 4097c5e727db..9025352ebe05 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/client.py @@ -108,7 +108,7 @@ class RoutersClient(metaclass=RoutersClientMeta): """The Routers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RoutersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/README.rst index 1d5f11e98ca6..e826f22dc584 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RoutersTransport` is the ABC for all transports. -- public child `RoutersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RoutersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRoutersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RoutersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RoutersTransport`` is the ABC for all transports. + +- public child ``RoutersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RoutersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRoutersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RoutersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/base.py index f809756e91f1..65f93419bd93 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/rest.py index a67b0de96d73..91feeb7e7b70 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routers/transports/rest.py @@ -1413,6 +1413,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RoutersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/client.py index ab706f6ae554..ce1aace0d67e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/client.py @@ -108,7 +108,7 @@ class RoutesClient(metaclass=RoutesClientMeta): """The Routes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RoutesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/README.rst index ece3f327f1db..59b24c7b8607 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RoutesTransport` is the ABC for all transports. -- public child `RoutesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RoutesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRoutesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RoutesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RoutesTransport`` is the ABC for all transports. + +- public child ``RoutesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RoutesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRoutesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RoutesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/base.py index cfb3ac6037dd..a6d4bc95961e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/rest.py index 83b9b5fac751..8a2f367a6d5f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/routes/transports/rest.py @@ -413,6 +413,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RoutesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/client.py index f9d90a8d5212..1d57e0879474 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/client.py @@ -108,7 +108,7 @@ class SecurityPoliciesClient(metaclass=SecurityPoliciesClientMeta): """The SecurityPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = SecurityPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/README.rst index 0ccd9c25c159..1061ac468325 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SecurityPoliciesTransport` is the ABC for all transports. -- public child `SecurityPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SecurityPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSecurityPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SecurityPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SecurityPoliciesTransport`` is the ABC for all transports. + +- public child ``SecurityPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SecurityPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSecurityPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SecurityPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/base.py index 0e5ab1e15615..de617b92c034 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/rest.py index 44da391cb31e..ff6a441aa638 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/security_policies/transports/rest.py @@ -871,6 +871,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SecurityPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/client.py index 10b122d0db6b..399236f7c531 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/client.py @@ -108,7 +108,7 @@ class ServiceAttachmentsClient(metaclass=ServiceAttachmentsClientMeta): """The ServiceAttachments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ServiceAttachmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/README.rst index 5f7c8c3d83fa..19ad54459a96 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServiceAttachmentsTransport` is the ABC for all transports. -- public child `ServiceAttachmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServiceAttachmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServiceAttachmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServiceAttachmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServiceAttachmentsTransport`` is the ABC for all transports. + +- public child ``ServiceAttachmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServiceAttachmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServiceAttachmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServiceAttachmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/base.py index 61350b1fbc73..d0fc1e13f7d9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/rest.py index 120a3c1b6c8d..eb6a258d6d33 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/service_attachments/transports/rest.py @@ -651,6 +651,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ServiceAttachmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/client.py index 32b900220f95..a670b758d24c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/client.py @@ -108,7 +108,7 @@ class SnapshotGroupsClient(metaclass=SnapshotGroupsClientMeta): """The SnapshotGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SnapshotGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/README.rst index 847feb6bc471..d07d9d3dfac5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnapshotGroupsTransport` is the ABC for all transports. -- public child `SnapshotGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnapshotGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnapshotGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnapshotGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnapshotGroupsTransport`` is the ABC for all transports. + +- public child ``SnapshotGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnapshotGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnapshotGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnapshotGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/base.py index d81c1583324d..d7ff28339ccb 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/rest.py index b4b8bff509b3..9e87252501b4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_groups/transports/rest.py @@ -536,6 +536,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SnapshotGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/client.py index 18d0260d818c..a5f73af3ab5c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/client.py @@ -107,7 +107,7 @@ class SnapshotSettingsServiceClient(metaclass=SnapshotSettingsServiceClientMeta) """The SnapshotSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = SnapshotSettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/README.rst index 68c71745a361..0a85f1b33870 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnapshotSettingsServiceTransport` is the ABC for all transports. -- public child `SnapshotSettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnapshotSettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnapshotSettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnapshotSettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnapshotSettingsServiceTransport`` is the ABC for all transports. + +- public child ``SnapshotSettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnapshotSettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnapshotSettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnapshotSettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/base.py index 44f050b7d643..b204c6724fec 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/rest.py index 16d140eb7a0e..5e39c7e760b5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshot_settings_service/transports/rest.py @@ -257,6 +257,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SnapshotSettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/client.py index b8bd82685201..68fb38f359f5 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/client.py @@ -108,7 +108,7 @@ class SnapshotsClient(metaclass=SnapshotsClientMeta): """The Snapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/README.rst index b80ab398fdb8..ed5078590d73 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnapshotsTransport` is the ABC for all transports. -- public child `SnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnapshotsTransport`` is the ABC for all transports. + +- public child ``SnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/base.py index 0bd0be84c1c4..d81b51c4b477 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/rest.py index 54a48bdc5fd0..fd9590b1d782 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/snapshots/transports/rest.py @@ -634,6 +634,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/client.py index 3cde14ada239..070a74860ab0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/client.py @@ -108,7 +108,7 @@ class SslCertificatesClient(metaclass=SslCertificatesClientMeta): """The SslCertificates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = SslCertificatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/README.rst index adaacba051cd..54488d94eb3c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SslCertificatesTransport` is the ABC for all transports. -- public child `SslCertificatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SslCertificatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSslCertificatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SslCertificatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SslCertificatesTransport`` is the ABC for all transports. + +- public child ``SslCertificatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SslCertificatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSslCertificatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SslCertificatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/base.py index ddb0bb52eb4f..7440698f3942 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/rest.py index 8e25398b30a7..803c4ed3b500 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_certificates/transports/rest.py @@ -485,6 +485,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SslCertificatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/client.py index b35d6c64286c..0bde83e63726 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/client.py @@ -108,7 +108,7 @@ class SslPoliciesClient(metaclass=SslPoliciesClientMeta): """The SslPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SslPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/README.rst index 90c2c96db3de..c0fe30afaa5b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SslPoliciesTransport` is the ABC for all transports. -- public child `SslPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SslPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSslPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SslPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SslPoliciesTransport`` is the ABC for all transports. + +- public child ``SslPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SslPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSslPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SslPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/base.py index fcbcac6d55e6..7435ee4c4b8b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/rest.py index 92e423fad419..4e650d6247ca 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/ssl_policies/transports/rest.py @@ -587,6 +587,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SslPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/client.py index 3ada28b79f4b..082bddfe852e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/client.py @@ -105,7 +105,7 @@ class StoragePoolTypesClient(metaclass=StoragePoolTypesClientMeta): """The StoragePoolTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = StoragePoolTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/README.rst index eb123fb58f19..ab99ff687c6b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`StoragePoolTypesTransport` is the ABC for all transports. -- public child `StoragePoolTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `StoragePoolTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseStoragePoolTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `StoragePoolTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``StoragePoolTypesTransport`` is the ABC for all transports. + +- public child ``StoragePoolTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``StoragePoolTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseStoragePoolTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``StoragePoolTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/base.py index 44642907f366..6da204c91f33 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/rest.py index dd42327c05be..462540fb606c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pool_types/transports/rest.py @@ -318,6 +318,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[StoragePoolTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/client.py index a395d453774e..de46639ddb50 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/client.py @@ -108,7 +108,7 @@ class StoragePoolsClient(metaclass=StoragePoolsClientMeta): """The StoragePools API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = StoragePoolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/README.rst index f0bef4dd7f4e..989226566992 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`StoragePoolsTransport` is the ABC for all transports. -- public child `StoragePoolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `StoragePoolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseStoragePoolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `StoragePoolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``StoragePoolsTransport`` is the ABC for all transports. + +- public child ``StoragePoolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``StoragePoolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseStoragePoolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``StoragePoolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/base.py index d4baf966100d..0e8771718802 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/rest.py index f0efb927c0f6..29ca8a6bbcf2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/storage_pools/transports/rest.py @@ -699,6 +699,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[StoragePoolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/client.py index d59a2b7d4316..ceb627310b93 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/client.py @@ -108,7 +108,7 @@ class SubnetworksClient(metaclass=SubnetworksClientMeta): """The Subnetworks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SubnetworksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/README.rst index eb4732e3d7f1..bb2d45cfcb5c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SubnetworksTransport` is the ABC for all transports. -- public child `SubnetworksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SubnetworksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSubnetworksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SubnetworksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SubnetworksTransport`` is the ABC for all transports. + +- public child ``SubnetworksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SubnetworksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSubnetworksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SubnetworksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/base.py index 11e7b32654ec..6c0eef956b0f 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/rest.py index e99befaaf8ca..9382763f90bf 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/subnetworks/transports/rest.py @@ -811,6 +811,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SubnetworksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/client.py index 3c2369afcadf..6e5277e8ce3b 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/client.py @@ -108,7 +108,7 @@ class TargetGrpcProxiesClient(metaclass=TargetGrpcProxiesClientMeta): """The TargetGrpcProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetGrpcProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/README.rst index 52ce0ef73ecc..11862ec53a41 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetGrpcProxiesTransport` is the ABC for all transports. -- public child `TargetGrpcProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetGrpcProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetGrpcProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetGrpcProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetGrpcProxiesTransport`` is the ABC for all transports. + +- public child ``TargetGrpcProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetGrpcProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetGrpcProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetGrpcProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/base.py index f2ce43fb7999..70704c38e01d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/rest.py index 11e37b541723..08cef93f1f6a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_grpc_proxies/transports/rest.py @@ -480,6 +480,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetGrpcProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/client.py index 5867e6d26df3..268b4cb2dcdd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/client.py @@ -108,7 +108,7 @@ class TargetHttpProxiesClient(metaclass=TargetHttpProxiesClientMeta): """The TargetHttpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetHttpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/README.rst index d7c24090549d..1096201d216a 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetHttpProxiesTransport` is the ABC for all transports. -- public child `TargetHttpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetHttpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetHttpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetHttpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetHttpProxiesTransport`` is the ABC for all transports. + +- public child ``TargetHttpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetHttpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetHttpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetHttpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/base.py index d65f6307de5c..43957d2aaf36 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/rest.py index 93fed1c1bf66..febc37f25fba 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_http_proxies/transports/rest.py @@ -593,6 +593,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetHttpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/client.py index 46c9a6fcbf2b..62244ad7eabe 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/client.py @@ -108,7 +108,7 @@ class TargetHttpsProxiesClient(metaclass=TargetHttpsProxiesClientMeta): """The TargetHttpsProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetHttpsProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/README.rst index e4a84921dff6..a977b5c1e9d7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetHttpsProxiesTransport` is the ABC for all transports. -- public child `TargetHttpsProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetHttpsProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetHttpsProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetHttpsProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetHttpsProxiesTransport`` is the ABC for all transports. + +- public child ``TargetHttpsProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetHttpsProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetHttpsProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetHttpsProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/base.py index 25347813db15..aad7b8207d64 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/rest.py index 91c736842f78..0e74d8febf07 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_https_proxies/transports/rest.py @@ -818,6 +818,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetHttpsProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/client.py index a9bfe8db5b51..e27eee1775b2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/client.py @@ -108,7 +108,7 @@ class TargetInstancesClient(metaclass=TargetInstancesClientMeta): """The TargetInstances API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = TargetInstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/README.rst index f09666e9ceff..d98f543bdcc0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetInstancesTransport` is the ABC for all transports. -- public child `TargetInstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetInstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetInstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetInstancesTransport`` is the ABC for all transports. + +- public child ``TargetInstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetInstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetInstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/base.py index 5dfde8b86761..ad607fb18d42 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/rest.py index b54bc61da392..16682bd3f553 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_instances/transports/rest.py @@ -542,6 +542,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetInstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/client.py index d6ba8053975c..ed9a7fead7fd 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/client.py @@ -108,7 +108,7 @@ class TargetPoolsClient(metaclass=TargetPoolsClientMeta): """The TargetPools API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = TargetPoolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/README.rst index 661878aeb974..8d69e5b6f1ac 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetPoolsTransport` is the ABC for all transports. -- public child `TargetPoolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetPoolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetPoolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetPoolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetPoolsTransport`` is the ABC for all transports. + +- public child ``TargetPoolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetPoolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetPoolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetPoolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/base.py index 4c425c3a2e61..b504377deac7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/rest.py index de99d4a080b0..99e81683d7ab 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_pools/transports/rest.py @@ -867,6 +867,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetPoolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/client.py index f1b6bbe80b1e..e37fec318d4d 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/client.py @@ -108,7 +108,7 @@ class TargetSslProxiesClient(metaclass=TargetSslProxiesClientMeta): """The TargetSslProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = TargetSslProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/README.rst index c4fd45add5f1..5046d955895e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetSslProxiesTransport` is the ABC for all transports. -- public child `TargetSslProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetSslProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetSslProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetSslProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetSslProxiesTransport`` is the ABC for all transports. + +- public child ``TargetSslProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetSslProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetSslProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetSslProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/base.py index d5e5c228481e..b727938c3a9c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/rest.py index 9b9cb18778e5..80bd4fb9ed12 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_ssl_proxies/transports/rest.py @@ -707,6 +707,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetSslProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/client.py index 054dd079b2c8..9aa99f761899 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/client.py @@ -108,7 +108,7 @@ class TargetTcpProxiesClient(metaclass=TargetTcpProxiesClientMeta): """The TargetTcpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = TargetTcpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/README.rst index 3040978bc37f..e7b7b4662228 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetTcpProxiesTransport` is the ABC for all transports. -- public child `TargetTcpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetTcpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetTcpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetTcpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetTcpProxiesTransport`` is the ABC for all transports. + +- public child ``TargetTcpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetTcpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetTcpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetTcpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/base.py index b08ff767ab7c..0a122b37d421 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/rest.py index 7dc4c1a3e9c4..7852ce743c42 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_tcp_proxies/transports/rest.py @@ -597,6 +597,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetTcpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/client.py index ba0e1b9220a6..c2328fc7cc53 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/client.py @@ -108,7 +108,7 @@ class TargetVpnGatewaysClient(metaclass=TargetVpnGatewaysClientMeta): """The TargetVpnGateways API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetVpnGatewaysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/README.rst index 729cd35a377a..3d2a7424b7c0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetVpnGatewaysTransport` is the ABC for all transports. -- public child `TargetVpnGatewaysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetVpnGatewaysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetVpnGatewaysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetVpnGatewaysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetVpnGatewaysTransport`` is the ABC for all transports. + +- public child ``TargetVpnGatewaysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetVpnGatewaysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetVpnGatewaysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetVpnGatewaysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/base.py index 15984235259a..d76d4372bec6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/rest.py index 845b5a8714a0..34c3a7c631c8 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/target_vpn_gateways/transports/rest.py @@ -540,6 +540,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetVpnGatewaysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/client.py index 54668e26b968..89dd496edb49 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/client.py @@ -108,7 +108,7 @@ class UrlMapsClient(metaclass=UrlMapsClientMeta): """The UrlMaps API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = UrlMapsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/README.rst index 03f5dbb958f1..4c9396f6b7b2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UrlMapsTransport` is the ABC for all transports. -- public child `UrlMapsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UrlMapsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUrlMapsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UrlMapsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UrlMapsTransport`` is the ABC for all transports. + +- public child ``UrlMapsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UrlMapsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUrlMapsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UrlMapsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/base.py index 534064afd69e..d9c241d66b09 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/rest.py index 2b06acdab1bb..108bb8602409 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/url_maps/transports/rest.py @@ -685,6 +685,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UrlMapsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/client.py index 9681123be4f8..be9873e356c7 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/client.py @@ -108,7 +108,7 @@ class VpnGatewaysClient(metaclass=VpnGatewaysClientMeta): """The VpnGateways API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = VpnGatewaysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/README.rst index 1c5d4b400fdb..72c21068bf55 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VpnGatewaysTransport` is the ABC for all transports. -- public child `VpnGatewaysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VpnGatewaysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVpnGatewaysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VpnGatewaysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VpnGatewaysTransport`` is the ABC for all transports. + +- public child ``VpnGatewaysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VpnGatewaysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVpnGatewaysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VpnGatewaysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/base.py index 95bc6334f371..8ccbd2139919 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/rest.py index b76f711dfdeb..6e48367ebebc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_gateways/transports/rest.py @@ -591,6 +591,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VpnGatewaysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/client.py index 2fad6094fd6f..17cee216d2b3 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/client.py @@ -108,7 +108,7 @@ class VpnTunnelsClient(metaclass=VpnTunnelsClientMeta): """The VpnTunnels API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = VpnTunnelsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/README.rst index 1bf067e72e57..ca4198c01932 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VpnTunnelsTransport` is the ABC for all transports. -- public child `VpnTunnelsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VpnTunnelsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVpnTunnelsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VpnTunnelsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VpnTunnelsTransport`` is the ABC for all transports. + +- public child ``VpnTunnelsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VpnTunnelsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVpnTunnelsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VpnTunnelsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/base.py index c8bf7e256eaf..c944a2a5b134 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/rest.py index 9cc78f887a13..07677508c8fc 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/vpn_tunnels/transports/rest.py @@ -528,6 +528,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VpnTunnelsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/client.py index dd25f9398eea..916c52df7c11 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/client.py @@ -108,7 +108,7 @@ class WireGroupsClient(metaclass=WireGroupsClientMeta): """The WireGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = WireGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/README.rst index e5b31cbf4bec..c32f386d68a2 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WireGroupsTransport` is the ABC for all transports. -- public child `WireGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WireGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWireGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WireGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WireGroupsTransport`` is the ABC for all transports. + +- public child ``WireGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WireGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWireGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WireGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/base.py index 5f1614d53dc3..d1dcaaecf099 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/rest.py index ab6739979721..6cf47a1d876e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/wire_groups/transports/rest.py @@ -409,6 +409,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WireGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/client.py index f07b2544a190..d1624c0f579e 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/client.py @@ -105,7 +105,7 @@ class ZoneOperationsClient(metaclass=ZoneOperationsClientMeta): """The ZoneOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = ZoneOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/README.rst index eb93acc7255e..fbf08fe656d4 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ZoneOperationsTransport` is the ABC for all transports. -- public child `ZoneOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ZoneOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseZoneOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ZoneOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ZoneOperationsTransport`` is the ABC for all transports. + +- public child ``ZoneOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ZoneOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseZoneOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ZoneOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/base.py index a8a405888b96..b3e504ec0cc0 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/rest.py index c4f190c90180..3cb190c784d6 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_operations/transports/rest.py @@ -369,6 +369,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ZoneOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/client.py index 94e88b6aad2a..cea4843ef0b9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/client.py @@ -108,7 +108,7 @@ class ZoneVmExtensionPoliciesClient(metaclass=ZoneVmExtensionPoliciesClientMeta) """The ZoneVmExtensionPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = ZoneVmExtensionPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/README.rst index 35339b868a6f..86107a652935 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ZoneVmExtensionPoliciesTransport` is the ABC for all transports. -- public child `ZoneVmExtensionPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ZoneVmExtensionPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseZoneVmExtensionPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ZoneVmExtensionPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ZoneVmExtensionPoliciesTransport`` is the ABC for all transports. + +- public child ``ZoneVmExtensionPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ZoneVmExtensionPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseZoneVmExtensionPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ZoneVmExtensionPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/base.py index c2c2136835be..6575643802ed 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/rest.py index 3a214e812f7e..867eeb84cfa9 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zone_vm_extension_policies/transports/rest.py @@ -427,6 +427,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ZoneVmExtensionPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/client.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/client.py index b2a639827266..cfe0f9d09880 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/client.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/client.py @@ -105,7 +105,7 @@ class ZonesClient(metaclass=ZonesClientMeta): """The Zones API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = ZonesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/README.rst b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/README.rst index 6c572dcd2511..6eff58d762a1 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/README.rst +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ZonesTransport` is the ABC for all transports. -- public child `ZonesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ZonesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseZonesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ZonesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ZonesTransport`` is the ABC for all transports. + +- public child ``ZonesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ZonesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseZonesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ZonesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/base.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/base.py index e923070fa93e..0d926742d336 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/base.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/rest.py b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/rest.py index 4bd099b1821e..0c4ba0f7143c 100644 --- a/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/rest.py +++ b/packages/google-cloud-compute-v1beta/google/cloud/compute_v1beta/services/zones/transports/rest.py @@ -251,6 +251,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ZonesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute-v1beta/noxfile.py b/packages/google-cloud-compute-v1beta/noxfile.py index b9911fb35639..906f9ff4508c 100644 --- a/packages/google-cloud-compute-v1beta/noxfile.py +++ b/packages/google-cloud-compute-v1beta/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-compute-v1beta/setup.py b/packages/google-cloud-compute-v1beta/setup.py index b1880ffe332b..6647d20b4e5a 100644 --- a/packages/google-cloud-compute-v1beta/setup.py +++ b/packages/google-cloud-compute-v1beta/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-compute-v1beta" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-compute-v1beta/testing/constraints-3.7.txt b/packages/google-cloud-compute-v1beta/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-compute-v1beta/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-compute-v1beta/testing/constraints-3.8.txt b/packages/google-cloud-compute-v1beta/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-compute-v1beta/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-compute-v1beta/testing/constraints-3.9.txt b/packages/google-cloud-compute-v1beta/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-compute-v1beta/testing/constraints-3.9.txt +++ b/packages/google-cloud-compute-v1beta/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_accelerator_types.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_accelerator_types.py index 75038fc1e664..9fe14c5f652d 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_accelerator_types.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_accelerator_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AcceleratorTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): AcceleratorTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AcceleratorTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2004,8 +2009,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2076,17 +2082,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = AcceleratorTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2146,8 +2155,9 @@ def test_get_rest_bad_request(request_type=compute.GetAcceleratorTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2228,17 +2238,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = AcceleratorTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AcceleratorTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2289,8 +2299,9 @@ def test_list_rest_bad_request(request_type=compute.ListAcceleratorTypesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2359,17 +2370,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = AcceleratorTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2524,11 +2537,14 @@ def test_accelerator_types_base_transport(): def test_accelerator_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AcceleratorTypesTransport( @@ -2549,9 +2565,12 @@ def test_accelerator_types_base_transport_with_credentials_file(): def test_accelerator_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AcceleratorTypesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_addresses.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_addresses.py index f8905413a979..24fc417c5b41 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_addresses.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_addresses.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AddressesClient._get_default_mtls_endpoint(None) is None assert AddressesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AddressesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AddressesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3843,8 +3847,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3913,17 +3918,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AddressesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AddressesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3976,8 +3983,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4080,17 +4088,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4139,8 +4145,9 @@ def test_get_rest_bad_request(request_type=compute.GetAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4239,17 +4246,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4298,8 +4303,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4492,17 +4498,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4551,8 +4555,9 @@ def test_list_rest_bad_request(request_type=compute.ListAddressesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4619,17 +4624,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4678,8 +4681,9 @@ def test_move_rest_bad_request(request_type=compute.MoveAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4864,17 +4868,15 @@ def test_move_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_move") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_move_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_move") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4923,8 +4925,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsAddressReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5106,17 +5109,17 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AddressesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5169,8 +5172,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5309,17 +5313,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AddressesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.AddressesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AddressesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5581,11 +5588,14 @@ def test_addresses_base_transport(): def test_addresses_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.addresses.transports.AddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.addresses.transports.AddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AddressesTransport( @@ -5605,9 +5615,12 @@ def test_addresses_base_transport_with_credentials_file(): def test_addresses_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.addresses.transports.AddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.addresses.transports.AddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AddressesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_advice.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_advice.py index 3a5a920a599e..7b111da89121 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_advice.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_advice.py @@ -114,6 +114,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AdviceClient._get_default_mtls_endpoint(None) is None assert AdviceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AdviceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AdviceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1398,8 +1400,9 @@ def test_calendar_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1537,17 +1540,17 @@ def test_calendar_mode_rest_interceptors(null_interceptor): ) client = AdviceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdviceRestInterceptor, "post_calendar_mode" - ) as post, mock.patch.object( - transports.AdviceRestInterceptor, "post_calendar_mode_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdviceRestInterceptor, "pre_calendar_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdviceRestInterceptor, "post_calendar_mode" + ) as post, + mock.patch.object( + transports.AdviceRestInterceptor, "post_calendar_mode_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AdviceRestInterceptor, "pre_calendar_mode") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1658,11 +1661,14 @@ def test_advice_base_transport(): def test_advice_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.advice.transports.AdviceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.advice.transports.AdviceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdviceTransport( @@ -1682,9 +1688,12 @@ def test_advice_base_transport_with_credentials_file(): def test_advice_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.advice.transports.AdviceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.advice.transports.AdviceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdviceTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_autoscalers.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_autoscalers.py index 2e74a0e3adf5..665731bb34e2 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_autoscalers.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_autoscalers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutoscalersClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AutoscalersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AutoscalersClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3862,8 +3866,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3934,17 +3939,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalersRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3997,8 +4004,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4103,17 +4111,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4164,8 +4170,9 @@ def test_get_rest_bad_request(request_type=compute.GetAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4248,17 +4255,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_get") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4307,8 +4312,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4525,17 +4531,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4586,8 +4590,9 @@ def test_list_rest_bad_request(request_type=compute.ListAutoscalersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4656,17 +4661,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_list") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4715,8 +4718,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4933,17 +4937,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4994,8 +4996,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5136,17 +5139,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalersRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5199,8 +5205,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5417,17 +5424,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_update") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5687,11 +5692,14 @@ def test_autoscalers_base_transport(): def test_autoscalers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoscalersTransport( @@ -5711,9 +5719,12 @@ def test_autoscalers_base_transport_with_credentials_file(): def test_autoscalers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoscalersTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_buckets.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_buckets.py index c3cd7aaf3c96..bf056680f67b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_buckets.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_buckets.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackendBucketsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( BackendBucketsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BackendBucketsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5722,8 +5727,9 @@ def test_add_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5903,18 +5909,20 @@ def test_add_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_add_signed_url_key" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_add_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_add_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_add_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_add_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_add_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5967,8 +5975,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6037,17 +6046,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6103,8 +6115,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6209,17 +6222,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6272,8 +6287,9 @@ def test_delete_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6378,18 +6394,20 @@ def test_delete_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_delete_signed_url_key" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_delete_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_delete_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_delete_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_delete_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_delete_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6440,8 +6458,9 @@ def test_get_rest_bad_request(request_type=compute.GetBackendBucketRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6528,17 +6547,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.BackendBucketsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendBucketsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6591,8 +6608,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6659,17 +6677,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6720,8 +6741,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6943,17 +6965,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7004,8 +7028,9 @@ def test_list_rest_bad_request(request_type=compute.ListBackendBucketsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7074,17 +7099,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendBucketsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7137,8 +7162,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7207,17 +7233,19 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_list_usable_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_list_usable_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7270,8 +7298,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchBackendBucketRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7493,17 +7522,17 @@ def test_patch_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendBucketsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7556,8 +7585,9 @@ def test_set_edge_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7740,18 +7770,20 @@ def test_set_edge_security_policy_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_set_edge_security_policy" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_set_edge_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_set_edge_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_set_edge_security_policy" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_set_edge_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_set_edge_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7804,8 +7836,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7988,17 +8021,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8051,8 +8087,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8193,18 +8230,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8257,8 +8296,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8480,17 +8520,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8882,11 +8924,14 @@ def test_backend_buckets_base_transport(): def test_backend_buckets_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendBucketsTransport( @@ -8906,9 +8951,12 @@ def test_backend_buckets_base_transport_with_credentials_file(): def test_backend_buckets_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendBucketsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_services.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_services.py index 71a0c4700efe..7383043c9298 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_services.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_backend_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackendServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( BackendServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BackendServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -6561,8 +6566,9 @@ def test_add_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6742,18 +6748,20 @@ def test_add_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_add_signed_url_key" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_add_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_add_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_add_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_add_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_add_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6806,8 +6814,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6878,17 +6887,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6944,8 +6956,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7050,17 +7063,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7113,8 +7128,9 @@ def test_delete_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7219,18 +7235,20 @@ def test_delete_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_delete_signed_url_key" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_delete_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_delete_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_delete_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_delete_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_delete_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7281,8 +7299,9 @@ def test_get_rest_bad_request(request_type=compute.GetBackendServiceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7408,17 +7427,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendServicesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7471,8 +7490,9 @@ def test_get_effective_security_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7536,19 +7556,22 @@ def test_get_effective_security_policies_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_get_effective_security_policies", - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_get_effective_security_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get_effective_security_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_get_effective_security_policies", + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_get_effective_security_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "pre_get_effective_security_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7610,8 +7633,9 @@ def test_get_health_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7750,17 +7774,19 @@ def test_get_health_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_health" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_health_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get_health" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_health" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_health_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_get_health" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7815,8 +7841,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7883,17 +7910,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7944,8 +7974,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8327,17 +8358,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8388,8 +8421,9 @@ def test_list_rest_bad_request(request_type=compute.ListBackendServicesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8458,17 +8492,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendServicesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8521,8 +8555,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8591,17 +8626,19 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list_usable_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list_usable_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8654,8 +8691,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchBackendServiceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9037,17 +9075,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9100,8 +9140,9 @@ def test_set_edge_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9284,18 +9325,20 @@ def test_set_edge_security_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_edge_security_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_set_edge_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_set_edge_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_set_edge_security_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_set_edge_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_set_edge_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9348,8 +9391,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9532,17 +9576,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9595,8 +9642,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9779,18 +9827,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_set_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9843,8 +9893,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9985,18 +10036,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10049,8 +10102,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10432,17 +10486,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10901,11 +10957,14 @@ def test_backend_services_base_transport(): def test_backend_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendServicesTransport( @@ -10925,9 +10984,12 @@ def test_backend_services_base_transport_with_credentials_file(): def test_backend_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendServicesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_cross_site_networks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_cross_site_networks.py index 43d1becd7ec3..61266471306e 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_cross_site_networks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_cross_site_networks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CrossSiteNetworksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): CrossSiteNetworksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CrossSiteNetworksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2960,8 +2965,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteCrossSiteNetworkRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3066,17 +3072,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3127,8 +3135,9 @@ def test_get_rest_bad_request(request_type=compute.GetCrossSiteNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3201,17 +3210,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3262,8 +3273,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertCrossSiteNetworkRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3449,17 +3461,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3510,8 +3524,9 @@ def test_list_rest_bad_request(request_type=compute.ListCrossSiteNetworksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3584,17 +3599,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3647,8 +3664,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchCrossSiteNetworkReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3834,17 +3852,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4039,11 +4059,14 @@ def test_cross_site_networks_base_transport(): def test_cross_site_networks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CrossSiteNetworksTransport( @@ -4063,9 +4086,12 @@ def test_cross_site_networks_base_transport_with_credentials_file(): def test_cross_site_networks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CrossSiteNetworksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_settings_service.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_settings_service.py index 0b749d119948..b43a62c01466 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_settings_service.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_settings_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiskSettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): DiskSettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DiskSettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1919,8 +1924,9 @@ def test_get_rest_bad_request(request_type=compute.GetDiskSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1980,17 +1986,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = DiskSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskSettingsServiceRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.DiskSettingsServiceRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskSettingsServiceRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiskSettingsServiceRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.DiskSettingsServiceRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DiskSettingsServiceRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2039,8 +2047,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchDiskSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2217,17 +2226,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = DiskSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskSettingsServiceRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.DiskSettingsServiceRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskSettingsServiceRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiskSettingsServiceRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.DiskSettingsServiceRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DiskSettingsServiceRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2359,11 +2370,14 @@ def test_disk_settings_service_base_transport(): def test_disk_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.disk_settings_service.transports.DiskSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.disk_settings_service.transports.DiskSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiskSettingsServiceTransport( @@ -2383,9 +2397,12 @@ def test_disk_settings_service_base_transport_with_credentials_file(): def test_disk_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.disk_settings_service.transports.DiskSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.disk_settings_service.transports.DiskSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiskSettingsServiceTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_types.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_types.py index c152449b572c..47af2bcfb908 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_types.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disk_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiskTypesClient._get_default_mtls_endpoint(None) is None assert DiskTypesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -134,6 +135,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DiskTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DiskTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1952,8 +1956,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2022,17 +2027,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = DiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DiskTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2092,9 @@ def test_get_rest_bad_request(request_type=compute.GetDiskTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2165,17 +2173,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = DiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DiskTypesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DiskTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2224,8 +2230,9 @@ def test_list_rest_bad_request(request_type=compute.ListDiskTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2292,17 +2299,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = DiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DiskTypesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DiskTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2453,11 +2458,14 @@ def test_disk_types_base_transport(): def test_disk_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiskTypesTransport( @@ -2478,9 +2486,12 @@ def test_disk_types_base_transport_with_credentials_file(): def test_disk_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiskTypesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disks.py index 194b10a56b2e..6193769d092c 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_disks.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DisksClient._get_default_mtls_endpoint(None) is None assert DisksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DisksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert DisksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -8124,8 +8126,9 @@ def test_add_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8313,17 +8316,19 @@ def test_add_resource_policies_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_add_resource_policies" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_add_resource_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_add_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_add_resource_policies" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_add_resource_policies_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_add_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8376,8 +8381,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8446,17 +8452,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8507,8 +8515,9 @@ def test_bulk_insert_rest_bad_request(request_type=compute.BulkInsertDiskRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8697,17 +8706,15 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_bulk_insert") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_bulk_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8758,8 +8765,9 @@ def test_bulk_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8942,17 +8950,19 @@ def test_bulk_set_labels_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_set_labels" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_bulk_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_bulk_set_labels" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_bulk_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_bulk_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9005,8 +9015,9 @@ def test_create_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9226,17 +9237,19 @@ def test_create_snapshot_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_create_snapshot" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_create_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_create_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_create_snapshot" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_create_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_create_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9287,8 +9300,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9391,17 +9405,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9450,8 +9462,9 @@ def test_get_rest_bad_request(request_type=compute.GetDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9610,17 +9623,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9669,8 +9680,9 @@ def test_get_iam_policy_rest_bad_request(request_type=compute.GetIamPolicyDiskRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9735,17 +9747,17 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_get_iam_policy") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9796,8 +9808,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10039,17 +10052,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10098,8 +10109,9 @@ def test_list_rest_bad_request(request_type=compute.ListDisksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10166,17 +10178,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10227,8 +10237,9 @@ def test_remove_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10416,17 +10427,20 @@ def test_remove_resource_policies_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_remove_resource_policies" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_remove_resource_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_remove_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_remove_resource_policies" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, + "post_remove_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_remove_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10477,8 +10491,9 @@ def test_resize_rest_bad_request(request_type=compute.ResizeDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10655,17 +10670,15 @@ def test_resize_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_resize") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_resize") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10714,8 +10727,9 @@ def test_set_iam_policy_rest_bad_request(request_type=compute.SetIamPolicyDiskRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10896,17 +10910,17 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_set_iam_policy") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10957,8 +10971,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11140,17 +11155,15 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_set_labels") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11201,8 +11214,9 @@ def test_start_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11390,17 +11404,20 @@ def test_start_async_replication_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_start_async_replication" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_start_async_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_start_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_start_async_replication" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, + "post_start_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_start_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11453,8 +11470,9 @@ def test_stop_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11557,17 +11575,19 @@ def test_stop_async_replication_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_stop_async_replication" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_stop_async_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_stop_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_stop_async_replication" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_stop_async_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_stop_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11620,8 +11640,9 @@ def test_stop_group_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11809,18 +11830,20 @@ def test_stop_group_async_replication_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_stop_group_async_replication" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, - "post_stop_group_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_stop_group_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_stop_group_async_replication" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, + "post_stop_group_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_stop_group_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11873,8 +11896,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12013,17 +12037,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12076,8 +12102,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12319,17 +12346,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_update") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12828,11 +12853,14 @@ def test_disks_base_transport(): def test_disks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.disks.transports.DisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.disks.transports.DisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DisksTransport( @@ -12852,9 +12880,12 @@ def test_disks_base_transport_with_credentials_file(): def test_disks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.disks.transports.DisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.disks.transports.DisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DisksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_external_vpn_gateways.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_external_vpn_gateways.py index b68e4615a3c0..7a8148b996c8 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_external_vpn_gateways.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_external_vpn_gateways.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ExternalVpnGatewaysClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ExternalVpnGatewaysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ExternalVpnGatewaysClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3132,8 +3137,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteExternalVpnGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3238,17 +3244,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3299,8 +3307,9 @@ def test_get_rest_bad_request(request_type=compute.GetExternalVpnGatewayRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3377,17 +3386,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3438,8 +3449,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertExternalVpnGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3638,17 +3650,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3699,8 +3713,9 @@ def test_list_rest_bad_request(request_type=compute.ListExternalVpnGatewaysReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3771,17 +3786,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3836,8 +3853,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4021,17 +4039,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4084,8 +4105,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4226,18 +4248,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4457,11 +4481,14 @@ def test_external_vpn_gateways_base_transport(): def test_external_vpn_gateways_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExternalVpnGatewaysTransport( @@ -4481,9 +4508,12 @@ def test_external_vpn_gateways_base_transport_with_credentials_file(): def test_external_vpn_gateways_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExternalVpnGatewaysTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewall_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewall_policies.py index 8ae0a8c2b3ad..ce598805c9e5 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewall_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewall_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirewallPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): FirewallPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FirewallPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -8010,8 +8015,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8201,17 +8207,20 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_association_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_association" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_add_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8264,8 +8273,9 @@ def test_add_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8510,18 +8520,20 @@ def test_add_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_packet_mirroring_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_add_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_add_packet_mirroring_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_packet_mirroring_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_add_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_add_packet_mirroring_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8572,8 +8584,9 @@ def test_add_rule_rest_bad_request(request_type=compute.AddRuleFirewallPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8818,17 +8831,19 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8881,8 +8896,9 @@ def test_clone_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8987,17 +9003,19 @@ def test_clone_rules_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_clone_rules" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_clone_rules_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_clone_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_clone_rules" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_clone_rules_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_clone_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9048,8 +9066,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteFirewallPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9154,17 +9173,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9215,8 +9236,9 @@ def test_get_rest_bad_request(request_type=compute.GetFirewallPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9307,17 +9329,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallPoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9370,8 +9392,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9444,17 +9467,20 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_association_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_association" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9509,8 +9535,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9577,17 +9604,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9640,8 +9670,9 @@ def test_get_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9732,18 +9763,20 @@ def test_get_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_packet_mirroring_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_get_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_packet_mirroring_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_packet_mirroring_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_get_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_packet_mirroring_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9794,8 +9827,9 @@ def test_get_rule_rest_bad_request(request_type=compute.GetRuleFirewallPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9886,17 +9920,19 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9947,8 +9983,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertFirewallPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10228,17 +10265,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10289,8 +10328,9 @@ def test_list_rest_bad_request(request_type=compute.ListFirewallPoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10357,17 +10397,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10420,8 +10462,9 @@ def test_list_associations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10484,18 +10527,20 @@ def test_list_associations_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_list_associations" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_list_associations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_list_associations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_list_associations" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_list_associations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_list_associations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10551,8 +10596,9 @@ def test_move_rest_bad_request(request_type=compute.MoveFirewallPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10657,17 +10703,19 @@ def test_move_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_move" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_move_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_move" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10718,8 +10766,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchFirewallPolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10999,17 +11048,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11062,8 +11113,9 @@ def test_patch_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11308,18 +11360,22 @@ def test_patch_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_packet_mirroring_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_patch_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_patch_packet_mirroring_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_patch_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_patch_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "pre_patch_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11372,8 +11428,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11618,17 +11675,19 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11681,8 +11740,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11787,18 +11847,20 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_association" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_remove_association" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_remove_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11851,8 +11913,9 @@ def test_remove_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11957,18 +12020,22 @@ def test_remove_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_packet_mirroring_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_remove_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_remove_packet_mirroring_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_remove_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_remove_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "pre_remove_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12021,8 +12088,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12127,17 +12195,19 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_remove_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12190,8 +12260,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12381,17 +12452,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12444,8 +12518,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12586,18 +12661,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13165,11 +13242,14 @@ def test_firewall_policies_base_transport(): def test_firewall_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallPoliciesTransport( @@ -13189,9 +13269,12 @@ def test_firewall_policies_base_transport_with_credentials_file(): def test_firewall_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewalls.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewalls.py index 4a3cde12d1b0..4e367b2bb961 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewalls.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_firewalls.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirewallsClient._get_default_mtls_endpoint(None) is None assert FirewallsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FirewallsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FirewallsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3461,8 +3465,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3565,17 +3570,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3624,8 +3627,9 @@ def test_get_rest_bad_request(request_type=compute.GetFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3718,17 +3722,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3777,8 +3779,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3990,17 +3993,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4049,8 +4050,9 @@ def test_list_rest_bad_request(request_type=compute.ListFirewallsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4117,17 +4119,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4176,8 +4176,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4389,17 +4390,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4450,8 +4449,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4590,17 +4590,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.FirewallsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4653,8 +4656,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,17 +4870,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_update") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5113,11 +5115,14 @@ def test_firewalls_base_transport(): def test_firewalls_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallsTransport( @@ -5137,9 +5142,12 @@ def test_firewalls_base_transport_with_credentials_file(): def test_firewalls_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_forwarding_rules.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_forwarding_rules.py index 20ebdbabd59e..bb236fa9b8ba 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_forwarding_rules.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_forwarding_rules.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ForwardingRulesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( ForwardingRulesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ForwardingRulesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4333,8 +4338,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4405,17 +4411,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4475,8 +4484,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteForwardingRuleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4585,17 +4595,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4650,8 +4662,9 @@ def test_get_rest_bad_request(request_type=compute.GetForwardingRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4795,17 +4808,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ForwardingRulesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4856,8 +4869,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertForwardingRuleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5085,17 +5099,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5146,8 +5162,9 @@ def test_list_rest_bad_request(request_type=compute.ListForwardingRulesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5216,17 +5233,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ForwardingRulesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5281,8 +5298,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchForwardingRuleRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5514,17 +5532,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5577,8 +5597,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5762,17 +5783,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5829,8 +5852,9 @@ def test_set_target_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6013,17 +6037,19 @@ def test_set_target_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_target" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_set_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_target" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_set_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6076,8 +6102,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6218,18 +6245,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6512,11 +6541,14 @@ def test_forwarding_rules_base_transport(): def test_forwarding_rules_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ForwardingRulesTransport( @@ -6536,9 +6568,12 @@ def test_forwarding_rules_base_transport_with_credentials_file(): def test_forwarding_rules_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ForwardingRulesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_future_reservations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_future_reservations.py index 5b74aab3f304..c0f45302457f 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_future_reservations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_future_reservations.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FutureReservationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): FutureReservationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FutureReservationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3741,8 +3746,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3815,18 +3821,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3886,8 +3894,9 @@ def test_cancel_rest_bad_request(request_type=compute.CancelFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3996,17 +4005,19 @@ def test_cancel_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_cancel" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_cancel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_cancel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_cancel" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_cancel_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_cancel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4061,8 +4072,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4171,17 +4183,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4236,8 +4250,9 @@ def test_get_rest_bad_request(request_type=compute.GetFutureReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4343,17 +4358,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4404,8 +4421,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4686,17 +4704,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4747,8 +4767,9 @@ def test_list_rest_bad_request(request_type=compute.ListFutureReservationsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4821,17 +4842,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4891,8 +4914,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5177,17 +5201,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5424,11 +5450,14 @@ def test_future_reservations_base_transport(): def test_future_reservations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FutureReservationsTransport( @@ -5448,9 +5477,12 @@ def test_future_reservations_base_transport_with_credentials_file(): def test_future_reservations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FutureReservationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_addresses.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_addresses.py index 357a1329ad8f..7ce7a0e3f01e 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_addresses.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_addresses.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalAddressesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( GlobalAddressesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalAddressesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3500,8 +3505,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteGlobalAddressRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3606,17 +3612,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3667,8 +3675,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3769,17 +3778,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalAddressesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3830,8 +3839,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertGlobalAddressRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4026,17 +4036,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4087,8 +4099,9 @@ def test_list_rest_bad_request(request_type=compute.ListGlobalAddressesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4157,17 +4170,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalAddressesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4218,8 +4231,9 @@ def test_move_rest_bad_request(request_type=compute.MoveGlobalAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4406,17 +4420,17 @@ def test_move_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_move" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_move_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalAddressesRestInterceptor, "pre_move") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4469,8 +4483,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4654,17 +4669,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4717,8 +4734,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4859,18 +4877,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5111,11 +5131,14 @@ def test_global_addresses_base_transport(): def test_global_addresses_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalAddressesTransport( @@ -5135,9 +5158,12 @@ def test_global_addresses_base_transport_with_credentials_file(): def test_global_addresses_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalAddressesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_forwarding_rules.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_forwarding_rules.py index 0487e757c354..9c367768df1f 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_forwarding_rules.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_forwarding_rules.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalForwardingRulesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): GlobalForwardingRulesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalForwardingRulesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3954,8 +3959,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4060,17 +4066,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4121,8 +4129,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalForwardingRuleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4262,17 +4271,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4325,8 +4336,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4554,17 +4566,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4615,8 +4629,9 @@ def test_list_rest_bad_request(request_type=compute.ListGlobalForwardingRulesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4685,17 +4700,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4746,8 +4763,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchGlobalForwardingRuleRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4975,17 +4993,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5038,8 +5058,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5223,17 +5244,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5286,8 +5310,9 @@ def test_set_target_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5466,17 +5491,20 @@ def test_set_target_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_target" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_set_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_set_target" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, + "post_set_target_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_set_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5529,8 +5557,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5671,18 +5700,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5944,11 +5975,14 @@ def test_global_forwarding_rules_base_transport(): def test_global_forwarding_rules_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalForwardingRulesTransport( @@ -5968,9 +6002,12 @@ def test_global_forwarding_rules_base_transport_with_credentials_file(): def test_global_forwarding_rules_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalForwardingRulesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_network_endpoint_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_network_endpoint_groups.py index fb18d21f1298..3e2aa7b42410 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_network_endpoint_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_network_endpoint_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalNetworkEndpointGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): GlobalNetworkEndpointGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalNetworkEndpointGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3712,8 +3717,9 @@ def test_attach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3915,20 +3921,22 @@ def test_attach_network_endpoints_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints", - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "pre_attach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints", + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "pre_attach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3981,8 +3989,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4087,18 +4096,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4151,8 +4162,9 @@ def test_detach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4354,20 +4366,22 @@ def test_detach_network_endpoints_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints", - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "pre_detach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints", + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "pre_detach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4420,8 +4434,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4510,17 +4525,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4575,8 +4593,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4802,18 +4821,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4866,8 +4887,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4936,17 +4958,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5001,8 +5026,9 @@ def test_list_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5071,20 +5097,22 @@ def test_list_network_endpoints_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints", - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "pre_list_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints", + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "pre_list_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5332,11 +5360,14 @@ def test_global_network_endpoint_groups_base_transport(): def test_global_network_endpoint_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalNetworkEndpointGroupsTransport( @@ -5356,9 +5387,12 @@ def test_global_network_endpoint_groups_base_transport_with_credentials_file(): def test_global_network_endpoint_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalNetworkEndpointGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_operations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_operations.py index 3559a78b0472..e58ddc4d744c 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_operations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): GlobalOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2357,8 +2362,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2429,17 +2435,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2492,8 +2501,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteGlobalOperationReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2553,17 +2563,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2619,8 +2631,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2725,17 +2738,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalOperationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2786,8 +2799,9 @@ def test_list_rest_bad_request(request_type=compute.ListGlobalOperationsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2856,17 +2870,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2917,8 +2933,9 @@ def test_wait_rest_bad_request(request_type=compute.WaitGlobalOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3023,17 +3040,19 @@ def test_wait_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_wait" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_wait_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_wait" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_wait" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_wait_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_wait" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3228,11 +3247,14 @@ def test_global_operations_base_transport(): def test_global_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOperationsTransport( @@ -3252,9 +3274,12 @@ def test_global_operations_base_transport_with_credentials_file(): def test_global_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOperationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_organization_operations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_organization_operations.py index 13309c8f8b1b..bfc9c2c396f6 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_organization_operations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_organization_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalOrganizationOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): GlobalOrganizationOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalOrganizationOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1784,8 +1789,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1847,18 +1853,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalOrganizationOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1916,8 +1924,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2022,17 +2031,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalOrganizationOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2097,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2155,18 +2168,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalOrganizationOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2319,11 +2334,14 @@ def test_global_organization_operations_base_transport(): def test_global_organization_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOrganizationOperationsTransport( @@ -2343,9 +2361,12 @@ def test_global_organization_operations_base_transport_with_credentials_file(): def test_global_organization_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOrganizationOperationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_public_delegated_prefixes.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_public_delegated_prefixes.py index e3d7c0e6b4cc..a64de388f146 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_public_delegated_prefixes.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_public_delegated_prefixes.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalPublicDelegatedPrefixesClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): GlobalPublicDelegatedPrefixesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalPublicDelegatedPrefixesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2994,8 +2999,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3100,18 +3106,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3164,8 +3172,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3260,18 +3269,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3326,8 +3337,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3541,18 +3553,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3605,8 +3619,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3675,18 +3690,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3741,8 +3758,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3956,18 +3974,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4162,11 +4182,14 @@ def test_global_public_delegated_prefixes_base_transport(): def test_global_public_delegated_prefixes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalPublicDelegatedPrefixesTransport( @@ -4186,9 +4209,12 @@ def test_global_public_delegated_prefixes_base_transport_with_credentials_file() def test_global_public_delegated_prefixes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalPublicDelegatedPrefixesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_vm_extension_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_vm_extension_policies.py index 2322468c3916..5afff06896cf 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_vm_extension_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_global_vm_extension_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalVmExtensionPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): GlobalVmExtensionPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalVmExtensionPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3268,8 +3273,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3342,18 +3348,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = GlobalVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3411,8 +3419,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3607,17 +3616,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3668,8 +3680,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalVmExtensionPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3750,17 +3763,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3815,8 +3831,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4029,17 +4046,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4092,8 +4112,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4166,17 +4187,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4234,8 +4258,9 @@ def test_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4448,17 +4473,20 @@ def test_update_rest_interceptors(null_interceptor): ) client = GlobalVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, + "post_update_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalVmExtensionPoliciesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4674,11 +4702,14 @@ def test_global_vm_extension_policies_base_transport(): def test_global_vm_extension_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.global_vm_extension_policies.transports.GlobalVmExtensionPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.global_vm_extension_policies.transports.GlobalVmExtensionPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalVmExtensionPoliciesTransport( @@ -4698,9 +4729,12 @@ def test_global_vm_extension_policies_base_transport_with_credentials_file(): def test_global_vm_extension_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.global_vm_extension_policies.transports.GlobalVmExtensionPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.global_vm_extension_policies.transports.GlobalVmExtensionPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalVmExtensionPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_health_checks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_health_checks.py index d94bffa56826..8c1952977cbf 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_health_checks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_health_checks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert HealthChecksClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert HealthChecksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + HealthChecksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3735,8 +3740,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3807,17 +3813,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.HealthChecksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3870,8 +3878,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3976,17 +3985,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4037,8 +4046,9 @@ def test_get_rest_bad_request(request_type=compute.GetHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4125,17 +4135,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.HealthChecksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4184,8 +4192,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4429,17 +4438,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4490,8 +4499,9 @@ def test_list_rest_bad_request(request_type=compute.ListHealthChecksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4560,17 +4570,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.HealthChecksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4621,8 +4629,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,17 +4875,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.HealthChecksRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4929,8 +4936,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5071,18 +5079,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HealthChecksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5135,8 +5145,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5380,17 +5391,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5650,11 +5661,14 @@ def test_health_checks_base_transport(): def test_health_checks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HealthChecksTransport( @@ -5674,9 +5688,12 @@ def test_health_checks_base_transport_with_credentials_file(): def test_health_checks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HealthChecksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_image_family_views.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_image_family_views.py index 7e0b5956a22c..e2c02831f1b7 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_image_family_views.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_image_family_views.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ImageFamilyViewsClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): ImageFamilyViewsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ImageFamilyViewsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1450,8 +1455,9 @@ def test_get_rest_bad_request(request_type=compute.GetImageFamilyViewRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1511,17 +1517,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ImageFamilyViewsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageFamilyViewsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ImageFamilyViewsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImageFamilyViewsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageFamilyViewsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ImageFamilyViewsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImageFamilyViewsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1630,11 +1636,14 @@ def test_image_family_views_base_transport(): def test_image_family_views_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageFamilyViewsTransport( @@ -1655,9 +1664,12 @@ def test_image_family_views_base_transport_with_credentials_file(): def test_image_family_views_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageFamilyViewsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_images.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_images.py index 167ac34f6523..a789028f57e4 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_images.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_images.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ImagesClient._get_default_mtls_endpoint(None) is None assert ImagesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ImagesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ImagesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -4441,8 +4443,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4545,17 +4548,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4604,8 +4605,9 @@ def test_deprecate_rest_bad_request(request_type=compute.DeprecateImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4792,17 +4794,15 @@ def test_deprecate_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_deprecate" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_deprecate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_deprecate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_deprecate") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_deprecate_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_deprecate") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4851,8 +4851,9 @@ def test_get_rest_bad_request(request_type=compute.GetImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4965,17 +4966,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5026,8 +5025,9 @@ def test_get_from_family_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5140,17 +5140,19 @@ def test_get_from_family_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_from_family" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_from_family_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_get_from_family" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_from_family" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_from_family_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_get_from_family" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5201,8 +5203,9 @@ def test_get_iam_policy_rest_bad_request(request_type=compute.GetIamPolicyImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5267,17 +5270,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5328,8 +5333,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5564,17 +5570,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5623,8 +5627,9 @@ def test_list_rest_bad_request(request_type=compute.ListImagesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5691,17 +5696,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5750,8 +5753,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5986,17 +5990,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6045,8 +6047,9 @@ def test_set_iam_policy_rest_bad_request(request_type=compute.SetIamPolicyImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6227,17 +6230,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6288,8 +6293,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsImageRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6471,17 +6477,15 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_set_labels") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6532,8 +6536,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6672,17 +6677,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7007,11 +7014,14 @@ def test_images_base_transport(): def test_images_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.images.transports.ImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.images.transports.ImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImagesTransport( @@ -7031,9 +7041,12 @@ def test_images_base_transport_with_credentials_file(): def test_images_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.images.transports.ImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.images.transports.ImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImagesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_manager_resize_requests.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_manager_resize_requests.py index 072a7f08bbe1..61e1bbfa8bed 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_manager_resize_requests.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_manager_resize_requests.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( InstanceGroupManagerResizeRequestsClient._get_default_mtls_endpoint(None) @@ -155,6 +156,12 @@ def test__get_default_mtls_endpoint(): ) == non_googleapi ) + assert ( + InstanceGroupManagerResizeRequestsClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3161,8 +3168,9 @@ def test_cancel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3272,18 +3280,20 @@ def test_cancel_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_cancel" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_cancel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_cancel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_cancel" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_cancel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_cancel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3341,8 +3351,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3452,18 +3463,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3521,8 +3534,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3612,18 +3626,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3685,8 +3701,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3946,18 +3963,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4014,8 +4033,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4090,18 +4110,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4301,11 +4323,14 @@ def test_instance_group_manager_resize_requests_base_transport(): def test_instance_group_manager_resize_requests_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagerResizeRequestsTransport( @@ -4325,9 +4350,12 @@ def test_instance_group_manager_resize_requests_base_transport_with_credentials_ def test_instance_group_manager_resize_requests_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagerResizeRequestsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_managers.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_managers.py index ff28106484e3..9d62cdbb75f9 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_managers.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_group_managers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceGroupManagersClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InstanceGroupManagersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceGroupManagersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -13087,8 +13092,9 @@ def test_abandon_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13282,18 +13288,20 @@ def test_abandon_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_abandon_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_abandon_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_abandon_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_abandon_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_abandon_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_abandon_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13346,8 +13354,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13418,18 +13427,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13491,8 +13502,9 @@ def test_apply_updates_to_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13689,20 +13701,22 @@ def test_apply_updates_to_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_apply_updates_to_instances", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_apply_updates_to_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13759,8 +13773,9 @@ def test_configure_accelerator_topologies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13956,20 +13971,22 @@ def test_configure_accelerator_topologies_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_configure_accelerator_topologies", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_configure_accelerator_topologies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_configure_accelerator_topologies", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_configure_accelerator_topologies", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_configure_accelerator_topologies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_configure_accelerator_topologies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14028,8 +14045,9 @@ def test_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14235,18 +14253,20 @@ def test_create_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_create_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_create_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_create_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14303,8 +14323,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14413,17 +14434,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14480,8 +14503,9 @@ def test_delete_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14676,18 +14700,20 @@ def test_delete_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_delete_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_delete_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_delete_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_delete_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_delete_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_delete_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14744,8 +14770,9 @@ def test_delete_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14941,20 +14968,22 @@ def test_delete_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_delete_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_delete_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15009,8 +15038,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceGroupManagerReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15122,17 +15152,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15187,8 +15219,9 @@ def test_get_available_accelerator_topologies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15259,20 +15292,22 @@ def test_get_available_accelerator_topologies_rest_interceptors(null_interceptor ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_get_available_accelerator_topologies", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_get_available_accelerator_topologies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_get_available_accelerator_topologies", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_get_available_accelerator_topologies", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_get_available_accelerator_topologies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_get_available_accelerator_topologies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15334,8 +15369,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15681,17 +15717,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15742,8 +15780,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstanceGroupManagersReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15812,17 +15851,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15881,8 +15922,9 @@ def test_list_errors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15949,18 +15991,20 @@ def test_list_errors_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list_errors" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_errors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list_errors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_list_errors" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_errors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_list_errors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16022,8 +16066,9 @@ def test_list_managed_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16092,18 +16137,22 @@ def test_list_managed_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list_managed_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_managed_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list_managed_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_managed_instances", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_managed_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_list_managed_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16167,8 +16216,9 @@ def test_list_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16237,19 +16287,22 @@ def test_list_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list_per_instance_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_list_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16309,8 +16362,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInstanceGroupManagerRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16660,17 +16714,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16727,8 +16783,9 @@ def test_patch_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16934,20 +16991,22 @@ def test_patch_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_patch_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_patch_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17004,8 +17063,9 @@ def test_recreate_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17199,18 +17259,20 @@ def test_recreate_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_recreate_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_recreate_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_recreate_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_recreate_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_recreate_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_recreate_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17267,8 +17329,9 @@ def test_resize_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17377,17 +17440,19 @@ def test_resize_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resize" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_resize" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17444,8 +17509,9 @@ def test_resize_advanced_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17640,18 +17706,20 @@ def test_resize_advanced_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resize_advanced" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_resize_advanced_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_resize_advanced" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resize_advanced" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_resize_advanced_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_resize_advanced" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17708,8 +17776,9 @@ def test_resume_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17903,18 +17972,20 @@ def test_resume_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resume_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_resume_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_resume_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resume_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_resume_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_resume_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17971,8 +18042,9 @@ def test_set_auto_healing_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18168,19 +18240,22 @@ def test_set_auto_healing_policies_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_set_auto_healing_policies", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_set_auto_healing_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_set_auto_healing_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_auto_healing_policies", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_auto_healing_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_set_auto_healing_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18237,8 +18312,9 @@ def test_set_instance_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18432,18 +18508,21 @@ def test_set_instance_template_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_set_instance_template" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_set_instance_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_set_instance_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_instance_template", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_instance_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_set_instance_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18500,8 +18579,9 @@ def test_set_target_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18696,18 +18776,20 @@ def test_set_target_pools_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_set_target_pools" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_set_target_pools_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_set_target_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_set_target_pools" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_target_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_set_target_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18764,8 +18846,9 @@ def test_start_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18959,18 +19042,20 @@ def test_start_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_start_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_start_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_start_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_start_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_start_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_start_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19027,8 +19112,9 @@ def test_stop_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19223,18 +19309,20 @@ def test_stop_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_stop_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_stop_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_stop_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_stop_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_stop_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_stop_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19291,8 +19379,9 @@ def test_suspend_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19487,18 +19576,20 @@ def test_suspend_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_suspend_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_suspend_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_suspend_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_suspend_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_suspend_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_suspend_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19551,8 +19642,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19693,18 +19785,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19763,8 +19857,9 @@ def test_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20114,17 +20209,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20181,8 +20278,9 @@ def test_update_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20390,20 +20488,22 @@ def test_update_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_update_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_update_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21155,11 +21255,14 @@ def test_instance_group_managers_base_transport(): def test_instance_group_managers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagersTransport( @@ -21179,9 +21282,12 @@ def test_instance_group_managers_base_transport_with_credentials_file(): def test_instance_group_managers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagersTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_groups.py index 0f8de64231fc..79c21185777f 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( InstanceGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4638,8 +4643,9 @@ def test_add_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4833,17 +4839,19 @@ def test_add_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_add_instances" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_add_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_add_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_add_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_add_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_add_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4896,8 +4904,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4968,17 +4977,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5038,8 +5050,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstanceGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5148,17 +5161,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5213,8 +5228,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5303,17 +5319,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstanceGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstanceGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5364,8 +5378,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstanceGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5556,17 +5571,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5617,8 +5634,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstanceGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5687,17 +5705,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstanceGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5754,8 +5772,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5913,17 +5932,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5985,8 +6007,9 @@ def test_remove_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6180,17 +6203,20 @@ def test_remove_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_remove_instances" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_remove_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_remove_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_remove_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_remove_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_remove_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6247,8 +6273,9 @@ def test_set_named_ports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6443,17 +6470,20 @@ def test_set_named_ports_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_set_named_ports" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_set_named_ports_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_set_named_ports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_set_named_ports" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_set_named_ports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_set_named_ports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6506,8 +6536,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6648,18 +6679,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6963,11 +6996,14 @@ def test_instance_groups_base_transport(): def test_instance_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupsTransport( @@ -6987,9 +7023,12 @@ def test_instance_groups_base_transport_with_credentials_file(): def test_instance_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_settings_service.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_settings_service.py index f1c5c4518517..839a9c5705e2 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_settings_service.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_settings_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceSettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): InstanceSettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceSettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1903,8 +1908,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1971,17 +1977,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2032,8 +2040,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInstanceSettingRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2217,17 +2226,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InstanceSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2359,11 +2371,14 @@ def test_instance_settings_service_base_transport(): def test_instance_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceSettingsServiceTransport( @@ -2383,9 +2398,12 @@ def test_instance_settings_service_base_transport_with_credentials_file(): def test_instance_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceSettingsServiceTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_templates.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_templates.py index ce6a0b274c48..1b020f82fbdf 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_templates.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instance_templates.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceTemplatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): InstanceTemplatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceTemplatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3389,8 +3394,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3459,18 +3465,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3526,8 +3534,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstanceTemplateRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3632,17 +3641,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3693,8 +3704,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceTemplateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3771,17 +3783,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3834,8 +3848,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3902,17 +3917,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3963,8 +3981,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstanceTemplateRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4370,17 +4389,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4431,8 +4452,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstanceTemplatesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4501,17 +4523,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4566,8 +4590,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4750,17 +4775,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4813,8 +4841,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4955,18 +4984,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5228,11 +5259,14 @@ def test_instance_templates_base_transport(): def test_instance_templates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceTemplatesTransport( @@ -5252,9 +5286,12 @@ def test_instance_templates_base_transport_with_credentials_file(): def test_instance_templates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceTemplatesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instances.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instances.py index 28124edca5bd..c0fce2950c01 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instances.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instances.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstancesClient._get_default_mtls_endpoint(None) is None assert InstancesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -137,6 +138,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert InstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + InstancesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -22962,8 +22966,9 @@ def test_add_access_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23149,17 +23154,19 @@ def test_add_access_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_access_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_access_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_add_access_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_access_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_access_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_add_access_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23212,8 +23219,9 @@ def test_add_network_interface_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23430,17 +23438,20 @@ def test_add_network_interface_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_network_interface" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_network_interface_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_add_network_interface" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_network_interface" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_add_network_interface_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_add_network_interface" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23493,8 +23504,9 @@ def test_add_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23682,17 +23694,20 @@ def test_add_resource_policies_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_resource_policies" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_resource_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_add_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_resource_policies" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_add_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_add_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23745,8 +23760,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23815,17 +23831,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23878,8 +23896,9 @@ def test_attach_disk_rest_bad_request(request_type=compute.AttachDiskInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24110,17 +24129,19 @@ def test_attach_disk_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_attach_disk" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_attach_disk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_attach_disk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_attach_disk" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_attach_disk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_attach_disk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24171,8 +24192,9 @@ def test_bulk_insert_rest_bad_request(request_type=compute.BulkInsertInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24574,17 +24596,19 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_bulk_insert" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_bulk_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24635,8 +24659,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24739,17 +24764,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24800,8 +24823,9 @@ def test_delete_access_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24904,17 +24928,20 @@ def test_delete_access_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_access_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_access_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete_access_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_access_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_delete_access_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_delete_access_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24967,8 +24994,9 @@ def test_delete_network_interface_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25071,18 +25099,20 @@ def test_delete_network_interface_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_network_interface" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_delete_network_interface_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete_network_interface" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_network_interface" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_delete_network_interface_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_delete_network_interface" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25133,8 +25163,9 @@ def test_detach_disk_rest_bad_request(request_type=compute.DetachDiskInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25237,17 +25268,19 @@ def test_detach_disk_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_detach_disk" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_detach_disk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_detach_disk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_detach_disk" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_detach_disk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_detach_disk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25298,8 +25331,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25419,17 +25453,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25480,8 +25512,9 @@ def test_get_effective_firewalls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25539,18 +25572,20 @@ def test_get_effective_firewalls_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_effective_firewalls" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_get_effective_firewalls_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_effective_firewalls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_effective_firewalls" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_effective_firewalls_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_effective_firewalls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25608,8 +25643,9 @@ def test_get_guest_attributes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25678,17 +25714,20 @@ def test_get_guest_attributes_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_guest_attributes" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_guest_attributes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_guest_attributes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_guest_attributes" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_guest_attributes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_guest_attributes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25741,8 +25780,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25807,17 +25847,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25870,8 +25912,9 @@ def test_get_partner_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25932,17 +25975,20 @@ def test_get_partner_metadata_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_partner_metadata" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_partner_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_partner_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_partner_metadata" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_partner_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_partner_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25995,8 +26041,9 @@ def test_get_screenshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26059,17 +26106,19 @@ def test_get_screenshot_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_screenshot" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_screenshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_screenshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_screenshot" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_screenshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_screenshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26122,8 +26171,9 @@ def test_get_serial_port_output_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26192,17 +26242,20 @@ def test_get_serial_port_output_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_serial_port_output" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_serial_port_output_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_serial_port_output" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_serial_port_output" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_serial_port_output_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_serial_port_output" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26255,8 +26308,9 @@ def test_get_shielded_instance_identity_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26317,18 +26371,20 @@ def test_get_shielded_instance_identity_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_shielded_instance_identity" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_get_shielded_instance_identity_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_shielded_instance_identity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_shielded_instance_identity" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_shielded_instance_identity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_shielded_instance_identity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26383,8 +26439,9 @@ def test_get_shielded_vm_identity_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26445,18 +26502,20 @@ def test_get_shielded_vm_identity_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_shielded_vm_identity" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_get_shielded_vm_identity_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_shielded_vm_identity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_shielded_vm_identity" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_shielded_vm_identity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_shielded_vm_identity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26507,8 +26566,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26948,17 +27008,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27007,8 +27065,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstancesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27075,17 +27134,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27136,8 +27193,9 @@ def test_list_referrers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27204,17 +27262,19 @@ def test_list_referrers_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_referrers" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_referrers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_list_referrers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_referrers" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_referrers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_list_referrers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27269,8 +27329,9 @@ def test_patch_partner_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27450,17 +27511,20 @@ def test_patch_partner_metadata_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_patch_partner_metadata" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_patch_partner_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_patch_partner_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_patch_partner_metadata" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_patch_partner_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_patch_partner_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27513,8 +27577,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27617,17 +27682,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_perform_maintenance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27680,8 +27748,9 @@ def test_remove_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27869,18 +27938,20 @@ def test_remove_resource_policies_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_remove_resource_policies" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_remove_resource_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_remove_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_remove_resource_policies" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_remove_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_remove_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27933,8 +28004,9 @@ def test_report_host_as_faulty_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28125,17 +28197,20 @@ def test_report_host_as_faulty_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_report_host_as_faulty" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_report_host_as_faulty_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_report_host_as_faulty" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_report_host_as_faulty" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_report_host_as_faulty_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_report_host_as_faulty" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28186,8 +28261,9 @@ def test_reset_rest_bad_request(request_type=compute.ResetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28290,17 +28366,15 @@ def test_reset_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_reset" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_reset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_reset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_reset") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_reset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_reset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28349,8 +28423,9 @@ def test_resume_rest_bad_request(request_type=compute.ResumeInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28543,17 +28618,15 @@ def test_resume_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_resume" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_resume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_resume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_resume") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_resume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_resume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28604,8 +28677,9 @@ def test_send_diagnostic_interrupt_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28663,18 +28737,20 @@ def test_send_diagnostic_interrupt_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_send_diagnostic_interrupt" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_send_diagnostic_interrupt_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_send_diagnostic_interrupt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_send_diagnostic_interrupt" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_send_diagnostic_interrupt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_send_diagnostic_interrupt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28732,8 +28808,9 @@ def test_set_deletion_protection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28836,18 +28913,20 @@ def test_set_deletion_protection_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_deletion_protection" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_deletion_protection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_deletion_protection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_deletion_protection" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_deletion_protection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_deletion_protection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28900,8 +28979,9 @@ def test_set_disk_auto_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29004,17 +29084,20 @@ def test_set_disk_auto_delete_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_disk_auto_delete" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_disk_auto_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_disk_auto_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_disk_auto_delete" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_disk_auto_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_disk_auto_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29067,8 +29150,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29249,17 +29333,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29310,8 +29396,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsInstanceReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29495,17 +29582,17 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29558,8 +29645,9 @@ def test_set_machine_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29749,17 +29837,20 @@ def test_set_machine_resources_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_resources" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_resources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_machine_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_machine_resources" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_machine_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_machine_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29812,8 +29903,9 @@ def test_set_machine_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30001,17 +30093,19 @@ def test_set_machine_type_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_type" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_machine_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_machine_type" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_machine_type_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_machine_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30062,8 +30156,9 @@ def test_set_metadata_rest_bad_request(request_type=compute.SetMetadataInstanceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30238,17 +30333,19 @@ def test_set_metadata_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_metadata" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_metadata" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_metadata_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30301,8 +30398,9 @@ def test_set_min_cpu_platform_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30490,17 +30588,20 @@ def test_set_min_cpu_platform_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_min_cpu_platform" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_min_cpu_platform_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_min_cpu_platform" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_min_cpu_platform" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_min_cpu_platform_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_min_cpu_platform" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30551,8 +30652,9 @@ def test_set_name_rest_bad_request(request_type=compute.SetNameInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30734,17 +30836,15 @@ def test_set_name_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_name" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_name_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_name" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_set_name") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_name_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_set_name") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30795,8 +30895,9 @@ def test_set_scheduling_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30996,17 +31097,19 @@ def test_set_scheduling_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_scheduling" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_scheduling_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_scheduling" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_scheduling" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_scheduling_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_scheduling" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31059,8 +31162,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31252,17 +31356,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_security_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31315,8 +31422,9 @@ def test_set_service_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31505,17 +31613,20 @@ def test_set_service_account_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_service_account" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_service_account_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_service_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_service_account" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_service_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_service_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31568,8 +31679,9 @@ def test_set_shielded_instance_integrity_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31757,20 +31869,22 @@ def test_set_shielded_instance_integrity_policy_rest_interceptors(null_intercept ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_shielded_instance_integrity_policy", - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_shielded_instance_integrity_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, - "pre_set_shielded_instance_integrity_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_shielded_instance_integrity_policy", + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_shielded_instance_integrity_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, + "pre_set_shielded_instance_integrity_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31823,8 +31937,9 @@ def test_set_shielded_vm_integrity_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32007,18 +32122,20 @@ def test_set_shielded_vm_integrity_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_shielded_vm_integrity_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_shielded_vm_integrity_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_shielded_vm_integrity_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_shielded_vm_integrity_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_shielded_vm_integrity_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_shielded_vm_integrity_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32069,8 +32186,9 @@ def test_set_tags_rest_bad_request(request_type=compute.SetTagsInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32244,17 +32362,15 @@ def test_set_tags_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_tags" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_tags_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_tags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_set_tags") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_tags_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_set_tags") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32305,8 +32421,9 @@ def test_simulate_maintenance_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32409,18 +32526,20 @@ def test_simulate_maintenance_event_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_simulate_maintenance_event" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_simulate_maintenance_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_simulate_maintenance_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_simulate_maintenance_event" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_simulate_maintenance_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_simulate_maintenance_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32471,8 +32590,9 @@ def test_start_rest_bad_request(request_type=compute.StartInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32575,17 +32695,15 @@ def test_start_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_start" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_start_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_start" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_start") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_start_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_start") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32636,8 +32754,9 @@ def test_start_with_encryption_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32836,18 +32955,20 @@ def test_start_with_encryption_key_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_start_with_encryption_key" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_start_with_encryption_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_start_with_encryption_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_start_with_encryption_key" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_start_with_encryption_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_start_with_encryption_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32898,8 +33019,9 @@ def test_stop_rest_bad_request(request_type=compute.StopInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33002,17 +33124,15 @@ def test_stop_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_stop" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_stop_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_stop" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_stop") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_stop_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_stop") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33061,8 +33181,9 @@ def test_suspend_rest_bad_request(request_type=compute.SuspendInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33165,17 +33286,15 @@ def test_suspend_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_suspend" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_suspend_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_suspend" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_suspend") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_suspend_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_suspend") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33226,8 +33345,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33366,17 +33486,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33429,8 +33552,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33870,17 +33994,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_update") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33931,8 +34053,9 @@ def test_update_access_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34118,17 +34241,20 @@ def test_update_access_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_access_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_access_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_access_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_access_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_access_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_access_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34181,8 +34307,9 @@ def test_update_display_device_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34357,17 +34484,20 @@ def test_update_display_device_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_display_device" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_display_device_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_display_device" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_display_device" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_display_device_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_display_device" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34420,8 +34550,9 @@ def test_update_network_interface_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34638,18 +34769,20 @@ def test_update_network_interface_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_network_interface" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_update_network_interface_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_network_interface" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_network_interface" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_network_interface_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_network_interface" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34702,8 +34835,9 @@ def test_update_shielded_instance_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34886,18 +35020,20 @@ def test_update_shielded_instance_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_shielded_instance_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_update_shielded_instance_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_shielded_instance_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_shielded_instance_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_shielded_instance_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_shielded_instance_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34950,8 +35086,9 @@ def test_update_shielded_vm_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35132,18 +35269,20 @@ def test_update_shielded_vm_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_shielded_vm_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_update_shielded_vm_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_shielded_vm_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_shielded_vm_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_shielded_vm_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_shielded_vm_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36473,11 +36612,14 @@ def test_instances_base_transport(): def test_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instances.transports.InstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instances.transports.InstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstancesTransport( @@ -36497,9 +36639,12 @@ def test_instances_base_transport_with_credentials_file(): def test_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instances.transports.InstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instances.transports.InstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstancesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshot_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshot_groups.py index d4a15870d255..f9eec9150e8b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshot_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshot_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstantSnapshotGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InstantSnapshotGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstantSnapshotGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3239,8 +3244,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3349,17 +3355,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3414,8 +3422,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstantSnapshotGroupReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3502,17 +3511,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3567,8 +3578,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3635,18 +3647,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3699,8 +3713,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3900,17 +3915,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3961,8 +3978,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstantSnapshotGroupsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4035,17 +4053,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4100,8 +4120,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4284,18 +4305,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4348,8 +4371,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4490,18 +4514,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4742,11 +4768,14 @@ def test_instant_snapshot_groups_base_transport(): def test_instant_snapshot_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instant_snapshot_groups.transports.InstantSnapshotGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instant_snapshot_groups.transports.InstantSnapshotGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstantSnapshotGroupsTransport( @@ -4766,9 +4795,12 @@ def test_instant_snapshot_groups_base_transport_with_credentials_file(): def test_instant_snapshot_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instant_snapshot_groups.transports.InstantSnapshotGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instant_snapshot_groups.transports.InstantSnapshotGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstantSnapshotGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshots.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshots.py index 9cfc36a2fbce..6b2b9a624ab4 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshots.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_instant_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstantSnapshotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InstantSnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstantSnapshotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3897,8 +3902,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3969,17 +3975,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4039,8 +4048,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstantSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4149,17 +4159,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4214,8 +4226,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstantSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4323,17 +4336,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstantSnapshotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4386,8 +4399,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4454,17 +4468,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4515,8 +4532,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstantSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4718,17 +4736,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4779,8 +4799,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstantSnapshotsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4849,17 +4870,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4914,8 +4937,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5098,17 +5122,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5161,8 +5188,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5346,17 +5374,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5409,8 +5439,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5551,18 +5582,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5845,11 +5878,14 @@ def test_instant_snapshots_base_transport(): def test_instant_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstantSnapshotsTransport( @@ -5869,9 +5905,12 @@ def test_instant_snapshots_base_transport_with_credentials_file(): def test_instant_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstantSnapshotsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachment_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachment_groups.py index 74b9cb16c21d..af413521d36b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachment_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachment_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectAttachmentGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): InterconnectAttachmentGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectAttachmentGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3893,8 +3898,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3999,18 +4005,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4063,8 +4071,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4141,17 +4150,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4209,8 +4221,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4277,18 +4290,21 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_iam_policy", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4341,8 +4357,9 @@ def test_get_operational_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4411,20 +4428,22 @@ def test_get_operational_status_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_get_operational_status", - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_get_operational_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "pre_get_operational_status", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_operational_status", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_operational_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "pre_get_operational_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4486,8 +4505,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4724,18 +4744,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4788,8 +4810,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4862,18 +4885,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4931,8 +4956,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5169,18 +5195,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5233,8 +5261,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5417,18 +5446,21 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_set_iam_policy", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5481,8 +5513,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5625,20 +5658,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5923,11 +5958,14 @@ def test_interconnect_attachment_groups_base_transport(): def test_interconnect_attachment_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentGroupsTransport( @@ -5947,9 +5985,12 @@ def test_interconnect_attachment_groups_base_transport_with_credentials_file(): def test_interconnect_attachment_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachments.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachments.py index 7f8d79155cad..26513524d15f 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachments.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_attachments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectAttachmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InterconnectAttachmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectAttachmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3983,8 +3988,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4055,18 +4061,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4128,8 +4136,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4238,17 +4247,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4303,8 +4315,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectAttachmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4469,17 +4482,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4534,8 +4549,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4783,17 +4799,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4844,8 +4863,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectAttachmentsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4914,17 +4934,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4983,8 +5005,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5236,17 +5259,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5299,8 +5325,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5484,18 +5511,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, - "post_set_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5548,8 +5577,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5690,18 +5720,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5963,11 +5997,14 @@ def test_interconnect_attachments_base_transport(): def test_interconnect_attachments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentsTransport( @@ -5987,9 +6024,12 @@ def test_interconnect_attachments_base_transport_with_credentials_file(): def test_interconnect_attachments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_groups.py index 5ede3b3f3932..8bf18180d221 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InterconnectGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4223,8 +4228,9 @@ def test_create_members_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4435,18 +4441,20 @@ def test_create_members_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_create_members" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_create_members_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_create_members" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_create_members" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_create_members_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_create_members" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4497,8 +4505,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInterconnectGroupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4603,17 +4612,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4664,8 +4675,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4740,17 +4752,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4803,8 +4817,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4871,18 +4886,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4935,8 +4952,9 @@ def test_get_operational_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5001,18 +5019,20 @@ def test_get_operational_status_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get_operational_status" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_get_operational_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_get_operational_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get_operational_status" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_get_operational_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_get_operational_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5068,8 +5088,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInterconnectGroupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5298,17 +5319,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5359,8 +5382,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectGroupsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5433,17 +5457,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5499,8 +5525,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInterconnectGroupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5729,17 +5756,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5792,8 +5821,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5976,18 +6006,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6040,8 +6072,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6182,18 +6215,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6499,11 +6534,14 @@ def test_interconnect_groups_base_transport(): def test_interconnect_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectGroupsTransport( @@ -6523,9 +6561,12 @@ def test_interconnect_groups_base_transport_with_credentials_file(): def test_interconnect_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_locations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_locations.py index eb96c74240d7..a4eb6356466b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_locations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_locations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectLocationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): InterconnectLocationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectLocationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1728,8 +1733,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectLocationReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1832,17 +1838,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1895,8 +1903,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectLocationsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1965,17 +1974,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2109,11 +2120,14 @@ def test_interconnect_locations_base_transport(): def test_interconnect_locations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectLocationsTransport( @@ -2134,9 +2148,12 @@ def test_interconnect_locations_base_transport_with_credentials_file(): def test_interconnect_locations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectLocationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_remote_locations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_remote_locations.py index 921c1a6c8d95..1179c128378b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_remote_locations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnect_remote_locations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectRemoteLocationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InterconnectRemoteLocationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectRemoteLocationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1781,8 +1786,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1881,17 +1887,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectRemoteLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1946,8 +1955,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2016,17 +2026,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectRemoteLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2163,11 +2176,14 @@ def test_interconnect_remote_locations_base_transport(): def test_interconnect_remote_locations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectRemoteLocationsTransport( @@ -2188,9 +2204,12 @@ def test_interconnect_remote_locations_base_transport_with_credentials_file(): def test_interconnect_remote_locations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectRemoteLocationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnects.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnects.py index 9a0228fbc653..fd1e40097f9b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnects.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_interconnects.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( InterconnectsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3862,8 +3867,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInterconnectRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3968,17 +3974,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4029,8 +4035,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4151,17 +4158,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InterconnectsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4212,8 +4217,9 @@ def test_get_diagnostics_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4273,17 +4279,20 @@ def test_get_diagnostics_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_diagnostics" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_diagnostics_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_get_diagnostics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_get_diagnostics" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, + "post_get_diagnostics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_get_diagnostics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4341,8 +4350,9 @@ def test_get_macsec_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4405,17 +4415,20 @@ def test_get_macsec_config_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_macsec_config" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_macsec_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_get_macsec_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_get_macsec_config" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, + "post_get_macsec_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_get_macsec_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4471,8 +4484,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInterconnectRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4730,17 +4744,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4791,8 +4805,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4861,17 +4876,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InterconnectsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4922,8 +4935,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInterconnectRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5181,17 +5195,17 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5242,8 +5256,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsInterconnectR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5427,17 +5442,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5490,8 +5507,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5632,18 +5650,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5928,11 +5948,14 @@ def test_interconnects_base_transport(): def test_interconnects_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectsTransport( @@ -5952,9 +5975,12 @@ def test_interconnects_base_transport_with_credentials_file(): def test_interconnects_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_license_codes.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_license_codes.py index fa07eb410708..a95cc3920afa 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_license_codes.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_license_codes.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LicenseCodesClient._get_default_mtls_endpoint(None) is None assert ( @@ -135,6 +136,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert LicenseCodesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + LicenseCodesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1610,8 +1615,9 @@ def test_get_rest_bad_request(request_type=compute.GetLicenseCodeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1688,17 +1694,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = LicenseCodesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseCodesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.LicenseCodesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseCodesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicenseCodesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.LicenseCodesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicenseCodesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1749,8 +1753,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1891,18 +1896,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = LicenseCodesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseCodesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.LicenseCodesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseCodesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseCodesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.LicenseCodesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseCodesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2038,11 +2045,14 @@ def test_license_codes_base_transport(): def test_license_codes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseCodesTransport( @@ -2063,9 +2073,12 @@ def test_license_codes_base_transport_with_credentials_file(): def test_license_codes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseCodesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_licenses.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_licenses.py index a14a3130ab45..30e247e24c1c 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_licenses.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_licenses.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LicensesClient._get_default_mtls_endpoint(None) is None assert LicensesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert LicensesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert LicensesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -3530,8 +3532,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3634,17 +3637,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3693,8 +3694,9 @@ def test_get_rest_bad_request(request_type=compute.GetLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3795,17 +3797,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3856,8 +3856,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3922,17 +3923,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicensesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicensesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3983,8 +3986,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4187,17 +4191,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4246,8 +4248,9 @@ def test_list_rest_bad_request(request_type=compute.ListLicensesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4312,17 +4315,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4375,8 +4376,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4557,17 +4559,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicensesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicensesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4620,8 +4624,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4760,17 +4765,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicensesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.LicensesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicensesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4823,8 +4831,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5027,17 +5036,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_update") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5295,11 +5302,14 @@ def test_licenses_base_transport(): def test_licenses_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.licenses.transports.LicensesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.licenses.transports.LicensesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicensesTransport( @@ -5319,9 +5329,12 @@ def test_licenses_base_transport_with_credentials_file(): def test_licenses_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.licenses.transports.LicensesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.licenses.transports.LicensesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicensesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_images.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_images.py index 815879be721e..ca674741a54a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_images.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_images.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MachineImagesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( MachineImagesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MachineImagesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3497,8 +3502,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteMachineImageRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3603,17 +3609,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3664,8 +3670,9 @@ def test_get_rest_bad_request(request_type=compute.GetMachineImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3754,17 +3761,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineImagesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3815,8 +3820,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3883,17 +3889,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3944,8 +3952,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertMachineImageRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4394,17 +4403,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4455,8 +4464,9 @@ def test_list_rest_bad_request(request_type=compute.ListMachineImagesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4525,17 +4535,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineImagesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4588,8 +4596,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4772,17 +4781,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4833,8 +4844,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsMachineImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5018,17 +5030,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5081,8 +5095,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5223,18 +5238,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5496,11 +5513,14 @@ def test_machine_images_base_transport(): def test_machine_images_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineImagesTransport( @@ -5520,9 +5540,12 @@ def test_machine_images_base_transport_with_credentials_file(): def test_machine_images_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineImagesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_types.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_types.py index 11105f345663..7ec85479bb5c 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_types.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_machine_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MachineTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -136,6 +137,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MachineTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MachineTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1965,8 +1970,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2037,17 +2043,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = MachineTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2100,8 +2108,9 @@ def test_get_rest_bad_request(request_type=compute.GetMachineTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2190,17 +2199,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = MachineTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineTypesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2249,8 +2256,9 @@ def test_list_rest_bad_request(request_type=compute.ListMachineTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2319,17 +2327,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = MachineTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineTypesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2482,11 +2488,14 @@ def test_machine_types_base_transport(): def test_machine_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineTypesTransport( @@ -2507,9 +2516,12 @@ def test_machine_types_base_transport_with_credentials_file(): def test_machine_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineTypesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_attachments.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_attachments.py index 7987dfdd357c..c13a0f91159d 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_attachments.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_attachments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkAttachmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): NetworkAttachmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkAttachmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3943,8 +3948,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4013,18 +4019,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4084,8 +4092,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNetworkAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4194,17 +4203,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4259,8 +4270,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkAttachmentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4353,17 +4365,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4416,8 +4430,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4484,18 +4499,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4546,8 +4563,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNetworkAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4761,17 +4779,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4822,8 +4842,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkAttachmentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4892,17 +4913,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4959,8 +4982,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNetworkAttachmentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5178,17 +5202,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5241,8 +5267,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5425,18 +5452,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5489,8 +5518,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5631,18 +5661,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5925,11 +5957,14 @@ def test_network_attachments_base_transport(): def test_network_attachments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkAttachmentsTransport( @@ -5949,9 +5984,12 @@ def test_network_attachments_base_transport_with_credentials_file(): def test_network_attachments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkAttachmentsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_edge_security_services.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_edge_security_services.py index 22e78f9b494e..25a48e3b49b4 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_edge_security_services.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_edge_security_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkEdgeSecurityServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): NetworkEdgeSecurityServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkEdgeSecurityServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3138,8 +3143,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3212,18 +3218,21 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3285,8 +3294,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3395,18 +3405,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3463,8 +3475,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3549,17 +3562,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3614,8 +3630,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3810,18 +3827,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3878,8 +3897,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4078,18 +4098,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4284,11 +4306,14 @@ def test_network_edge_security_services_base_transport(): def test_network_edge_security_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEdgeSecurityServicesTransport( @@ -4308,9 +4333,12 @@ def test_network_edge_security_services_base_transport_with_credentials_file(): def test_network_edge_security_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEdgeSecurityServicesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_endpoint_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_endpoint_groups.py index ed5f3fc906bd..00a338753735 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_endpoint_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_endpoint_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkEndpointGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): NetworkEndpointGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkEndpointGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4312,8 +4317,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4384,18 +4390,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4457,8 +4465,9 @@ def test_attach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4662,18 +4671,22 @@ def test_attach_network_endpoints_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_attach_network_endpoints" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_attach_network_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints", + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "pre_attach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4730,8 +4743,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4840,17 +4854,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4907,8 +4923,9 @@ def test_detach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5112,18 +5129,22 @@ def test_detach_network_endpoints_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_detach_network_endpoints" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_detach_network_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints", + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "pre_detach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5178,8 +5199,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkEndpointGroupReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5272,17 +5294,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5337,8 +5361,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5564,17 +5589,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5625,8 +5652,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkEndpointGroupsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5695,17 +5723,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5764,8 +5794,9 @@ def test_list_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5936,18 +5967,22 @@ def test_list_network_endpoints_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_list_network_endpoints" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_list_network_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints", + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "pre_list_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6005,8 +6040,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6147,18 +6183,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6447,11 +6485,14 @@ def test_network_endpoint_groups_base_transport(): def test_network_endpoint_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEndpointGroupsTransport( @@ -6471,9 +6512,12 @@ def test_network_endpoint_groups_base_transport_with_credentials_file(): def test_network_endpoint_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEndpointGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_firewall_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_firewall_policies.py index e6b9b73a5ab0..dd790fad6978 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_firewall_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_firewall_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkFirewallPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): NetworkFirewallPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkFirewallPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -8311,8 +8316,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8502,18 +8508,20 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_add_association" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8566,8 +8574,9 @@ def test_add_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8812,20 +8821,22 @@ def test_add_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_add_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_add_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_add_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_add_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8878,8 +8889,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9124,17 +9136,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9187,8 +9202,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9259,18 +9275,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9328,8 +9346,9 @@ def test_clone_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9434,18 +9453,20 @@ def test_clone_rules_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_clone_rules" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_clone_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_clone_rules" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_clone_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9498,8 +9519,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9604,17 +9626,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9665,8 +9690,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkFirewallPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9757,17 +9783,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9820,8 +9848,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9894,18 +9923,20 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_association" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9960,8 +9991,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10028,18 +10060,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10092,8 +10126,9 @@ def test_get_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10184,20 +10219,22 @@ def test_get_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_get_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_get_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10250,8 +10287,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10342,17 +10380,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10405,8 +10446,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10686,17 +10728,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10747,8 +10792,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkFirewallPoliciesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10815,17 +10861,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10876,8 +10924,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNetworkFirewallPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11157,17 +11206,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11220,8 +11272,9 @@ def test_patch_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11468,20 +11521,22 @@ def test_patch_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_patch_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_patch_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_patch_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_patch_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11534,8 +11589,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11780,18 +11836,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11844,8 +11902,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11950,18 +12009,20 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_association" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_association" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12014,8 +12075,9 @@ def test_remove_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12120,20 +12182,22 @@ def test_remove_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_remove_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_remove_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12186,8 +12250,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12292,18 +12357,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12356,8 +12423,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12540,18 +12608,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12604,8 +12674,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12746,18 +12817,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13302,11 +13377,14 @@ def test_network_firewall_policies_base_transport(): def test_network_firewall_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkFirewallPoliciesTransport( @@ -13326,9 +13404,12 @@ def test_network_firewall_policies_base_transport_with_credentials_file(): def test_network_firewall_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkFirewallPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_profiles.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_profiles.py index f2b2deb3a16a..2349f0d8be08 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_profiles.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_network_profiles.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkProfilesClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( NetworkProfilesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkProfilesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1698,8 +1703,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkProfileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1776,17 +1782,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworkProfilesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1837,8 +1843,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkProfilesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1911,17 +1918,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworkProfilesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2058,11 +2065,14 @@ def test_network_profiles_base_transport(): def test_network_profiles_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkProfilesTransport( @@ -2083,9 +2093,12 @@ def test_network_profiles_base_transport_with_credentials_file(): def test_network_profiles_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkProfilesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_networks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_networks.py index a60ad1270cf6..4320def23e7b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_networks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_networks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworksClient._get_default_mtls_endpoint(None) is None assert NetworksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NetworksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert NetworksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -6008,8 +6010,9 @@ def test_add_peering_rest_bad_request(request_type=compute.AddPeeringNetworkRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6223,17 +6226,17 @@ def test_add_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_add_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_add_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_add_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_add_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_add_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_add_peering") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6286,8 +6289,9 @@ def test_cancel_request_remove_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6475,18 +6479,20 @@ def test_cancel_request_remove_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_cancel_request_remove_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, - "post_cancel_request_remove_peering_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_cancel_request_remove_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_cancel_request_remove_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_cancel_request_remove_peering_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_cancel_request_remove_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6537,8 +6543,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6641,17 +6648,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6700,8 +6705,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6797,17 +6803,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6858,8 +6862,9 @@ def test_get_effective_firewalls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6917,17 +6922,20 @@ def test_get_effective_firewalls_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_get_effective_firewalls" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_get_effective_firewalls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_get_effective_firewalls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_get_effective_firewalls" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_get_effective_firewalls_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_get_effective_firewalls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6983,8 +6991,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7213,17 +7222,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7272,8 +7279,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7340,17 +7348,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7401,8 +7407,9 @@ def test_list_peering_routes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7469,17 +7476,19 @@ def test_list_peering_routes_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_list_peering_routes" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_list_peering_routes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_list_peering_routes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_list_peering_routes" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_list_peering_routes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_list_peering_routes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7532,8 +7541,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7762,17 +7772,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7823,8 +7831,9 @@ def test_remove_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8008,17 +8017,19 @@ def test_remove_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_remove_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_remove_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_remove_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_remove_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_remove_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_remove_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8071,8 +8082,9 @@ def test_request_remove_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8260,17 +8272,20 @@ def test_request_remove_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_request_remove_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_request_remove_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_request_remove_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_request_remove_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_request_remove_peering_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_request_remove_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8323,8 +8338,9 @@ def test_switch_to_custom_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8427,17 +8443,20 @@ def test_switch_to_custom_mode_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_switch_to_custom_mode" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_switch_to_custom_mode_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_switch_to_custom_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_switch_to_custom_mode" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_switch_to_custom_mode_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_switch_to_custom_mode" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8490,8 +8509,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8630,17 +8650,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8695,8 +8718,9 @@ def test_update_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8910,17 +8934,19 @@ def test_update_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_update_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_update_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_update_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_update_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_update_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_update_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9316,11 +9342,14 @@ def test_networks_base_transport(): def test_networks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.networks.transports.NetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.networks.transports.NetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworksTransport( @@ -9340,9 +9369,12 @@ def test_networks_base_transport_with_credentials_file(): def test_networks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.networks.transports.NetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.networks.transports.NetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_groups.py index 10a2089c566b..89a9d5f37f90 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NodeGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + NodeGroupsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -6363,8 +6367,9 @@ def test_add_nodes_rest_bad_request(request_type=compute.AddNodesNodeGroupReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6550,17 +6555,17 @@ def test_add_nodes_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_add_nodes" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_add_nodes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_add_nodes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_add_nodes" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_add_nodes_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_add_nodes") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6613,8 +6618,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6685,17 +6691,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6748,8 +6756,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6854,17 +6863,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6915,8 +6922,9 @@ def test_delete_nodes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7104,17 +7112,19 @@ def test_delete_nodes_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete_nodes" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete_nodes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_delete_nodes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_delete_nodes" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_delete_nodes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_delete_nodes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7165,8 +7175,9 @@ def test_get_rest_bad_request(request_type=compute.GetNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7255,17 +7266,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7316,8 +7325,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7384,17 +7394,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7445,8 +7457,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7648,17 +7661,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7707,8 +7718,9 @@ def test_list_rest_bad_request(request_type=compute.ListNodeGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7777,17 +7789,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7836,8 +7846,9 @@ def test_list_nodes_rest_bad_request(request_type=compute.ListNodesNodeGroupsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7906,17 +7917,19 @@ def test_list_nodes_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list_nodes" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list_nodes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_list_nodes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_list_nodes" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_list_nodes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_list_nodes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7969,8 +7982,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8172,17 +8186,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8233,8 +8245,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8425,17 +8438,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_perform_maintenance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8488,8 +8504,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8672,17 +8689,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8735,8 +8754,9 @@ def test_set_node_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8926,17 +8946,19 @@ def test_set_node_template_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_node_template" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_node_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_set_node_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_node_template" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_node_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_set_node_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8989,8 +9011,9 @@ def test_simulate_maintenance_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9180,18 +9203,20 @@ def test_simulate_maintenance_event_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_simulate_maintenance_event" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, - "post_simulate_maintenance_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_simulate_maintenance_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_simulate_maintenance_event" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, + "post_simulate_maintenance_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_simulate_maintenance_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9244,8 +9269,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9386,17 +9412,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9811,11 +9840,14 @@ def test_node_groups_base_transport(): def test_node_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeGroupsTransport( @@ -9835,9 +9867,12 @@ def test_node_groups_base_transport_with_credentials_file(): def test_node_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_templates.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_templates.py index 88e25fa0b2cc..12535a79b110 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_templates.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_templates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeTemplatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( NodeTemplatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NodeTemplatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3439,8 +3444,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3511,17 +3517,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3578,8 +3587,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNodeTemplateRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3688,17 +3698,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3753,8 +3763,9 @@ def test_get_rest_bad_request(request_type=compute.GetNodeTemplateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3841,17 +3852,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3902,8 +3911,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3970,17 +3980,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4031,8 +4043,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNodeTemplateRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4232,17 +4245,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4293,8 +4306,9 @@ def test_list_rest_bad_request(request_type=compute.ListNodeTemplatesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4363,17 +4377,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4426,8 +4438,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4610,17 +4623,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4673,8 +4688,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4815,18 +4831,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5088,11 +5106,14 @@ def test_node_templates_base_transport(): def test_node_templates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTemplatesTransport( @@ -5112,9 +5133,12 @@ def test_node_templates_base_transport_with_credentials_file(): def test_node_templates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTemplatesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_types.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_types.py index d1110570af81..8b2cfdc973dc 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_types.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_node_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeTypesClient._get_default_mtls_endpoint(None) is None assert NodeTypesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -134,6 +135,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NodeTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + NodeTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1952,8 +1956,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2022,17 +2027,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NodeTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2092,9 @@ def test_get_rest_bad_request(request_type=compute.GetNodeTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2169,17 +2177,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NodeTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTypesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2228,8 +2234,9 @@ def test_list_rest_bad_request(request_type=compute.ListNodeTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2296,17 +2303,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NodeTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTypesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2457,11 +2462,14 @@ def test_node_types_base_transport(): def test_node_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTypesTransport( @@ -2482,9 +2490,12 @@ def test_node_types_base_transport_with_credentials_file(): def test_node_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTypesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_organization_security_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_organization_security_policies.py index 4f90c09b14e6..d74c240f72c2 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_organization_security_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_organization_security_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert OrganizationSecurityPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): OrganizationSecurityPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + OrganizationSecurityPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -6073,8 +6078,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6265,18 +6271,22 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_add_association", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_add_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6329,8 +6339,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6615,18 +6626,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_add_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6679,8 +6692,9 @@ def test_copy_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6785,18 +6799,20 @@ def test_copy_rules_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_copy_rules" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_copy_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_copy_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_copy_rules" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_copy_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_copy_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6849,8 +6865,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6955,18 +6972,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7019,8 +7038,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7111,17 +7131,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7174,8 +7197,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7250,18 +7274,22 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_association", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_get_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7316,8 +7344,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7400,18 +7429,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_get_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7464,8 +7495,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7859,18 +7891,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7923,8 +7957,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7991,18 +8026,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8055,8 +8092,9 @@ def test_list_associations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8123,18 +8161,22 @@ def test_list_associations_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_list_associations" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_associations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_list_associations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_associations", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_associations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_list_associations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8196,8 +8238,9 @@ def test_list_preconfigured_expression_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8263,20 +8306,22 @@ def test_list_preconfigured_expression_sets_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets", - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "pre_list_preconfigured_expression_sets", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_list_preconfigured_expression_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8340,8 +8385,9 @@ def test_move_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8446,18 +8492,20 @@ def test_move_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_move_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_move" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_move_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_move" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8510,8 +8558,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8905,18 +8954,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8969,8 +9020,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9255,18 +9307,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9319,8 +9373,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9425,19 +9480,22 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_remove_association", - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_remove_association", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_remove_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9490,8 +9548,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9596,18 +9655,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10041,11 +10102,14 @@ def test_organization_security_policies_base_transport(): def test_organization_security_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OrganizationSecurityPoliciesTransport( @@ -10065,9 +10129,12 @@ def test_organization_security_policies_base_transport_with_credentials_file(): def test_organization_security_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OrganizationSecurityPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_packet_mirrorings.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_packet_mirrorings.py index 0cd320263265..7b3ab5366618 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_packet_mirrorings.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_packet_mirrorings.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PacketMirroringsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PacketMirroringsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PacketMirroringsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3495,8 +3500,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3567,17 +3573,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3637,8 +3646,9 @@ def test_delete_rest_bad_request(request_type=compute.DeletePacketMirroringReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3747,17 +3757,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3812,8 +3824,9 @@ def test_get_rest_bad_request(request_type=compute.GetPacketMirroringRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3896,17 +3909,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PacketMirroringsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3957,8 +3970,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertPacketMirroringReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4161,17 +4175,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4222,8 +4238,9 @@ def test_list_rest_bad_request(request_type=compute.ListPacketMirroringsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4292,17 +4309,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4359,8 +4378,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchPacketMirroringRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4567,17 +4587,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4630,8 +4652,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4772,18 +4795,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5024,11 +5049,14 @@ def test_packet_mirrorings_base_transport(): def test_packet_mirrorings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PacketMirroringsTransport( @@ -5048,9 +5076,12 @@ def test_packet_mirrorings_base_transport_with_credentials_file(): def test_packet_mirrorings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PacketMirroringsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_preview_features.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_preview_features.py index 7fce90e1f598..556e9f5a501d 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_preview_features.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_preview_features.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PreviewFeaturesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( PreviewFeaturesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PreviewFeaturesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2108,8 +2113,9 @@ def test_get_rest_bad_request(request_type=compute.GetPreviewFeatureRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2184,17 +2190,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = PreviewFeaturesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PreviewFeaturesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2245,8 +2251,9 @@ def test_list_rest_bad_request(request_type=compute.ListPreviewFeaturesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2317,17 +2324,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = PreviewFeaturesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PreviewFeaturesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2378,8 +2385,9 @@ def test_update_rest_bad_request(request_type=compute.UpdatePreviewFeatureReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2579,17 +2587,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = PreviewFeaturesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2742,11 +2752,14 @@ def test_preview_features_base_transport(): def test_preview_features_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PreviewFeaturesTransport( @@ -2766,9 +2779,12 @@ def test_preview_features_base_transport_with_credentials_file(): def test_preview_features_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PreviewFeaturesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_projects.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_projects.py index 429c920cfbab..2ab0d9e4d0bf 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_projects.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_projects.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProjectsClient._get_default_mtls_endpoint(None) is None assert ProjectsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ProjectsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ProjectsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -6467,8 +6469,9 @@ def test_disable_xpn_host_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6571,17 +6574,19 @@ def test_disable_xpn_host_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_host" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_host_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_disable_xpn_host" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_disable_xpn_host" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_disable_xpn_host_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_disable_xpn_host" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6634,8 +6639,9 @@ def test_disable_xpn_resource_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6823,17 +6829,20 @@ def test_disable_xpn_resource_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_resource" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_resource_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_disable_xpn_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_disable_xpn_resource" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_disable_xpn_resource_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_disable_xpn_resource" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6886,8 +6895,9 @@ def test_enable_xpn_host_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6990,17 +7000,19 @@ def test_enable_xpn_host_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_host" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_host_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_enable_xpn_host" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_host" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_host_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_enable_xpn_host" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7053,8 +7065,9 @@ def test_enable_xpn_resource_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7242,17 +7255,19 @@ def test_enable_xpn_resource_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_resource" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_resource_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_enable_xpn_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_resource" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_resource_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_enable_xpn_resource" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7303,8 +7318,9 @@ def test_get_rest_bad_request(request_type=compute.GetProjectRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7389,17 +7405,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ProjectsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ProjectsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7448,8 +7462,9 @@ def test_get_xpn_host_rest_bad_request(request_type=compute.GetXpnHostProjectReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7534,17 +7549,19 @@ def test_get_xpn_host_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_host" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_host_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_get_xpn_host" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_host" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_host_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_get_xpn_host" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7597,8 +7614,9 @@ def test_get_xpn_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7661,17 +7679,19 @@ def test_get_xpn_resources_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_resources" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_resources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_get_xpn_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_resources" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_resources_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_get_xpn_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7726,8 +7746,9 @@ def test_list_xpn_hosts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7877,17 +7898,19 @@ def test_list_xpn_hosts_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_list_xpn_hosts" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_list_xpn_hosts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_list_xpn_hosts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_list_xpn_hosts" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_list_xpn_hosts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_list_xpn_hosts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7938,8 +7961,9 @@ def test_move_disk_rest_bad_request(request_type=compute.MoveDiskProjectRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8119,17 +8143,15 @@ def test_move_disk_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_disk" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_disk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_move_disk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ProjectsRestInterceptor, "post_move_disk") as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_move_disk_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ProjectsRestInterceptor, "pre_move_disk") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8180,8 +8202,9 @@ def test_move_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8363,17 +8386,19 @@ def test_move_instance_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_instance" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_move_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_move_instance" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_move_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_move_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8426,8 +8451,9 @@ def test_set_cloud_armor_tier_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8615,17 +8641,20 @@ def test_set_cloud_armor_tier_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_cloud_armor_tier" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_cloud_armor_tier_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_cloud_armor_tier" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_cloud_armor_tier" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_cloud_armor_tier_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_cloud_armor_tier" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8678,8 +8707,9 @@ def test_set_common_instance_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8856,18 +8886,20 @@ def test_set_common_instance_metadata_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_common_instance_metadata" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, - "post_set_common_instance_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_common_instance_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_common_instance_metadata" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_common_instance_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_common_instance_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8920,8 +8952,9 @@ def test_set_default_network_tier_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9109,18 +9142,20 @@ def test_set_default_network_tier_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_default_network_tier" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, - "post_set_default_network_tier_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_default_network_tier" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_default_network_tier" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_default_network_tier_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_default_network_tier" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9173,8 +9208,9 @@ def test_set_managed_protection_tier_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9362,18 +9398,20 @@ def test_set_managed_protection_tier_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_managed_protection_tier" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, - "post_set_managed_protection_tier_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_managed_protection_tier" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_managed_protection_tier" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_managed_protection_tier_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_managed_protection_tier" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9426,8 +9464,9 @@ def test_set_usage_export_bucket_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9609,17 +9648,20 @@ def test_set_usage_export_bucket_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_usage_export_bucket" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_usage_export_bucket_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_usage_export_bucket" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_usage_export_bucket" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_usage_export_bucket_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_usage_export_bucket" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10040,11 +10082,14 @@ def test_projects_base_transport(): def test_projects_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.projects.transports.ProjectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.projects.transports.ProjectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectsTransport( @@ -10064,9 +10109,12 @@ def test_projects_base_transport_with_credentials_file(): def test_projects_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.projects.transports.ProjectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.projects.transports.ProjectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_advertised_prefixes.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_advertised_prefixes.py index e4e0bf66fcdc..77e404396c6f 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_advertised_prefixes.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_advertised_prefixes.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PublicAdvertisedPrefixesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PublicAdvertisedPrefixesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PublicAdvertisedPrefixesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3760,8 +3765,9 @@ def test_announce_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3866,18 +3872,20 @@ def test_announce_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_announce" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, - "post_announce_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_announce" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_announce" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_announce_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_announce" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3930,8 +3938,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4036,17 +4045,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4097,8 +4109,9 @@ def test_get_rest_bad_request(request_type=compute.GetPublicAdvertisedPrefixeReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4187,17 +4200,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4252,8 +4267,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4458,17 +4474,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4521,8 +4540,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4591,17 +4611,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4656,8 +4679,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4862,17 +4886,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4925,8 +4952,9 @@ def test_withdraw_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5031,18 +5059,20 @@ def test_withdraw_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_withdraw" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, - "post_withdraw_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_withdraw" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_withdraw" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_withdraw_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_withdraw" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5279,11 +5309,14 @@ def test_public_advertised_prefixes_base_transport(): def test_public_advertised_prefixes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicAdvertisedPrefixesTransport( @@ -5303,9 +5336,12 @@ def test_public_advertised_prefixes_base_transport_with_credentials_file(): def test_public_advertised_prefixes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicAdvertisedPrefixesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_delegated_prefixes.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_delegated_prefixes.py index 66199becb623..8a642a4a71fe 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_delegated_prefixes.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_public_delegated_prefixes.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PublicDelegatedPrefixesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PublicDelegatedPrefixesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PublicDelegatedPrefixesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4138,8 +4143,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4210,18 +4216,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4283,8 +4291,9 @@ def test_announce_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4393,17 +4402,20 @@ def test_announce_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_announce" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_announce_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_announce" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_announce" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_announce_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_announce" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4460,8 +4472,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4570,17 +4583,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4635,8 +4651,9 @@ def test_get_rest_bad_request(request_type=compute.GetPublicDelegatedPrefixeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4735,17 +4752,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4800,8 +4819,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5015,17 +5035,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5076,8 +5099,9 @@ def test_list_rest_bad_request(request_type=compute.ListPublicDelegatedPrefixesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5146,17 +5170,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5215,8 +5241,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5434,17 +5461,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5501,8 +5531,9 @@ def test_withdraw_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5611,17 +5642,20 @@ def test_withdraw_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_withdraw" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_withdraw_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_withdraw" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_withdraw" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_withdraw_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_withdraw" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5879,11 +5913,14 @@ def test_public_delegated_prefixes_base_transport(): def test_public_delegated_prefixes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicDelegatedPrefixesTransport( @@ -5903,9 +5940,12 @@ def test_public_delegated_prefixes_base_transport_with_credentials_file(): def test_public_delegated_prefixes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicDelegatedPrefixesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_autoscalers.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_autoscalers.py index 357a96bae4ca..f18a131abbfa 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_autoscalers.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_autoscalers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionAutoscalersClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionAutoscalersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionAutoscalersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3641,8 +3646,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionAutoscalerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3747,17 +3753,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3808,8 +3816,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3892,17 +3901,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3953,8 +3964,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionAutoscalerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4173,17 +4185,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4234,8 +4248,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionAutoscalersRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4304,17 +4319,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4367,8 +4384,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionAutoscalerReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4585,17 +4603,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4648,8 +4668,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4790,18 +4811,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4854,8 +4877,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionAutoscalerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5074,17 +5098,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5323,11 +5349,14 @@ def test_region_autoscalers_base_transport(): def test_region_autoscalers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionAutoscalersTransport( @@ -5347,9 +5376,12 @@ def test_region_autoscalers_base_transport_with_credentials_file(): def test_region_autoscalers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionAutoscalersTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_buckets.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_buckets.py index 5acdd4b993f9..1d2251877042 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_buckets.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_buckets.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionBackendBucketsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionBackendBucketsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionBackendBucketsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3940,8 +3945,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionBackendBucketR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4050,17 +4056,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4115,8 +4123,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4207,17 +4216,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4270,8 +4281,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4338,18 +4350,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4400,8 +4414,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionBackendBucketR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4623,17 +4638,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4684,8 +4701,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionBackendBucketsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4754,17 +4772,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4817,8 +4837,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4887,17 +4908,20 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_list_usable_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, + "post_list_usable_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4954,8 +4978,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionBackendBucketReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5181,17 +5206,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5244,8 +5271,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5428,18 +5456,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5492,8 +5522,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5634,18 +5665,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionBackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendBucketsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendBucketsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5928,11 +5961,14 @@ def test_region_backend_buckets_base_transport(): def test_region_backend_buckets_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_backend_buckets.transports.RegionBackendBucketsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_backend_buckets.transports.RegionBackendBucketsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionBackendBucketsTransport( @@ -5952,9 +5988,12 @@ def test_region_backend_buckets_base_transport_with_credentials_file(): def test_region_backend_buckets_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_backend_buckets.transports.RegionBackendBucketsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_backend_buckets.transports.RegionBackendBucketsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionBackendBucketsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_services.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_services.py index 1035dcaa9023..208c8c445072 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_services.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_backend_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionBackendServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionBackendServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionBackendServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5011,8 +5016,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5121,17 +5127,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5186,8 +5194,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5317,17 +5326,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5384,8 +5395,9 @@ def test_get_health_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5528,17 +5540,20 @@ def test_get_health_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_health" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_health_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_get_health" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get_health" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_get_health_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_get_health" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5593,8 +5608,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5661,18 +5677,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5725,8 +5743,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6108,17 +6127,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6169,8 +6190,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionBackendServicesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6239,17 +6261,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6302,8 +6326,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6372,18 +6397,20 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_list_usable_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_list_usable_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6440,8 +6467,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionBackendServiceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6827,17 +6855,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6890,8 +6920,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7074,18 +7105,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7142,8 +7175,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7330,18 +7364,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_set_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7394,8 +7430,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7536,18 +7573,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7606,8 +7645,9 @@ def test_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7993,17 +8033,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8349,11 +8391,14 @@ def test_region_backend_services_base_transport(): def test_region_backend_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionBackendServicesTransport( @@ -8373,9 +8418,12 @@ def test_region_backend_services_base_transport_with_credentials_file(): def test_region_backend_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionBackendServicesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_commitments.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_commitments.py index a8e0dce4895c..18133777c558 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_commitments.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_commitments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionCommitmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionCommitmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionCommitmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3547,8 +3552,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3619,18 +3625,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3683,8 +3691,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionCommitmentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3783,17 +3792,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3844,8 +3855,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionCommitmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4173,17 +4185,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4234,8 +4248,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionCommitmentsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4304,17 +4319,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4367,8 +4384,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4509,18 +4527,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4573,8 +4593,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionCommitmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4902,17 +4923,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4965,8 +4988,9 @@ def test_update_reservations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5267,18 +5291,20 @@ def test_update_reservations_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_update_reservations" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, - "post_update_reservations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_update_reservations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_update_reservations" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, + "post_update_reservations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_update_reservations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5519,11 +5545,14 @@ def test_region_commitments_base_transport(): def test_region_commitments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCommitmentsTransport( @@ -5543,9 +5572,12 @@ def test_region_commitments_base_transport_with_credentials_file(): def test_region_commitments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCommitmentsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_composite_health_checks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_composite_health_checks.py index f163e3d0e958..fdee60a0e91d 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_composite_health_checks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_composite_health_checks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionCompositeHealthChecksClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionCompositeHealthChecksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionCompositeHealthChecksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3552,8 +3557,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3624,18 +3630,21 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3697,8 +3706,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3807,18 +3817,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3875,8 +3887,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3963,17 +3976,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4028,8 +4044,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4222,18 +4239,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4286,8 +4305,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4356,17 +4376,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4425,8 +4448,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4623,18 +4647,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4687,8 +4713,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4831,20 +4858,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5085,11 +5114,14 @@ def test_region_composite_health_checks_base_transport(): def test_region_composite_health_checks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCompositeHealthChecksTransport( @@ -5109,9 +5141,12 @@ def test_region_composite_health_checks_base_transport_with_credentials_file(): def test_region_composite_health_checks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCompositeHealthChecksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_settings.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_settings.py index 1f4c0231dd08..231a10d2e8b4 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_settings.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_settings.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionDiskSettingsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): RegionDiskSettingsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionDiskSettingsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1911,8 +1916,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionDiskSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1972,17 +1978,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionDiskSettingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDiskSettingsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionDiskSettingsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDiskSettingsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDiskSettingsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionDiskSettingsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDiskSettingsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2033,8 +2041,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionDiskSettingReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2213,17 +2222,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionDiskSettingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDiskSettingsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionDiskSettingsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDiskSettingsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDiskSettingsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionDiskSettingsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDiskSettingsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2355,11 +2366,14 @@ def test_region_disk_settings_base_transport(): def test_region_disk_settings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_disk_settings.transports.RegionDiskSettingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_disk_settings.transports.RegionDiskSettingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDiskSettingsTransport( @@ -2379,9 +2393,12 @@ def test_region_disk_settings_base_transport_with_credentials_file(): def test_region_disk_settings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_disk_settings.transports.RegionDiskSettingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_disk_settings.transports.RegionDiskSettingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDiskSettingsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_types.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_types.py index faf6d91fa594..71b03ef924d5 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_types.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disk_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionDiskTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionDiskTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionDiskTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1718,8 +1723,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionDiskTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1800,17 +1806,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionDiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDiskTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1861,8 +1867,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionDiskTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1931,17 +1938,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionDiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDiskTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2073,11 +2080,14 @@ def test_region_disk_types_base_transport(): def test_region_disk_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDiskTypesTransport( @@ -2098,9 +2108,12 @@ def test_region_disk_types_base_transport_with_credentials_file(): def test_region_disk_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDiskTypesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disks.py index f0f723e84f76..eff35bd15762 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_disks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionDisksClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegionDisksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RegionDisksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -7432,8 +7436,9 @@ def test_add_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7623,18 +7628,20 @@ def test_add_resource_policies_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_add_resource_policies" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_add_resource_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_add_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_add_resource_policies" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_add_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_add_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7685,8 +7692,9 @@ def test_bulk_insert_rest_bad_request(request_type=compute.BulkInsertRegionDiskR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7877,17 +7885,19 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_bulk_insert" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_bulk_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7940,8 +7950,9 @@ def test_create_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8165,17 +8176,19 @@ def test_create_snapshot_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_create_snapshot" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_create_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_create_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_create_snapshot" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_create_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_create_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8226,8 +8239,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8332,17 +8346,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8393,8 +8405,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8555,17 +8568,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8616,8 +8627,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8684,17 +8696,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8745,8 +8759,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8990,17 +9005,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9051,8 +9064,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionDisksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9121,17 +9135,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9182,8 +9194,9 @@ def test_remove_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9373,18 +9386,20 @@ def test_remove_resource_policies_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_remove_resource_policies" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_remove_resource_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_remove_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_remove_resource_policies" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_remove_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_remove_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9435,8 +9450,9 @@ def test_resize_rest_bad_request(request_type=compute.ResizeRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9619,17 +9635,15 @@ def test_resize_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_resize") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_resize") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9682,8 +9696,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9866,17 +9881,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9927,8 +9944,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsRegionDiskReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10112,17 +10130,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10175,8 +10195,9 @@ def test_start_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10366,18 +10387,20 @@ def test_start_async_replication_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_start_async_replication" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_start_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_start_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_start_async_replication" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_start_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_start_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10430,8 +10453,9 @@ def test_stop_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10536,18 +10560,20 @@ def test_stop_async_replication_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_stop_async_replication" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_stop_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_stop_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_stop_async_replication" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_stop_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_stop_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10600,8 +10626,9 @@ def test_stop_group_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10791,18 +10818,20 @@ def test_stop_group_async_replication_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_stop_group_async_replication" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_stop_group_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_stop_group_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_stop_group_async_replication" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_stop_group_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_stop_group_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10855,8 +10884,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10997,17 +11027,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11060,8 +11093,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11305,17 +11339,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_update") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11774,11 +11806,14 @@ def test_region_disks_base_transport(): def test_region_disks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDisksTransport( @@ -11798,9 +11833,12 @@ def test_region_disks_base_transport_with_credentials_file(): def test_region_disks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDisksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_aggregation_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_aggregation_policies.py index 54e8cfd69160..e42dea160240 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_aggregation_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_aggregation_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( RegionHealthAggregationPoliciesClient._get_default_mtls_endpoint(None) is None @@ -150,6 +151,12 @@ def test__get_default_mtls_endpoint(): RegionHealthAggregationPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthAggregationPoliciesClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3597,8 +3604,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3669,19 +3677,22 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_aggregated_list", - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "pre_aggregated_list", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3743,8 +3754,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3853,18 +3865,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3921,8 +3935,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4011,18 +4026,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4077,8 +4094,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4272,18 +4290,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4336,8 +4356,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4406,18 +4427,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4479,8 +4502,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4678,18 +4702,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4742,8 +4768,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4886,20 +4913,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5140,11 +5169,14 @@ def test_region_health_aggregation_policies_base_transport(): def test_region_health_aggregation_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthAggregationPoliciesTransport( @@ -5164,9 +5196,12 @@ def test_region_health_aggregation_policies_base_transport_with_credentials_file def test_region_health_aggregation_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthAggregationPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_check_services.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_check_services.py index 8ed5dc0170c1..0e10f5c20932 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_check_services.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_check_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionHealthCheckServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionHealthCheckServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthCheckServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3528,8 +3533,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3600,18 +3606,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3673,8 +3681,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3783,17 +3792,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3848,8 +3860,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionHealthCheckServiceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3946,17 +3959,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4009,8 +4025,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4211,17 +4228,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4274,8 +4294,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4344,17 +4365,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4413,8 +4437,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4619,17 +4644,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4682,8 +4710,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4824,18 +4853,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5076,11 +5109,14 @@ def test_region_health_check_services_base_transport(): def test_region_health_check_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthCheckServicesTransport( @@ -5100,9 +5136,12 @@ def test_region_health_check_services_base_transport_with_credentials_file(): def test_region_health_check_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthCheckServicesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_checks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_checks.py index 58f481743852..59e33915d6b9 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_checks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_checks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionHealthChecksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionHealthChecksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthChecksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3629,8 +3634,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionHealthCheckReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3739,17 +3745,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3804,8 +3812,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3896,17 +3905,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3957,8 +3968,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionHealthCheckReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4204,17 +4216,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4265,8 +4279,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionHealthChecksReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4335,17 +4350,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4400,8 +4417,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionHealthCheckReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4651,17 +4669,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4714,8 +4734,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4856,18 +4877,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4924,8 +4947,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionHealthCheckReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5175,17 +5199,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5424,11 +5450,14 @@ def test_region_health_checks_base_transport(): def test_region_health_checks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthChecksTransport( @@ -5448,9 +5477,12 @@ def test_region_health_checks_base_transport_with_credentials_file(): def test_region_health_checks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthChecksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_sources.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_sources.py index b4a6805299ee..ac6305edb6fb 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_sources.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_health_sources.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionHealthSourcesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionHealthSourcesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthSourcesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3507,8 +3512,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3579,18 +3585,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3647,8 +3655,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionHealthSourceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3757,17 +3766,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3822,8 +3833,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionHealthSourceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3912,17 +3924,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3973,8 +3987,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionHealthSourceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4164,17 +4179,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4225,8 +4242,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionHealthSourcesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4295,17 +4313,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4360,8 +4380,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionHealthSourceRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4555,17 +4576,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4618,8 +4641,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4760,18 +4784,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5012,11 +5038,14 @@ def test_region_health_sources_base_transport(): def test_region_health_sources_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthSourcesTransport( @@ -5036,9 +5065,12 @@ def test_region_health_sources_base_transport_with_credentials_file(): def test_region_health_sources_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthSourcesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_manager_resize_requests.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_manager_resize_requests.py index f75eefcec778..383672bc6293 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_manager_resize_requests.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_manager_resize_requests.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( RegionInstanceGroupManagerResizeRequestsClient._get_default_mtls_endpoint(None) @@ -155,6 +156,12 @@ def test__get_default_mtls_endpoint(): ) == non_googleapi ) + assert ( + RegionInstanceGroupManagerResizeRequestsClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3162,8 +3169,9 @@ def test_cancel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3273,19 +3281,22 @@ def test_cancel_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_cancel", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_cancel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "pre_cancel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_cancel", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_cancel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "pre_cancel", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3343,8 +3354,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3454,19 +3466,22 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_delete", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_delete", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "pre_delete", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3524,8 +3539,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3615,18 +3631,22 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_get", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "pre_get", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3688,8 +3708,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3951,19 +3972,22 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_insert", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_insert", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "pre_insert", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4020,8 +4044,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4100,18 +4125,22 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_list", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagerResizeRequestsRestInterceptor, + "pre_list", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4315,11 +4344,14 @@ def test_region_instance_group_manager_resize_requests_base_transport(): def test_region_instance_group_manager_resize_requests_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_group_manager_resize_requests.transports.RegionInstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_group_manager_resize_requests.transports.RegionInstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupManagerResizeRequestsTransport( @@ -4339,9 +4371,12 @@ def test_region_instance_group_manager_resize_requests_base_transport_with_crede def test_region_instance_group_manager_resize_requests_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_group_manager_resize_requests.transports.RegionInstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_group_manager_resize_requests.transports.RegionInstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupManagerResizeRequestsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_managers.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_managers.py index 4af51bcbce7d..ead819026e75 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_managers.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_group_managers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstanceGroupManagersClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionInstanceGroupManagersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstanceGroupManagersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -12619,8 +12624,9 @@ def test_abandon_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12814,18 +12820,22 @@ def test_abandon_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_abandon_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_abandon_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_abandon_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_abandon_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_abandon_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_abandon_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12882,8 +12892,9 @@ def test_adopt_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13089,18 +13100,21 @@ def test_adopt_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_adopt_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_adopt_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_adopt_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_adopt_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_adopt_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_adopt_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13157,8 +13171,9 @@ def test_apply_updates_to_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13357,20 +13372,22 @@ def test_apply_updates_to_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_apply_updates_to_instances", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_apply_updates_to_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13429,8 +13446,9 @@ def test_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13636,18 +13654,22 @@ def test_create_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_create_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_create_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_create_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13704,8 +13726,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13814,18 +13837,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13882,8 +13907,9 @@ def test_delete_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14078,18 +14104,22 @@ def test_delete_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_delete_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_delete_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_delete_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14146,8 +14176,9 @@ def test_delete_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14343,20 +14374,22 @@ def test_delete_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_delete_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_delete_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14415,8 +14448,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14528,17 +14562,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14593,8 +14630,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14940,18 +14978,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15004,8 +15044,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15074,17 +15115,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15146,8 +15190,9 @@ def test_list_errors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15216,18 +15261,20 @@ def test_list_errors_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_list_errors" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_errors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_list_errors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_list_errors" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_errors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_list_errors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15289,8 +15336,9 @@ def test_list_managed_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15359,20 +15407,22 @@ def test_list_managed_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_managed_instances", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_managed_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_list_managed_instances", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_managed_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_managed_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_list_managed_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15434,8 +15484,9 @@ def test_list_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15504,20 +15555,22 @@ def test_list_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_list_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_list_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15583,8 +15636,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15934,18 +15988,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16002,8 +16058,9 @@ def test_patch_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16211,20 +16268,22 @@ def test_patch_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_patch_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_patch_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16283,8 +16342,9 @@ def test_recreate_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16478,18 +16538,22 @@ def test_recreate_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_recreate_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_recreate_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_recreate_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_recreate_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_recreate_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_recreate_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16546,8 +16610,9 @@ def test_resize_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16656,18 +16721,20 @@ def test_resize_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_resize_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_resize" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resize_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_resize" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16724,8 +16791,9 @@ def test_resize_advanced_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16920,18 +16988,21 @@ def test_resize_advanced_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_resize_advanced" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_resize_advanced_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_resize_advanced" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resize_advanced", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resize_advanced_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_resize_advanced" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16988,8 +17059,9 @@ def test_resume_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17183,18 +17255,22 @@ def test_resume_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_resume_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_resume_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_resume_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resume_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resume_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_resume_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17251,8 +17327,9 @@ def test_set_auto_healing_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17450,20 +17527,22 @@ def test_set_auto_healing_policies_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_auto_healing_policies", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_auto_healing_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_set_auto_healing_policies", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_auto_healing_policies", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_auto_healing_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_set_auto_healing_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17520,8 +17599,9 @@ def test_set_instance_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17717,20 +17797,22 @@ def test_set_instance_template_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_instance_template", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_instance_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_set_instance_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_instance_template", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_instance_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_set_instance_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17787,8 +17869,9 @@ def test_set_target_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17983,18 +18066,22 @@ def test_set_target_pools_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_set_target_pools" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_target_pools_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_set_target_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_target_pools", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_target_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_set_target_pools", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18051,8 +18138,9 @@ def test_start_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18246,18 +18334,21 @@ def test_start_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_start_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_start_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_start_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_start_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_start_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_start_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18314,8 +18405,9 @@ def test_stop_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18510,18 +18602,20 @@ def test_stop_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_stop_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_stop_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_stop_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_stop_instances" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_stop_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_stop_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18578,8 +18672,9 @@ def test_suspend_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18773,18 +18868,22 @@ def test_suspend_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_suspend_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_suspend_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_suspend_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_suspend_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_suspend_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_suspend_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18837,8 +18936,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18981,20 +19081,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19053,8 +19155,9 @@ def test_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19404,18 +19507,20 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_update_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_update_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19472,8 +19577,9 @@ def test_update_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19683,20 +19789,22 @@ def test_update_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_update_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_update_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20404,11 +20512,14 @@ def test_region_instance_group_managers_base_transport(): def test_region_instance_group_managers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupManagersTransport( @@ -20428,9 +20539,12 @@ def test_region_instance_group_managers_base_transport_with_credentials_file(): def test_region_instance_group_managers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupManagersTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_groups.py index 2d3e74adfae5..6799e0a9726e 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstanceGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionInstanceGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstanceGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2704,8 +2709,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionInstanceGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2794,17 +2800,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2855,8 +2863,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionInstanceGroupsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2925,17 +2934,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2994,8 +3005,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3154,18 +3166,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, - "post_list_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3227,8 +3241,9 @@ def test_set_named_ports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3423,18 +3438,20 @@ def test_set_named_ports_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_set_named_ports" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, - "post_set_named_ports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_set_named_ports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_set_named_ports" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, + "post_set_named_ports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_set_named_ports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3487,8 +3504,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3629,18 +3647,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3839,11 +3859,14 @@ def test_region_instance_groups_base_transport(): def test_region_instance_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupsTransport( @@ -3863,9 +3886,12 @@ def test_region_instance_groups_base_transport_with_credentials_file(): def test_region_instance_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_templates.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_templates.py index f653954efec1..1cf3cd5d5cf1 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_templates.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instance_templates.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstanceTemplatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): RegionInstanceTemplatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstanceTemplatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2599,8 +2604,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2709,17 +2715,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2774,8 +2783,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionInstanceTemplateRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2856,17 +2866,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2919,8 +2931,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3326,17 +3339,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3387,8 +3403,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionInstanceTemplatesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3457,17 +3474,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3643,11 +3662,14 @@ def test_region_instance_templates_base_transport(): def test_region_instance_templates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceTemplatesTransport( @@ -3667,9 +3689,12 @@ def test_region_instance_templates_base_transport_with_credentials_file(): def test_region_instance_templates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceTemplatesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instances.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instances.py index 0e2fd472497a..3739f6804256 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instances.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instances.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstancesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionInstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstancesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1664,8 +1669,9 @@ def test_bulk_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2069,17 +2075,19 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = RegionInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstancesRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.RegionInstancesRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstancesRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstancesRestInterceptor, "post_bulk_insert" + ) as post, + mock.patch.object( + transports.RegionInstancesRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstancesRestInterceptor, "pre_bulk_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2188,11 +2196,14 @@ def test_region_instances_base_transport(): def test_region_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstancesTransport( @@ -2212,9 +2223,12 @@ def test_region_instances_base_transport_with_credentials_file(): def test_region_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstancesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshot_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshot_groups.py index 50ade3d3a70a..3d87e777412a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshot_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshot_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstantSnapshotGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionInstantSnapshotGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstantSnapshotGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3280,8 +3285,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3390,18 +3396,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3458,8 +3466,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3546,17 +3555,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3611,8 +3623,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3679,18 +3692,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3743,8 +3758,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3944,18 +3960,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4008,8 +4026,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4082,17 +4101,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4147,8 +4169,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4331,18 +4354,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4395,8 +4420,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4539,20 +4565,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotGroupsRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotGroupsRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4793,11 +4821,14 @@ def test_region_instant_snapshot_groups_base_transport(): def test_region_instant_snapshot_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instant_snapshot_groups.transports.RegionInstantSnapshotGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instant_snapshot_groups.transports.RegionInstantSnapshotGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstantSnapshotGroupsTransport( @@ -4817,9 +4848,12 @@ def test_region_instant_snapshot_groups_base_transport_with_credentials_file(): def test_region_instant_snapshot_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instant_snapshot_groups.transports.RegionInstantSnapshotGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instant_snapshot_groups.transports.RegionInstantSnapshotGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstantSnapshotGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshots.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshots.py index 39bdfdae88ad..38c460b13905 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshots.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_instant_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstantSnapshotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionInstantSnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstantSnapshotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3657,8 +3662,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3767,17 +3773,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3832,8 +3841,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionInstantSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3941,17 +3951,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4004,8 +4016,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4072,18 +4085,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4136,8 +4151,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4339,17 +4355,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4400,8 +4419,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionInstantSnapshotsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4470,17 +4490,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4535,8 +4557,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4719,18 +4742,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4783,8 +4808,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4968,18 +4994,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_set_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5032,8 +5060,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5174,18 +5203,21 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5447,11 +5479,14 @@ def test_region_instant_snapshots_base_transport(): def test_region_instant_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstantSnapshotsTransport( @@ -5471,9 +5506,12 @@ def test_region_instant_snapshots_base_transport_with_credentials_file(): def test_region_instant_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstantSnapshotsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_mig_members.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_mig_members.py index 04269ef89f77..503ed107275e 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_mig_members.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_mig_members.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionMultiMigMembersClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): RegionMultiMigMembersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionMultiMigMembersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1780,8 +1785,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionMultiMigMemberReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1859,17 +1865,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionMultiMigMembersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionMultiMigMembersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionMultiMigMembersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionMultiMigMembersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionMultiMigMembersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionMultiMigMembersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionMultiMigMembersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1920,8 +1928,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionMultiMigMembersReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1990,17 +1999,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionMultiMigMembersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionMultiMigMembersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionMultiMigMembersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionMultiMigMembersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionMultiMigMembersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionMultiMigMembersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionMultiMigMembersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2132,11 +2143,14 @@ def test_region_multi_mig_members_base_transport(): def test_region_multi_mig_members_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_multi_mig_members.transports.RegionMultiMigMembersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_multi_mig_members.transports.RegionMultiMigMembersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionMultiMigMembersTransport( @@ -2157,9 +2171,12 @@ def test_region_multi_mig_members_base_transport_with_credentials_file(): def test_region_multi_mig_members_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_multi_mig_members.transports.RegionMultiMigMembersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_multi_mig_members.transports.RegionMultiMigMembersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionMultiMigMembersTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_migs.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_migs.py index a41e5de9cc4b..152b7e3bc0e8 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_migs.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_multi_migs.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionMultiMigsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionMultiMigsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionMultiMigsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2546,8 +2551,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionMultiMigReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2652,17 +2658,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionMultiMigsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2713,8 +2721,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionMultiMigRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2789,17 +2798,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionMultiMigsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionMultiMigsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2850,8 +2859,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionMultiMigReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3083,17 +3093,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionMultiMigsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3144,8 +3156,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionMultiMigsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3218,17 +3231,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionMultiMigsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionMultiMigsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionMultiMigsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionMultiMigsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3402,11 +3415,14 @@ def test_region_multi_migs_base_transport(): def test_region_multi_migs_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_multi_migs.transports.RegionMultiMigsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_multi_migs.transports.RegionMultiMigsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionMultiMigsTransport( @@ -3426,9 +3442,12 @@ def test_region_multi_migs_base_transport_with_credentials_file(): def test_region_multi_migs_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_multi_migs.transports.RegionMultiMigsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_multi_migs.transports.RegionMultiMigsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionMultiMigsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_endpoint_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_endpoint_groups.py index 44f12c0124fb..989cf30e7a29 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_endpoint_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_endpoint_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNetworkEndpointGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionNetworkEndpointGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNetworkEndpointGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3833,8 +3838,9 @@ def test_attach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4040,20 +4046,22 @@ def test_attach_network_endpoints_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints", - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "pre_attach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints", + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "pre_attach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4110,8 +4118,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4220,18 +4229,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4288,8 +4299,9 @@ def test_detach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4495,20 +4507,22 @@ def test_detach_network_endpoints_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints", - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "pre_detach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints", + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "pre_detach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4565,8 +4579,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4659,17 +4674,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4724,8 +4742,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4951,18 +4970,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5015,8 +5036,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5085,17 +5107,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5154,8 +5179,9 @@ def test_list_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5228,20 +5254,22 @@ def test_list_network_endpoints_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints", - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "pre_list_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints", + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "pre_list_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5489,11 +5517,14 @@ def test_region_network_endpoint_groups_base_transport(): def test_region_network_endpoint_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkEndpointGroupsTransport( @@ -5513,9 +5544,12 @@ def test_region_network_endpoint_groups_base_transport_with_credentials_file(): def test_region_network_endpoint_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkEndpointGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_firewall_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_firewall_policies.py index 75ec9f1ca887..988d00f46971 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_firewall_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_firewall_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNetworkFirewallPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): RegionNetworkFirewallPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNetworkFirewallPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -7505,8 +7510,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7700,18 +7706,22 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_add_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_add_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7768,8 +7778,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8018,18 +8029,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_add_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8086,8 +8099,9 @@ def test_clone_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8196,18 +8210,20 @@ def test_clone_rules_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_clone_rules" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_clone_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_clone_rules" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_clone_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8264,8 +8280,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8374,18 +8391,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8442,8 +8461,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8538,18 +8558,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8606,8 +8628,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8684,18 +8707,22 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_get_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8750,8 +8777,9 @@ def test_get_effective_firewalls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8819,20 +8847,22 @@ def test_get_effective_firewalls_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_effective_firewalls", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_effective_firewalls_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "pre_get_effective_firewalls", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_effective_firewalls", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_effective_firewalls_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_get_effective_firewalls", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8894,8 +8924,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8962,18 +8993,22 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_iam_policy", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_get_iam_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9030,8 +9065,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9126,18 +9162,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9190,8 +9228,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9471,18 +9510,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9535,8 +9576,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9603,18 +9645,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9671,8 +9715,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9956,18 +10001,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10024,8 +10071,9 @@ def test_patch_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10219,19 +10267,22 @@ def test_patch_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_patch_association", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_patch_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_patch_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_patch_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_patch_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10288,8 +10339,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10538,18 +10590,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10606,8 +10660,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10716,20 +10771,22 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_remove_association", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "pre_remove_association", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_remove_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_remove_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10786,8 +10843,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10896,18 +10954,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10960,8 +11020,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11144,18 +11205,22 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_set_iam_policy", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_set_iam_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11208,8 +11273,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11352,20 +11418,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11843,11 +11911,14 @@ def test_region_network_firewall_policies_base_transport(): def test_region_network_firewall_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkFirewallPoliciesTransport( @@ -11867,9 +11938,12 @@ def test_region_network_firewall_policies_base_transport_with_credentials_file() def test_region_network_firewall_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkFirewallPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_policies.py index 8f8ef668a391..c270e9aee5ba 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_network_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNetworkPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionNetworkPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNetworkPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -6025,8 +6030,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6214,18 +6220,20 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_add_association" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_add_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6282,8 +6290,9 @@ def test_add_traffic_classification_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6505,20 +6514,22 @@ def test_add_traffic_classification_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_add_traffic_classification_rule", - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_add_traffic_classification_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "pre_add_traffic_classification_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_add_traffic_classification_rule", + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_add_traffic_classification_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "pre_add_traffic_classification_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6571,8 +6582,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6643,18 +6655,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6714,8 +6728,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionNetworkPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6824,17 +6839,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6889,8 +6906,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionNetworkPolicyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6973,17 +6991,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7040,8 +7060,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7110,18 +7131,20 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_get_association" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_get_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7180,8 +7203,9 @@ def test_get_traffic_classification_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7260,20 +7284,22 @@ def test_get_traffic_classification_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_get_traffic_classification_rule", - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_get_traffic_classification_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "pre_get_traffic_classification_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_get_traffic_classification_rule", + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_get_traffic_classification_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "pre_get_traffic_classification_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7329,8 +7355,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionNetworkPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7554,17 +7581,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7615,8 +7644,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionNetworkPoliciesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7683,17 +7713,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7748,8 +7780,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionNetworkPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7977,17 +8010,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8044,8 +8079,9 @@ def test_patch_traffic_classification_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8267,20 +8303,22 @@ def test_patch_traffic_classification_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_patch_traffic_classification_rule", - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_patch_traffic_classification_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "pre_patch_traffic_classification_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_patch_traffic_classification_rule", + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_patch_traffic_classification_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "pre_patch_traffic_classification_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8339,8 +8377,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8449,18 +8488,20 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "post_remove_association" - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "post_remove_association" + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, "pre_remove_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8517,8 +8558,9 @@ def test_remove_traffic_classification_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8627,20 +8669,22 @@ def test_remove_traffic_classification_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_remove_traffic_classification_rule", - ) as post, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "post_remove_traffic_classification_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkPoliciesRestInterceptor, - "pre_remove_traffic_classification_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_remove_traffic_classification_rule", + ) as post, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "post_remove_traffic_classification_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkPoliciesRestInterceptor, + "pre_remove_traffic_classification_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9017,11 +9061,14 @@ def test_region_network_policies_base_transport(): def test_region_network_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_network_policies.transports.RegionNetworkPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_network_policies.transports.RegionNetworkPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkPoliciesTransport( @@ -9041,9 +9088,12 @@ def test_region_network_policies_base_transport_with_credentials_file(): def test_region_network_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_network_policies.transports.RegionNetworkPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_network_policies.transports.RegionNetworkPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_notification_endpoints.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_notification_endpoints.py index 4f10b68f39f5..4dadb9be4a49 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_notification_endpoints.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_notification_endpoints.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNotificationEndpointsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionNotificationEndpointsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNotificationEndpointsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3118,8 +3123,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3190,18 +3196,21 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3263,8 +3272,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3373,18 +3383,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3441,8 +3453,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3521,17 +3534,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3586,8 +3602,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3783,18 +3800,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3847,8 +3866,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3917,17 +3937,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3982,8 +4005,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4126,20 +4150,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4359,11 +4385,14 @@ def test_region_notification_endpoints_base_transport(): def test_region_notification_endpoints_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNotificationEndpointsTransport( @@ -4383,9 +4412,12 @@ def test_region_notification_endpoints_base_transport_with_credentials_file(): def test_region_notification_endpoints_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNotificationEndpointsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_operations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_operations.py index d3f27b1a775f..b897cec4429a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_operations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): RegionOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2126,8 +2131,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionOperationReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2187,17 +2193,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2253,8 +2261,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2359,17 +2368,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionOperationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2420,8 +2429,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionOperationsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2490,17 +2500,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2551,8 +2563,9 @@ def test_wait_rest_bad_request(request_type=compute.WaitRegionOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2657,17 +2670,19 @@ def test_wait_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_wait" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_wait_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_wait" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_wait" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_wait_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "pre_wait" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2841,11 +2856,14 @@ def test_region_operations_base_transport(): def test_region_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionOperationsTransport( @@ -2865,9 +2883,12 @@ def test_region_operations_base_transport_with_credentials_file(): def test_region_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionOperationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_security_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_security_policies.py index 9bc8f78e0377..37fde8d998c7 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_security_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_security_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSecurityPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionSecurityPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSecurityPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5047,8 +5052,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5337,17 +5343,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5404,8 +5413,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5514,17 +5524,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5579,8 +5592,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSecurityPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5675,17 +5689,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5742,8 +5758,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5830,17 +5847,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5893,8 +5913,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6288,17 +6309,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6349,8 +6373,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSecurityPoliciesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6417,17 +6442,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6482,8 +6509,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionSecurityPolicyRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6881,17 +6909,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6948,8 +6978,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7238,18 +7269,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7306,8 +7339,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7416,18 +7450,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7480,8 +7516,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7665,18 +7702,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, - "post_set_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7976,11 +8015,14 @@ def test_region_security_policies_base_transport(): def test_region_security_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSecurityPoliciesTransport( @@ -8000,9 +8042,12 @@ def test_region_security_policies_base_transport_with_credentials_file(): def test_region_security_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSecurityPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshot_settings.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshot_settings.py index 3ab5a89317c0..34957de204f1 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshot_settings.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshot_settings.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSnapshotSettingsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): RegionSnapshotSettingsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSnapshotSettingsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1929,8 +1934,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSnapshotSettingReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1990,17 +1996,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSnapshotSettingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotSettingsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSnapshotSettingsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotSettingsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotSettingsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSnapshotSettingsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotSettingsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2051,8 +2059,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionSnapshotSettingR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2234,17 +2243,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionSnapshotSettingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotSettingsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionSnapshotSettingsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotSettingsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotSettingsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionSnapshotSettingsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotSettingsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2376,11 +2387,14 @@ def test_region_snapshot_settings_base_transport(): def test_region_snapshot_settings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_snapshot_settings.transports.RegionSnapshotSettingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_snapshot_settings.transports.RegionSnapshotSettingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSnapshotSettingsTransport( @@ -2400,9 +2414,12 @@ def test_region_snapshot_settings_base_transport_with_credentials_file(): def test_region_snapshot_settings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_snapshot_settings.transports.RegionSnapshotSettingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_snapshot_settings.transports.RegionSnapshotSettingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSnapshotSettingsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshots.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshots.py index 1df1c32f153d..980d8fb752ac 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshots.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSnapshotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionSnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSnapshotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3603,8 +3608,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionSnapshotReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3709,17 +3715,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3770,8 +3778,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3913,17 +3922,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionSnapshotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3976,8 +3985,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4044,17 +4054,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4105,8 +4118,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionSnapshotReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4328,17 +4342,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4389,8 +4405,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSnapshotsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4459,17 +4476,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionSnapshotsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4522,8 +4539,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4706,17 +4724,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4769,8 +4790,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4954,17 +4976,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5017,8 +5041,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5159,18 +5184,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5432,11 +5459,14 @@ def test_region_snapshots_base_transport(): def test_region_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_snapshots.transports.RegionSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_snapshots.transports.RegionSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSnapshotsTransport( @@ -5456,9 +5486,12 @@ def test_region_snapshots_base_transport_with_credentials_file(): def test_region_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_snapshots.transports.RegionSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_snapshots.transports.RegionSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSnapshotsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_certificates.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_certificates.py index 4eeba306a70e..76851c48d4f5 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_certificates.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_certificates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSslCertificatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionSslCertificatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSslCertificatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2803,8 +2808,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2913,17 +2919,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2978,8 +2986,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSslCertificateReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3068,17 +3077,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3131,8 +3142,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3334,17 +3346,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3395,8 +3409,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSslCertificatesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3465,17 +3480,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3528,8 +3545,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3670,18 +3688,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3880,11 +3900,14 @@ def test_region_ssl_certificates_base_transport(): def test_region_ssl_certificates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslCertificatesTransport( @@ -3904,9 +3927,12 @@ def test_region_ssl_certificates_base_transport_with_credentials_file(): def test_region_ssl_certificates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslCertificatesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_policies.py index f7d104be4b69..b4990b0900d7 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_ssl_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSslPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionSslPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSslPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3424,8 +3429,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionSslPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3530,17 +3536,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3591,8 +3599,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3677,17 +3686,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3738,8 +3749,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionSslPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3932,17 +3944,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3993,8 +4007,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSslPoliciesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4063,17 +4078,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4126,8 +4143,9 @@ def test_list_available_features_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4190,18 +4208,20 @@ def test_list_available_features_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_list_available_features" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, - "post_list_available_features_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_list_available_features" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_list_available_features" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, + "post_list_available_features_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_list_available_features" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4257,8 +4277,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionSslPolicyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4451,17 +4472,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4514,8 +4537,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4656,18 +4680,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4910,11 +4936,14 @@ def test_region_ssl_policies_base_transport(): def test_region_ssl_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslPoliciesTransport( @@ -4934,9 +4963,12 @@ def test_region_ssl_policies_base_transport_with_credentials_file(): def test_region_ssl_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_http_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_http_proxies.py index a98f1c7c6d1d..fca54c737df2 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_http_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_http_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionTargetHttpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionTargetHttpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionTargetHttpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3233,8 +3238,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3343,17 +3349,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3408,8 +3417,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionTargetHttpProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3498,17 +3508,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3561,8 +3573,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3754,17 +3767,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3815,8 +3831,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionTargetHttpProxiesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3885,17 +3902,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3954,8 +3973,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4138,18 +4158,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, - "post_set_url_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4202,8 +4224,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4344,18 +4367,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4575,11 +4602,14 @@ def test_region_target_http_proxies_base_transport(): def test_region_target_http_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpProxiesTransport( @@ -4599,9 +4629,12 @@ def test_region_target_http_proxies_base_transport_with_credentials_file(): def test_region_target_http_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_https_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_https_proxies.py index 300e6cc9637a..67171a9cd2cc 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_https_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_https_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionTargetHttpsProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionTargetHttpsProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionTargetHttpsProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4115,8 +4120,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4225,17 +4231,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4290,8 +4299,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionTargetHttpsProxyRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4398,17 +4408,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4461,8 +4473,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4663,17 +4676,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4726,8 +4742,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4796,17 +4813,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4865,8 +4885,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5071,17 +5092,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5138,8 +5162,9 @@ def test_set_ssl_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5333,18 +5358,22 @@ def test_set_ssl_certificates_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_set_ssl_certificates" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, - "post_set_ssl_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_set_ssl_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_set_ssl_certificates", + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_set_ssl_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "pre_set_ssl_certificates", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5401,8 +5430,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5585,18 +5615,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, - "post_set_url_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5649,8 +5681,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5791,18 +5824,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6066,11 +6103,14 @@ def test_region_target_https_proxies_base_transport(): def test_region_target_https_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpsProxiesTransport( @@ -6090,9 +6130,12 @@ def test_region_target_https_proxies_base_transport_with_credentials_file(): def test_region_target_https_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpsProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_tcp_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_tcp_proxies.py index 541537a24495..106233f76c8b 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_tcp_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_target_tcp_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionTargetTcpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionTargetTcpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionTargetTcpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2807,8 +2812,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2917,17 +2923,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2982,8 +2991,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionTargetTcpProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3070,17 +3080,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3133,8 +3145,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3325,17 +3338,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3386,8 +3402,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionTargetTcpProxiesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3456,17 +3473,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3519,8 +3538,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3661,18 +3681,21 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3871,11 +3894,14 @@ def test_region_target_tcp_proxies_base_transport(): def test_region_target_tcp_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetTcpProxiesTransport( @@ -3895,9 +3921,12 @@ def test_region_target_tcp_proxies_base_transport_with_credentials_file(): def test_region_target_tcp_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetTcpProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_url_maps.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_url_maps.py index 0a36e7b42d96..f501139013e1 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_url_maps.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_url_maps.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionUrlMapsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionUrlMapsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionUrlMapsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4256,8 +4261,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionUrlMapRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4362,17 +4368,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4423,8 +4429,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4503,17 +4510,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4562,8 +4567,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionUrlMapRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4965,17 +4971,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5028,8 +5034,9 @@ def test_invalidate_cache_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5214,17 +5221,20 @@ def test_invalidate_cache_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_invalidate_cache" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_invalidate_cache_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_invalidate_cache" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_invalidate_cache" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, + "post_invalidate_cache_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "pre_invalidate_cache" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5275,8 +5285,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionUrlMapsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5345,17 +5356,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5406,8 +5415,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5809,17 +5819,17 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5872,8 +5882,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6014,18 +6025,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6078,8 +6091,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionUrlMapRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6481,17 +6495,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6542,8 +6556,9 @@ def test_validate_rest_bad_request(request_type=compute.ValidateRegionUrlMapRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6918,17 +6933,19 @@ def test_validate_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_validate" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_validate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_validate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_validate" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_validate_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "pre_validate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7211,11 +7228,14 @@ def test_region_url_maps_base_transport(): def test_region_url_maps_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionUrlMapsTransport( @@ -7235,9 +7255,12 @@ def test_region_url_maps_base_transport_with_credentials_file(): def test_region_url_maps_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionUrlMapsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_zones.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_zones.py index ed8ad6033219..082b0e8b2874 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_zones.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_region_zones.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionZonesClient._get_default_mtls_endpoint(None) is None assert ( @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegionZonesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RegionZonesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1482,8 +1486,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1552,17 +1557,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionZonesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionZonesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionZonesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionZonesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionZonesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionZonesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionZonesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1669,11 +1672,14 @@ def test_region_zones_base_transport(): def test_region_zones_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionZonesTransport( @@ -1694,9 +1700,12 @@ def test_region_zones_base_transport_with_credentials_file(): def test_region_zones_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionZonesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_regions.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_regions.py index dd12d316d83a..754979f171a3 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_regions.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_regions.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionsClient._get_default_mtls_endpoint(None) is None assert RegionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -133,6 +134,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RegionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1640,8 +1642,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1718,17 +1721,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RegionsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1777,8 +1778,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1845,17 +1847,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1985,11 +1985,14 @@ def test_regions_base_transport(): def test_regions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.regions.transports.RegionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.regions.transports.RegionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionsTransport( @@ -2010,9 +2013,12 @@ def test_regions_base_transport_with_credentials_file(): def test_regions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.regions.transports.RegionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.regions.transports.RegionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_blocks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_blocks.py index 95ba9e7a5765..6f83348097c6 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_blocks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_blocks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationBlocksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ReservationBlocksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationBlocksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2879,8 +2884,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationBlockRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2945,17 +2951,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3018,8 +3026,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3091,17 +3100,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3152,8 +3164,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationBlocksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3222,17 +3235,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3295,8 +3310,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3491,18 +3507,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, - "post_perform_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3560,8 +3578,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3752,17 +3771,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3820,8 +3842,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3967,18 +3990,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4200,11 +4225,14 @@ def test_reservation_blocks_base_transport(): def test_reservation_blocks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationBlocksTransport( @@ -4224,9 +4252,12 @@ def test_reservation_blocks_base_transport_with_credentials_file(): def test_reservation_blocks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationBlocksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_slots.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_slots.py index fa6dd53c2a5e..ee076666fa28 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_slots.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_slots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationSlotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ReservationSlotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationSlotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2654,8 +2659,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationSlotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2720,17 +2726,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationSlotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2793,8 +2799,9 @@ def test_get_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2989,17 +2996,19 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3054,8 +3063,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationSlotsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3128,17 +3138,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3199,8 +3211,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateReservationSlotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3415,17 +3428,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3599,11 +3614,14 @@ def test_reservation_slots_base_transport(): def test_reservation_slots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSlotsTransport( @@ -3623,9 +3641,12 @@ def test_reservation_slots_base_transport_with_credentials_file(): def test_reservation_slots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSlotsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_sub_blocks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_sub_blocks.py index a2ee89168f0b..6c2ef9236732 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_sub_blocks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservation_sub_blocks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationSubBlocksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ReservationSubBlocksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationSubBlocksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3779,8 +3784,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationSubBlockRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3845,17 +3851,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3918,8 +3926,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3991,18 +4000,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4060,8 +4071,9 @@ def test_get_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4256,17 +4268,20 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_get_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4321,8 +4336,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationSubBlocksRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4395,17 +4411,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4468,8 +4486,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4579,18 +4598,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_perform_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4648,8 +4669,9 @@ def test_report_faulty_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4848,18 +4870,20 @@ def test_report_faulty_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_report_faulty" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_report_faulty_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_report_faulty" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_report_faulty" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_report_faulty_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_report_faulty" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4917,8 +4941,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5109,18 +5134,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5178,8 +5205,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5325,18 +5353,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5600,11 +5630,14 @@ def test_reservation_sub_blocks_base_transport(): def test_reservation_sub_blocks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSubBlocksTransport( @@ -5624,9 +5657,12 @@ def test_reservation_sub_blocks_base_transport_with_credentials_file(): def test_reservation_sub_blocks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSubBlocksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservations.py index 0d1ae8f9d3e1..074bbafc2830 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_reservations.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ReservationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ReservationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4770,8 +4775,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4842,17 +4848,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4905,8 +4913,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5011,17 +5020,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5072,8 +5081,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5172,17 +5182,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ReservationsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5233,8 +5241,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5301,17 +5310,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5362,8 +5373,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5645,17 +5657,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5706,8 +5718,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5776,17 +5789,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ReservationsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5839,8 +5850,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6030,17 +6042,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_perform_maintenance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6091,8 +6106,9 @@ def test_resize_rest_bad_request(request_type=compute.ResizeReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6275,17 +6291,17 @@ def test_resize_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_resize" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_resize") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6338,8 +6354,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6522,17 +6539,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6585,8 +6604,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6727,18 +6747,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6791,8 +6813,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7074,17 +7097,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7409,11 +7432,14 @@ def test_reservations_base_transport(): def test_reservations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationsTransport( @@ -7433,9 +7459,12 @@ def test_reservations_base_transport_with_credentials_file(): def test_reservations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_resource_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_resource_policies.py index a8c4a2d2b926..fc9fe037aac7 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_resource_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_resource_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ResourcePoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ResourcePoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ResourcePoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3915,8 +3920,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3989,17 +3995,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4059,8 +4068,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteResourcePolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4169,17 +4179,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4234,8 +4246,9 @@ def test_get_rest_bad_request(request_type=compute.GetResourcePolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4316,17 +4329,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ResourcePoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4379,8 +4392,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4447,17 +4461,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4508,8 +4525,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertResourcePolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4762,17 +4780,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4823,8 +4843,9 @@ def test_list_rest_bad_request(request_type=compute.ListResourcePoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4895,17 +4916,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4960,8 +4983,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchResourcePolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5218,17 +5242,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5281,8 +5307,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5465,17 +5492,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5528,8 +5558,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5670,18 +5701,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5964,11 +5997,14 @@ def test_resource_policies_base_transport(): def test_resource_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ResourcePoliciesTransport( @@ -5988,9 +6024,12 @@ def test_resource_policies_base_transport_with_credentials_file(): def test_resource_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ResourcePoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollout_plans.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollout_plans.py index 58ca1ad5b6d7..a60e1a7127d2 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollout_plans.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollout_plans.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RolloutPlansClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RolloutPlansClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RolloutPlansClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2457,8 +2462,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRolloutPlanRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2563,17 +2569,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RolloutPlansClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutPlansRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RolloutPlansRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RolloutPlansRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutPlansRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2624,8 +2630,9 @@ def test_get_rest_bad_request(request_type=compute.GetRolloutPlanRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2702,17 +2709,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RolloutPlansClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutPlansRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RolloutPlansRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RolloutPlansRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutPlansRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2761,8 +2766,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRolloutPlanRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2993,17 +2999,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RolloutPlansClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutPlansRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RolloutPlansRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RolloutPlansRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutPlansRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3054,8 +3060,9 @@ def test_list_rest_bad_request(request_type=compute.ListRolloutPlansRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3126,17 +3133,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RolloutPlansClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RolloutPlansRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutPlansRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RolloutPlansRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RolloutPlansRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutPlansRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3312,11 +3317,14 @@ def test_rollout_plans_base_transport(): def test_rollout_plans_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.rollout_plans.transports.RolloutPlansTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.rollout_plans.transports.RolloutPlansTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RolloutPlansTransport( @@ -3336,9 +3344,12 @@ def test_rollout_plans_base_transport_with_credentials_file(): def test_rollout_plans_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.rollout_plans.transports.RolloutPlansTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.rollout_plans.transports.RolloutPlansTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RolloutPlansTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollouts.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollouts.py index 69ec370681fd..a234e4d31663 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollouts.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_rollouts.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RolloutsClient._get_default_mtls_endpoint(None) is None assert RolloutsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RolloutsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RolloutsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -2456,8 +2458,9 @@ def test_cancel_rest_bad_request(request_type=compute.CancelRolloutRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2560,17 +2563,15 @@ def test_cancel_rest_interceptors(null_interceptor): ) client = RolloutsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutsRestInterceptor, "post_cancel" - ) as post, mock.patch.object( - transports.RolloutsRestInterceptor, "post_cancel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutsRestInterceptor, "pre_cancel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RolloutsRestInterceptor, "post_cancel") as post, + mock.patch.object( + transports.RolloutsRestInterceptor, "post_cancel_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutsRestInterceptor, "pre_cancel") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2619,8 +2620,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRolloutRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2723,17 +2725,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RolloutsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RolloutsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RolloutsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RolloutsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2782,8 +2782,9 @@ def test_get_rest_bad_request(request_type=compute.GetRolloutRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2868,17 +2869,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RolloutsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RolloutsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RolloutsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RolloutsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2927,8 +2926,9 @@ def test_list_rest_bad_request(request_type=compute.ListRolloutsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2997,17 +2997,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RolloutsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RolloutsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RolloutsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RolloutsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RolloutsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RolloutsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RolloutsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3181,11 +3179,14 @@ def test_rollouts_base_transport(): def test_rollouts_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.rollouts.transports.RolloutsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.rollouts.transports.RolloutsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RolloutsTransport( @@ -3205,9 +3206,12 @@ def test_rollouts_base_transport_with_credentials_file(): def test_rollouts_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.rollouts.transports.RolloutsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.rollouts.transports.RolloutsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RolloutsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routers.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routers.py index 830c33974dfd..0f932c257126 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routers.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RoutersClient._get_default_mtls_endpoint(None) is None assert RoutersClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -135,6 +136,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RoutersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RoutersClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -8644,8 +8646,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8714,17 +8717,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8777,8 +8782,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8881,17 +8887,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8942,8 +8946,9 @@ def test_delete_named_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9046,17 +9051,19 @@ def test_delete_named_set_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_named_set" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_named_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_delete_named_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_named_set" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_named_set_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_delete_named_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9109,8 +9116,9 @@ def test_delete_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9213,17 +9221,19 @@ def test_delete_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_delete_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_delete_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9274,8 +9284,9 @@ def test_get_rest_bad_request(request_type=compute.GetRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9354,17 +9365,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9413,8 +9422,9 @@ def test_get_named_set_rest_bad_request(request_type=compute.GetNamedSetRouterRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9475,17 +9485,19 @@ def test_get_named_set_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_named_set" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_named_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_named_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_named_set" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_named_set_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_named_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9540,8 +9552,9 @@ def test_get_nat_ip_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9599,17 +9612,19 @@ def test_get_nat_ip_info_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_ip_info" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_ip_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_nat_ip_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_ip_info" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_ip_info_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_nat_ip_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9662,8 +9677,9 @@ def test_get_nat_mapping_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9730,17 +9746,19 @@ def test_get_nat_mapping_info_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_mapping_info" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_mapping_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_nat_mapping_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_mapping_info" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_mapping_info_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_nat_mapping_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9795,8 +9813,9 @@ def test_get_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9854,17 +9873,19 @@ def test_get_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9922,8 +9943,9 @@ def test_get_router_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9984,17 +10006,19 @@ def test_get_router_status_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_router_status" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_router_status_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_router_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_router_status" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_router_status_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_router_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10047,8 +10071,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10356,17 +10381,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10415,8 +10438,9 @@ def test_list_rest_bad_request(request_type=compute.ListRoutersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10483,17 +10507,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10544,8 +10566,9 @@ def test_list_bgp_routes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10616,17 +10639,19 @@ def test_list_bgp_routes_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_bgp_routes" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_bgp_routes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list_bgp_routes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_bgp_routes" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_bgp_routes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_list_bgp_routes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10681,8 +10706,9 @@ def test_list_named_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10753,17 +10779,19 @@ def test_list_named_sets_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_named_sets" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_named_sets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list_named_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_named_sets" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_named_sets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_list_named_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10818,8 +10846,9 @@ def test_list_route_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10890,17 +10919,19 @@ def test_list_route_policies_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_route_policies" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_route_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list_route_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_route_policies" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_route_policies_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_list_route_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10953,8 +10984,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11262,17 +11294,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11323,8 +11353,9 @@ def test_patch_named_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11508,17 +11539,19 @@ def test_patch_named_set_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_named_set" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_named_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_patch_named_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_named_set" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_named_set_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_patch_named_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11571,8 +11604,9 @@ def test_patch_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11766,17 +11800,19 @@ def test_patch_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_patch_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_patch_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11827,8 +11863,9 @@ def test_preview_rest_bad_request(request_type=compute.PreviewRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12091,17 +12128,15 @@ def test_preview_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_preview" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_preview_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_preview" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_preview") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_preview_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_preview") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12154,8 +12189,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12294,17 +12330,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12357,8 +12395,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12666,17 +12705,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_update") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12727,8 +12764,9 @@ def test_update_named_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12912,17 +12950,19 @@ def test_update_named_set_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_named_set" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_named_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_update_named_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_named_set" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_named_set_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_update_named_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12975,8 +13015,9 @@ def test_update_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13170,17 +13211,19 @@ def test_update_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_update_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_update_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13767,11 +13810,14 @@ def test_routers_base_transport(): def test_routers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.routers.transports.RoutersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.routers.transports.RoutersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutersTransport( @@ -13791,9 +13837,12 @@ def test_routers_base_transport_with_credentials_file(): def test_routers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.routers.transports.RoutersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.routers.transports.RoutersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutersTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routes.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routes.py index ba1489ce7787..cbafa91f141a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routes.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_routes.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RoutesClient._get_default_mtls_endpoint(None) is None assert RoutesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RoutesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RoutesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -2625,8 +2627,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2729,17 +2732,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2788,8 +2789,9 @@ def test_get_rest_bad_request(request_type=compute.GetRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2899,17 +2901,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2958,8 +2958,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3166,17 +3167,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3225,8 +3224,9 @@ def test_list_rest_bad_request(request_type=compute.ListRoutesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3293,17 +3293,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3354,8 +3352,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3494,17 +3493,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3703,11 +3704,14 @@ def test_routes_base_transport(): def test_routes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.routes.transports.RoutesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.routes.transports.RoutesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutesTransport( @@ -3727,9 +3731,12 @@ def test_routes_base_transport_with_credentials_file(): def test_routes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.routes.transports.RoutesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.routes.transports.RoutesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_security_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_security_policies.py index d06fe4ba305f..3420e0803880 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_security_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_security_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SecurityPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): SecurityPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SecurityPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5520,8 +5525,9 @@ def test_add_rule_rest_bad_request(request_type=compute.AddRuleSecurityPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5806,17 +5812,19 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_add_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5869,8 +5877,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5943,17 +5952,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6009,8 +6021,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSecurityPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6115,17 +6128,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6176,8 +6191,9 @@ def test_get_rest_bad_request(request_type=compute.GetSecurityPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6268,17 +6284,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SecurityPoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6329,8 +6345,9 @@ def test_get_rule_rest_bad_request(request_type=compute.GetRuleSecurityPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6413,17 +6430,19 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6474,8 +6493,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSecurityPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6869,17 +6889,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6930,8 +6952,9 @@ def test_list_rest_bad_request(request_type=compute.ListSecurityPoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6998,17 +7021,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7061,8 +7086,9 @@ def test_list_preconfigured_expression_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7128,20 +7154,22 @@ def test_list_preconfigured_expression_sets_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets", - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "pre_list_preconfigured_expression_sets", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets", + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "pre_list_preconfigured_expression_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7201,8 +7229,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSecurityPolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7596,17 +7625,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7659,8 +7690,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7945,17 +7977,19 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8008,8 +8042,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8114,17 +8149,19 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_remove_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_remove_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8177,8 +8214,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8362,17 +8400,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8425,8 +8465,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8567,18 +8608,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8947,11 +8990,14 @@ def test_security_policies_base_transport(): def test_security_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecurityPoliciesTransport( @@ -8971,9 +9017,12 @@ def test_security_policies_base_transport_with_credentials_file(): def test_security_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecurityPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_service_attachments.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_service_attachments.py index dd1cf3792d70..490ed83c9582 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_service_attachments.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_service_attachments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServiceAttachmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ServiceAttachmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ServiceAttachmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3945,8 +3950,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4017,18 +4023,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4088,8 +4096,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteServiceAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4198,17 +4207,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4263,8 +4274,9 @@ def test_get_rest_bad_request(request_type=compute.GetServiceAttachmentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4363,17 +4375,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4426,8 +4440,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4494,18 +4509,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4556,8 +4573,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertServiceAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4782,17 +4800,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4843,8 +4863,9 @@ def test_list_rest_bad_request(request_type=compute.ListServiceAttachmentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4913,17 +4934,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4980,8 +5003,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchServiceAttachmentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5210,17 +5234,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5273,8 +5299,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5457,18 +5484,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5521,8 +5550,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5663,18 +5693,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5957,11 +5989,14 @@ def test_service_attachments_base_transport(): def test_service_attachments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceAttachmentsTransport( @@ -5981,9 +6016,12 @@ def test_service_attachments_base_transport_with_credentials_file(): def test_service_attachments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceAttachmentsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_groups.py index ba779a0f747c..1bf92a3e2b98 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnapshotGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( SnapshotGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SnapshotGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3072,8 +3077,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSnapshotGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3178,17 +3184,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3239,8 +3247,9 @@ def test_get_rest_bad_request(request_type=compute.GetSnapshotGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3321,17 +3330,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3384,8 +3391,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3452,17 +3460,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3513,8 +3524,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSnapshotGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3709,17 +3721,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3770,8 +3784,9 @@ def test_list_rest_bad_request(request_type=compute.ListSnapshotGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3844,17 +3859,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3907,8 +3922,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4091,17 +4107,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4154,8 +4173,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4296,18 +4316,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SnapshotGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SnapshotGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4548,11 +4570,14 @@ def test_snapshot_groups_base_transport(): def test_snapshot_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.snapshot_groups.transports.SnapshotGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.snapshot_groups.transports.SnapshotGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotGroupsTransport( @@ -4572,9 +4597,12 @@ def test_snapshot_groups_base_transport_with_credentials_file(): def test_snapshot_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.snapshot_groups.transports.SnapshotGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.snapshot_groups.transports.SnapshotGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_settings_service.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_settings_service.py index e13c56f156ce..224bc85284d7 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_settings_service.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshot_settings_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnapshotSettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): SnapshotSettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SnapshotSettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1899,8 +1904,9 @@ def test_get_rest_bad_request(request_type=compute.GetSnapshotSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1960,17 +1966,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = SnapshotSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2021,8 +2029,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSnapshotSettingRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2204,17 +2213,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SnapshotSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2346,11 +2358,14 @@ def test_snapshot_settings_service_base_transport(): def test_snapshot_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotSettingsServiceTransport( @@ -2370,9 +2385,12 @@ def test_snapshot_settings_service_base_transport_with_credentials_file(): def test_snapshot_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotSettingsServiceTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshots.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshots.py index e55ff00531b5..c23423a3a06a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshots.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnapshotsClient._get_default_mtls_endpoint(None) is None assert SnapshotsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SnapshotsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3712,8 +3716,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3784,17 +3789,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3847,8 +3854,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3951,17 +3959,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4010,8 +4016,9 @@ def test_get_rest_bad_request(request_type=compute.GetSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4151,17 +4158,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4212,8 +4217,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4278,17 +4284,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4339,8 +4347,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4560,17 +4569,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4619,8 +4626,9 @@ def test_list_rest_bad_request(request_type=compute.ListSnapshotsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4687,17 +4695,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4748,8 +4754,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4930,17 +4937,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4991,8 +5000,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5174,17 +5184,17 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5237,8 +5247,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5377,17 +5388,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5670,11 +5684,14 @@ def test_snapshots_base_transport(): def test_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotsTransport( @@ -5694,9 +5711,12 @@ def test_snapshots_base_transport_with_credentials_file(): def test_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_certificates.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_certificates.py index 9367b354b754..3a7d82baeecc 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_certificates.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_certificates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SslCertificatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( SslCertificatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SslCertificatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2972,8 +2977,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3044,17 +3050,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3110,8 +3119,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSslCertificateReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3216,17 +3226,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3277,8 +3289,9 @@ def test_get_rest_bad_request(request_type=compute.GetSslCertificateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3363,17 +3376,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslCertificatesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3424,8 +3437,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSslCertificateReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3627,17 +3641,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3688,8 +3704,9 @@ def test_list_rest_bad_request(request_type=compute.ListSslCertificatesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3758,17 +3775,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslCertificatesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3821,8 +3838,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3963,18 +3981,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4194,11 +4214,14 @@ def test_ssl_certificates_base_transport(): def test_ssl_certificates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslCertificatesTransport( @@ -4218,9 +4241,12 @@ def test_ssl_certificates_base_transport_with_credentials_file(): def test_ssl_certificates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslCertificatesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_policies.py index 9cdb7e630b98..7a83664fc408 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_ssl_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SslPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SslPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SslPoliciesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3545,8 +3549,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3619,17 +3624,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3682,8 +3689,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3788,17 +3796,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3847,8 +3853,9 @@ def test_get_rest_bad_request(request_type=compute.GetSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3933,17 +3940,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3992,8 +3997,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4186,17 +4192,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4245,8 +4249,9 @@ def test_list_rest_bad_request(request_type=compute.ListSslPoliciesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4315,17 +4320,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4376,8 +4379,9 @@ def test_list_available_features_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4440,18 +4444,20 @@ def test_list_available_features_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_list_available_features" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, - "post_list_available_features_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_list_available_features" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_list_available_features" + ) as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, + "post_list_available_features_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "pre_list_available_features" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4507,8 +4513,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4701,17 +4708,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4762,8 +4767,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4904,17 +4910,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5178,11 +5187,14 @@ def test_ssl_policies_base_transport(): def test_ssl_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslPoliciesTransport( @@ -5202,9 +5214,12 @@ def test_ssl_policies_base_transport_with_credentials_file(): def test_ssl_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pool_types.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pool_types.py index 0920616bf4fe..984e49aad6bd 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pool_types.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pool_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert StoragePoolTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): StoragePoolTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + StoragePoolTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2004,8 +2009,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2074,17 +2080,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = StoragePoolTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2144,8 +2153,9 @@ def test_get_rest_bad_request(request_type=compute.GetStoragePoolTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2242,17 +2252,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = StoragePoolTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2303,8 +2313,9 @@ def test_list_rest_bad_request(request_type=compute.ListStoragePoolTypesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2373,17 +2384,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = StoragePoolTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2538,11 +2551,14 @@ def test_storage_pool_types_base_transport(): def test_storage_pool_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolTypesTransport( @@ -2563,9 +2579,12 @@ def test_storage_pool_types_base_transport_with_credentials_file(): def test_storage_pool_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolTypesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pools.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pools.py index ee2db0572678..107728022cbe 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pools.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_storage_pools.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert StoragePoolsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert StoragePoolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + StoragePoolsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4162,8 +4167,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4236,17 +4242,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4299,8 +4307,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4405,17 +4414,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4466,8 +4475,9 @@ def test_get_rest_bad_request(request_type=compute.GetStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4562,17 +4572,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.StoragePoolsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4623,8 +4631,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4691,17 +4700,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4752,8 +4763,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4969,17 +4981,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5030,8 +5042,9 @@ def test_list_rest_bad_request(request_type=compute.ListStoragePoolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5104,17 +5117,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.StoragePoolsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5165,8 +5176,9 @@ def test_list_disks_rest_bad_request(request_type=compute.ListDisksStoragePoolsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5239,17 +5251,19 @@ def test_list_disks_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list_disks" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list_disks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_list_disks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_list_disks" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_list_disks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_list_disks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5304,8 +5318,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5488,17 +5503,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5551,8 +5568,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5693,18 +5711,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5757,8 +5777,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5974,17 +5995,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6286,11 +6307,14 @@ def test_storage_pools_base_transport(): def test_storage_pools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolsTransport( @@ -6310,9 +6334,12 @@ def test_storage_pools_base_transport_with_credentials_file(): def test_storage_pools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_subnetworks.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_subnetworks.py index 6fb8bcdedb5b..bfb2a9987b7c 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_subnetworks.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_subnetworks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SubnetworksClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SubnetworksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SubnetworksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -5028,8 +5032,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5100,17 +5105,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5163,8 +5170,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5269,17 +5277,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5332,8 +5338,9 @@ def test_expand_ip_cidr_range_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5523,17 +5530,20 @@ def test_expand_ip_cidr_range_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_expand_ip_cidr_range" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_expand_ip_cidr_range_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_expand_ip_cidr_range" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_expand_ip_cidr_range" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, + "post_expand_ip_cidr_range_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_expand_ip_cidr_range" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5584,8 +5594,9 @@ def test_get_rest_bad_request(request_type=compute.GetSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5712,17 +5723,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5773,8 +5782,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5841,17 +5851,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5902,8 +5914,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6143,17 +6156,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6204,8 +6215,9 @@ def test_list_rest_bad_request(request_type=compute.ListSubnetworksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6274,17 +6286,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6335,8 +6345,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6407,17 +6418,19 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list_usable_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_list_usable_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6473,8 +6486,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6714,17 +6728,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6775,8 +6787,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6959,17 +6972,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7022,8 +7037,9 @@ def test_set_private_ip_google_access_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7213,18 +7229,20 @@ def test_set_private_ip_google_access_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_set_private_ip_google_access" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, - "post_set_private_ip_google_access_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_set_private_ip_google_access" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_set_private_ip_google_access" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, + "post_set_private_ip_google_access_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_set_private_ip_google_access" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7277,8 +7295,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7419,17 +7438,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7779,11 +7801,14 @@ def test_subnetworks_base_transport(): def test_subnetworks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubnetworksTransport( @@ -7803,9 +7828,12 @@ def test_subnetworks_base_transport_with_credentials_file(): def test_subnetworks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubnetworksTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_grpc_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_grpc_proxies.py index ffbab66820d2..de9d00c8133a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_grpc_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_grpc_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetGrpcProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetGrpcProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetGrpcProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3116,8 +3121,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetGrpcProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3222,17 +3228,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3283,8 +3291,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetGrpcProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3365,17 +3374,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3426,8 +3437,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetGrpcProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3617,17 +3629,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3678,8 +3692,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetGrpcProxiesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3748,17 +3763,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3811,8 +3828,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchTargetGrpcProxyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4002,17 +4020,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4065,8 +4085,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4207,18 +4228,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4438,11 +4461,14 @@ def test_target_grpc_proxies_base_transport(): def test_target_grpc_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetGrpcProxiesTransport( @@ -4462,9 +4488,12 @@ def test_target_grpc_proxies_base_transport_with_credentials_file(): def test_target_grpc_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetGrpcProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_http_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_http_proxies.py index a922a06ad3c4..40185bf1cbfe 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_http_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_http_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetHttpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetHttpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetHttpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3800,8 +3805,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3872,18 +3878,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3939,8 +3947,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetHttpProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4045,17 +4054,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4106,8 +4117,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetHttpProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4192,17 +4204,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4253,8 +4267,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetHttpProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4446,17 +4461,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4507,8 +4524,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetHttpProxiesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4577,17 +4595,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4640,8 +4660,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchTargetHttpProxyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4833,17 +4854,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4896,8 +4919,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5076,17 +5100,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_set_url_map_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5139,8 +5166,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5281,18 +5309,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5554,11 +5584,14 @@ def test_target_http_proxies_base_transport(): def test_target_http_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpProxiesTransport( @@ -5578,9 +5611,12 @@ def test_target_http_proxies_base_transport_with_credentials_file(): def test_target_http_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_https_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_https_proxies.py index dba49681c75f..cf7e69768859 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_https_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_https_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetHttpsProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetHttpsProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetHttpsProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5476,8 +5481,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5548,18 +5554,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5615,8 +5623,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetHttpsProxyRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5721,17 +5730,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5782,8 +5793,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetHttpsProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5886,17 +5898,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5947,8 +5961,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetHttpsProxyRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6149,17 +6164,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6210,8 +6227,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetHttpsProxiesReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6280,17 +6298,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6343,8 +6363,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchTargetHttpsProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6545,17 +6566,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6608,8 +6631,9 @@ def test_set_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6799,18 +6823,20 @@ def test_set_certificate_map_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_certificate_map" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_certificate_map" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6863,8 +6889,9 @@ def test_set_quic_override_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7054,18 +7081,20 @@ def test_set_quic_override_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_quic_override" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_quic_override_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_quic_override" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_quic_override" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_quic_override_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_quic_override" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7118,8 +7147,9 @@ def test_set_ssl_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7309,18 +7339,20 @@ def test_set_ssl_certificates_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_certificates" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_ssl_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_certificates" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_ssl_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_certificates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7373,8 +7405,9 @@ def test_set_ssl_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7555,18 +7588,20 @@ def test_set_ssl_policy_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_policy" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_ssl_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_policy" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_ssl_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7619,8 +7654,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7799,17 +7835,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_url_map_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7862,8 +7901,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8004,18 +8044,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8367,11 +8409,14 @@ def test_target_https_proxies_base_transport(): def test_target_https_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpsProxiesTransport( @@ -8391,9 +8436,12 @@ def test_target_https_proxies_base_transport_with_credentials_file(): def test_target_https_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpsProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_instances.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_instances.py index ed55ee7df528..d0ef2f73f4ff 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_instances.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_instances.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetInstancesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( TargetInstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetInstancesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3483,8 +3488,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3555,17 +3561,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3625,8 +3634,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetInstanceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3735,17 +3745,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3800,8 +3812,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3888,17 +3901,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetInstancesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3949,8 +3962,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetInstanceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4139,17 +4153,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4200,8 +4216,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetInstancesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4270,17 +4287,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetInstancesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4337,8 +4354,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4525,18 +4543,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, - "post_set_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4589,8 +4609,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4731,18 +4752,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4985,11 +5008,14 @@ def test_target_instances_base_transport(): def test_target_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetInstancesTransport( @@ -5009,9 +5035,12 @@ def test_target_instances_base_transport_with_credentials_file(): def test_target_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetInstancesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_pools.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_pools.py index e0043387f549..528b2b06f8f3 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_pools.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_pools.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetPoolsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TargetPoolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TargetPoolsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -5859,8 +5863,9 @@ def test_add_health_check_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6050,17 +6055,19 @@ def test_add_health_check_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_health_check" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_health_check_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_add_health_check" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_health_check" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_health_check_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_add_health_check" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6113,8 +6120,9 @@ def test_add_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6304,17 +6312,19 @@ def test_add_instance_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_instance" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_add_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_instance" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_add_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6367,8 +6377,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6439,17 +6450,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6502,8 +6515,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetPoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6608,17 +6622,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6669,8 +6681,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetPoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6757,17 +6770,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6816,8 +6827,9 @@ def test_get_health_rest_bad_request(request_type=compute.GetHealthTargetPoolReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6954,17 +6966,19 @@ def test_get_health_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get_health" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get_health_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_get_health" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_get_health" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_get_health_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_get_health" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7017,8 +7031,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetPoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7207,17 +7222,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7268,8 +7281,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetPoolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7338,17 +7352,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7399,8 +7411,9 @@ def test_remove_health_check_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7590,17 +7603,20 @@ def test_remove_health_check_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_health_check" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_health_check_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_remove_health_check" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_remove_health_check" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, + "post_remove_health_check_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_remove_health_check" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7653,8 +7669,9 @@ def test_remove_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7844,17 +7861,19 @@ def test_remove_instance_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_instance" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_remove_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_remove_instance" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_remove_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_remove_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7905,8 +7924,9 @@ def test_set_backup_rest_bad_request(request_type=compute.SetBackupTargetPoolReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8085,17 +8105,19 @@ def test_set_backup_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_backup" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_set_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_set_backup" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_set_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_set_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8148,8 +8170,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8332,17 +8355,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_security_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8395,8 +8421,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8537,17 +8564,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8918,11 +8948,14 @@ def test_target_pools_base_transport(): def test_target_pools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetPoolsTransport( @@ -8942,9 +8975,12 @@ def test_target_pools_base_transport_with_credentials_file(): def test_target_pools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetPoolsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_ssl_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_ssl_proxies.py index d29e79a1a615..d29a1c3a48f5 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_ssl_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_ssl_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetSslProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetSslProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetSslProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4786,8 +4791,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetSslProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4892,17 +4898,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4953,8 +4961,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetSslProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5037,17 +5046,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetSslProxiesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5098,8 +5107,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetSslProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5290,17 +5300,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5351,8 +5363,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetSslProxiesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5421,17 +5434,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5484,8 +5499,9 @@ def test_set_backend_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5675,18 +5691,20 @@ def test_set_backend_service_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_backend_service" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_backend_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_backend_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_backend_service" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_backend_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_backend_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5739,8 +5757,9 @@ def test_set_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5930,18 +5949,20 @@ def test_set_certificate_map_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_certificate_map" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_certificate_map" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5994,8 +6015,9 @@ def test_set_proxy_header_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6185,18 +6207,20 @@ def test_set_proxy_header_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_proxy_header" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_proxy_header_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_proxy_header" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_proxy_header" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_proxy_header_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_proxy_header" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6249,8 +6273,9 @@ def test_set_ssl_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6440,18 +6465,20 @@ def test_set_ssl_certificates_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_ssl_certificates" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_ssl_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_ssl_certificates" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_ssl_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_certificates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6504,8 +6531,9 @@ def test_set_ssl_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6686,17 +6714,20 @@ def test_set_ssl_policy_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_ssl_policy" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_ssl_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_ssl_policy" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_ssl_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6749,8 +6780,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6891,18 +6923,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7212,11 +7246,14 @@ def test_target_ssl_proxies_base_transport(): def test_target_ssl_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetSslProxiesTransport( @@ -7236,9 +7273,12 @@ def test_target_ssl_proxies_base_transport_with_credentials_file(): def test_target_ssl_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetSslProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_tcp_proxies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_tcp_proxies.py index 70c8759b6133..6c158781ed8d 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_tcp_proxies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_tcp_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetTcpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetTcpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetTcpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3814,8 +3819,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3886,17 +3892,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3952,8 +3961,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetTcpProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4058,17 +4068,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4119,8 +4131,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetTcpProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4203,17 +4216,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetTcpProxiesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4264,8 +4277,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetTcpProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4456,17 +4470,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4517,8 +4533,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetTcpProxiesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4587,17 +4604,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4650,8 +4669,9 @@ def test_set_backend_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4841,18 +4861,20 @@ def test_set_backend_service_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_set_backend_service" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, - "post_set_backend_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_set_backend_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_set_backend_service" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_set_backend_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_set_backend_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4905,8 +4927,9 @@ def test_set_proxy_header_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5096,18 +5119,20 @@ def test_set_proxy_header_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_set_proxy_header" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, - "post_set_proxy_header_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_set_proxy_header" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_set_proxy_header" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_set_proxy_header_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_set_proxy_header" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5160,8 +5185,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5302,18 +5328,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5577,11 +5605,14 @@ def test_target_tcp_proxies_base_transport(): def test_target_tcp_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetTcpProxiesTransport( @@ -5601,9 +5632,12 @@ def test_target_tcp_proxies_base_transport_with_credentials_file(): def test_target_tcp_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetTcpProxiesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_vpn_gateways.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_vpn_gateways.py index 738754ac7386..e437c3347846 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_vpn_gateways.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_target_vpn_gateways.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetVpnGatewaysClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetVpnGatewaysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetVpnGatewaysClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3493,8 +3498,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3565,18 +3571,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3636,8 +3644,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetVpnGatewayRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3746,17 +3755,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3811,8 +3822,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3901,17 +3913,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3962,8 +3976,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetVpnGatewayRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4157,17 +4172,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4218,8 +4235,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetVpnGatewaysRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4288,17 +4306,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4353,8 +4373,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4538,17 +4559,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4601,8 +4624,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4743,18 +4767,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4995,11 +5021,14 @@ def test_target_vpn_gateways_base_transport(): def test_target_vpn_gateways_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetVpnGatewaysTransport( @@ -5019,9 +5048,12 @@ def test_target_vpn_gateways_base_transport_with_credentials_file(): def test_target_vpn_gateways_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetVpnGatewaysTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_url_maps.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_url_maps.py index bf11e3b47ddd..29c62e5ae48a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_url_maps.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_url_maps.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UrlMapsClient._get_default_mtls_endpoint(None) is None assert UrlMapsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -135,6 +136,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert UrlMapsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert UrlMapsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -4340,8 +4342,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4410,17 +4413,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UrlMapsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4473,8 +4478,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4577,17 +4583,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4636,8 +4640,9 @@ def test_get_rest_bad_request(request_type=compute.GetUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4714,17 +4719,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4773,8 +4776,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5174,17 +5178,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5235,8 +5237,9 @@ def test_invalidate_cache_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5419,17 +5422,19 @@ def test_invalidate_cache_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_invalidate_cache" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_invalidate_cache_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_invalidate_cache" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_invalidate_cache" + ) as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_invalidate_cache_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UrlMapsRestInterceptor, "pre_invalidate_cache" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5480,8 +5485,9 @@ def test_list_rest_bad_request(request_type=compute.ListUrlMapsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5548,17 +5554,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5607,8 +5611,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6008,17 +6013,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6069,8 +6072,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6209,17 +6213,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UrlMapsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6272,8 +6278,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6673,17 +6680,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_update") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6732,8 +6737,9 @@ def test_validate_rest_bad_request(request_type=compute.ValidateUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7105,17 +7111,15 @@ def test_validate_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_validate" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_validate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_validate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_validate") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_validate_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_validate") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7417,11 +7421,14 @@ def test_url_maps_base_transport(): def test_url_maps_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UrlMapsTransport( @@ -7441,9 +7448,12 @@ def test_url_maps_base_transport_with_credentials_file(): def test_url_maps_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UrlMapsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_gateways.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_gateways.py index 796955eb6054..e3749f69ea5a 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_gateways.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_gateways.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VpnGatewaysClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VpnGatewaysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + VpnGatewaysClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3641,8 +3645,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3713,17 +3718,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3776,8 +3783,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3882,17 +3890,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3943,8 +3949,9 @@ def test_get_rest_bad_request(request_type=compute.GetVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4027,17 +4034,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_get") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4086,8 +4091,9 @@ def test_get_status_rest_bad_request(request_type=compute.GetStatusVpnGatewayReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4147,17 +4153,19 @@ def test_get_status_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get_status" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get_status_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_get_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_get_status" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_get_status_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_get_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4213,8 +4221,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4411,17 +4420,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4472,8 +4479,9 @@ def test_list_rest_bad_request(request_type=compute.ListVpnGatewaysRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4542,17 +4550,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_list") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4601,8 +4607,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsVpnGatewayReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4786,17 +4793,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4849,8 +4858,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4991,17 +5001,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5263,11 +5276,14 @@ def test_vpn_gateways_base_transport(): def test_vpn_gateways_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnGatewaysTransport( @@ -5287,9 +5303,12 @@ def test_vpn_gateways_base_transport_with_credentials_file(): def test_vpn_gateways_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnGatewaysTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_tunnels.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_tunnels.py index 8784480702f7..8189d386774f 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_tunnels.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_vpn_tunnels.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VpnTunnelsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VpnTunnelsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + VpnTunnelsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3419,8 +3423,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3491,17 +3496,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3554,8 +3561,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteVpnTunnelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3660,17 +3668,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3719,8 +3725,9 @@ def test_get_rest_bad_request(request_type=compute.GetVpnTunnelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3829,17 +3836,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3888,8 +3893,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertVpnTunnelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4108,17 +4114,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4167,8 +4171,9 @@ def test_list_rest_bad_request(request_type=compute.ListVpnTunnelsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4237,17 +4242,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4296,8 +4299,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsVpnTunnelRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4481,17 +4485,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4544,8 +4550,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4686,17 +4693,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4937,11 +4947,14 @@ def test_vpn_tunnels_base_transport(): def test_vpn_tunnels_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnTunnelsTransport( @@ -4961,9 +4974,12 @@ def test_vpn_tunnels_base_transport_with_credentials_file(): def test_vpn_tunnels_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnTunnelsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_wire_groups.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_wire_groups.py index 52746f0223ae..31da818cdf2e 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_wire_groups.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_wire_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WireGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert WireGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + WireGroupsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -2965,8 +2969,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3075,17 +3080,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3138,8 +3141,9 @@ def test_get_rest_bad_request(request_type=compute.GetWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3220,17 +3224,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3279,8 +3281,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3478,17 +3481,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3537,8 +3538,9 @@ def test_list_rest_bad_request(request_type=compute.ListWireGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3611,17 +3613,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3674,8 +3674,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3877,17 +3878,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4080,11 +4079,14 @@ def test_wire_groups_base_transport(): def test_wire_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WireGroupsTransport( @@ -4104,9 +4106,12 @@ def test_wire_groups_base_transport_with_credentials_file(): def test_wire_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WireGroupsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_operations.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_operations.py index a5839928489d..c8a98408d282 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_operations.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ZoneOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( ZoneOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ZoneOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2106,8 +2111,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteZoneOperationRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2167,17 +2173,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2233,8 +2241,9 @@ def test_get_rest_bad_request(request_type=compute.GetZoneOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2339,17 +2348,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2400,8 +2407,9 @@ def test_list_rest_bad_request(request_type=compute.ListZoneOperationsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2470,17 +2478,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2531,8 +2539,9 @@ def test_wait_rest_bad_request(request_type=compute.WaitZoneOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2637,17 +2646,17 @@ def test_wait_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_wait" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_wait_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_wait" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_wait" + ) as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_wait_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "pre_wait") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2821,11 +2830,14 @@ def test_zone_operations_base_transport(): def test_zone_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZoneOperationsTransport( @@ -2845,9 +2857,12 @@ def test_zone_operations_base_transport_with_credentials_file(): def test_zone_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZoneOperationsTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_vm_extension_policies.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_vm_extension_policies.py index 8fface38a827..db0db4428fbd 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_vm_extension_policies.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zone_vm_extension_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ZoneVmExtensionPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ZoneVmExtensionPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ZoneVmExtensionPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3026,8 +3031,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3136,17 +3142,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ZoneVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3201,8 +3210,9 @@ def test_get_rest_bad_request(request_type=compute.GetZoneVmExtensionPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3291,17 +3301,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ZoneVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3354,8 +3366,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3549,17 +3562,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ZoneVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3610,8 +3626,9 @@ def test_list_rest_bad_request(request_type=compute.ListZoneVmExtensionPoliciesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3684,17 +3701,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ZoneVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3753,8 +3772,9 @@ def test_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3952,17 +3972,20 @@ def test_update_rest_interceptors(null_interceptor): ) client = ZoneVmExtensionPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, + "post_update_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ZoneVmExtensionPoliciesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4157,11 +4180,14 @@ def test_zone_vm_extension_policies_base_transport(): def test_zone_vm_extension_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.zone_vm_extension_policies.transports.ZoneVmExtensionPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.zone_vm_extension_policies.transports.ZoneVmExtensionPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZoneVmExtensionPoliciesTransport( @@ -4181,9 +4207,12 @@ def test_zone_vm_extension_policies_base_transport_with_credentials_file(): def test_zone_vm_extension_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.zone_vm_extension_policies.transports.ZoneVmExtensionPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.zone_vm_extension_policies.transports.ZoneVmExtensionPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZoneVmExtensionPoliciesTransport() diff --git a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zones.py b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zones.py index d77e95b52019..5dc2dd2df2e3 100644 --- a/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zones.py +++ b/packages/google-cloud-compute-v1beta/tests/unit/gapic/compute_v1beta/test_zones.py @@ -114,6 +114,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ZonesClient._get_default_mtls_endpoint(None) is None assert ZonesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ZonesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ZonesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1629,8 +1631,9 @@ def test_get_rest_bad_request(request_type=compute.GetZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1709,17 +1712,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ZonesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZonesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ZonesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZonesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ZonesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ZonesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZonesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1768,8 +1769,9 @@ def test_list_rest_bad_request(request_type=compute.ListZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1836,17 +1838,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = ZonesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZonesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ZonesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZonesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ZonesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.ZonesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZonesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1976,11 +1976,14 @@ def test_zones_base_transport(): def test_zones_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1beta.services.zones.transports.ZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1beta.services.zones.transports.ZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZonesTransport( @@ -2001,9 +2004,12 @@ def test_zones_base_transport_with_credentials_file(): def test_zones_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1beta.services.zones.transports.ZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1beta.services.zones.transports.ZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZonesTransport() diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py index 2693fa6aadd5..1ae490ad200c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/client.py @@ -108,7 +108,7 @@ class AcceleratorTypesClient(metaclass=AcceleratorTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = AcceleratorTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/README.rst index 492c43918897..805d1f1f9012 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AcceleratorTypesTransport` is the ABC for all transports. -- public child `AcceleratorTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AcceleratorTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAcceleratorTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AcceleratorTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AcceleratorTypesTransport`` is the ABC for all transports. + +- public child ``AcceleratorTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AcceleratorTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAcceleratorTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AcceleratorTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py index 5a237533c71f..bae544b8185f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/rest.py index d4116ddd5c35..d1d29012bd90 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/rest.py @@ -320,6 +320,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AcceleratorTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py index 2a3434ae32ba..750d19a53540 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/client.py @@ -108,7 +108,7 @@ class AddressesClient(metaclass=AddressesClientMeta): """The Addresses API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = AddressesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/README.rst index 0868b903ae5f..2d0323b5454b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AddressesTransport` is the ABC for all transports. -- public child `AddressesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AddressesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAddressesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AddressesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AddressesTransport`` is the ABC for all transports. + +- public child ``AddressesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AddressesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAddressesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AddressesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/base.py index 656b6a975d70..b0b859ac46b6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/rest.py index 7fcc08029e68..e65fca8c0753 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/rest.py @@ -578,6 +578,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AddressesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py index 0477f4fba81c..857a75fb77a1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/client.py @@ -104,7 +104,7 @@ class AdviceClient(metaclass=AdviceClientMeta): """The Advice API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -603,7 +607,7 @@ def __init__( self._universe_domain = AdviceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/README.rst index 6cad73a5252f..3f748e33c131 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AdviceTransport` is the ABC for all transports. -- public child `AdviceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AdviceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAdviceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AdviceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AdviceTransport`` is the ABC for all transports. + +- public child ``AdviceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AdviceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAdviceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AdviceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/base.py index 305db5503fd5..e2a060460bdc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/rest.py index a4259b154351..c453a31808c2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/advice/transports/rest.py @@ -207,6 +207,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AdviceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py index dd8ddfef7bc1..91f24a726242 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/client.py @@ -108,7 +108,7 @@ class AutoscalersClient(metaclass=AutoscalersClientMeta): """The Autoscalers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = AutoscalersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/README.rst index efb6ecaee833..b10ff5a35b68 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutoscalersTransport` is the ABC for all transports. -- public child `AutoscalersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutoscalersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutoscalersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutoscalersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutoscalersTransport`` is the ABC for all transports. + +- public child ``AutoscalersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutoscalersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutoscalersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutoscalersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/base.py index cebae1db8825..a666c75d4caf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/rest.py index 9f9fd8d01124..d0d3c22e4154 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/rest.py @@ -585,6 +585,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutoscalersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py index 826f2d618f20..c8181650930d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/client.py @@ -108,7 +108,7 @@ class BackendBucketsClient(metaclass=BackendBucketsClientMeta): """The BackendBuckets API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = BackendBucketsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/README.rst index 30026928229f..24a46fc1cf4c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackendBucketsTransport` is the ABC for all transports. -- public child `BackendBucketsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackendBucketsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackendBucketsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackendBucketsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackendBucketsTransport`` is the ABC for all transports. + +- public child ``BackendBucketsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackendBucketsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackendBucketsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackendBucketsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/base.py index e70ad86cd15d..8193d3e43c5e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/rest.py index a831f4a9445a..b29b4f128c92 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_buckets/transports/rest.py @@ -813,6 +813,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackendBucketsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py index 02a162df0a42..be4f2a8ffcad 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/client.py @@ -108,7 +108,7 @@ class BackendServicesClient(metaclass=BackendServicesClientMeta): """The BackendServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = BackendServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/README.rst index ecdf9985b784..9cbb59449d41 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackendServicesTransport` is the ABC for all transports. -- public child `BackendServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackendServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackendServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackendServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackendServicesTransport`` is the ABC for all transports. + +- public child ``BackendServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackendServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackendServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackendServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/base.py index f72b1ae45be9..70b67fcdc5be 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/rest.py index 60d2c63f2df6..245e6a537207 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/backend_services/transports/rest.py @@ -1106,6 +1106,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackendServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py index 73d44749454b..3c48ef610c44 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/client.py @@ -108,7 +108,7 @@ class CrossSiteNetworksClient(metaclass=CrossSiteNetworksClientMeta): """The CrossSiteNetworks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = CrossSiteNetworksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/README.rst index 361c1232c685..2552c9613c60 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CrossSiteNetworksTransport` is the ABC for all transports. -- public child `CrossSiteNetworksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CrossSiteNetworksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCrossSiteNetworksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CrossSiteNetworksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CrossSiteNetworksTransport`` is the ABC for all transports. + +- public child ``CrossSiteNetworksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CrossSiteNetworksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCrossSiteNetworksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CrossSiteNetworksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/base.py index 301c6ba7c1a9..5f5bd7f51b60 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/rest.py index 90a050711d82..957243b19574 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/cross_site_networks/transports/rest.py @@ -421,6 +421,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CrossSiteNetworksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py index d3133253acda..c8d843215e11 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/client.py @@ -105,7 +105,7 @@ class DiskTypesClient(metaclass=DiskTypesClientMeta): """The DiskTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = DiskTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/README.rst index c9e4d5b0d18a..172851742cb6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DiskTypesTransport` is the ABC for all transports. -- public child `DiskTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DiskTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDiskTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DiskTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DiskTypesTransport`` is the ABC for all transports. + +- public child ``DiskTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DiskTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDiskTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DiskTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/base.py index 7929a00d5c6c..6bed1cdbd5bd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/rest.py index 84d5809031a1..c1f6b4274a6b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disk_types/transports/rest.py @@ -309,6 +309,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DiskTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py index 320fd813b12d..fc613c924358 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/client.py @@ -108,7 +108,7 @@ class DisksClient(metaclass=DisksClientMeta): """The Disks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = DisksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/README.rst index ee30b21ca95a..32f77cc14043 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DisksTransport` is the ABC for all transports. -- public child `DisksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DisksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDisksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DisksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DisksTransport`` is the ABC for all transports. + +- public child ``DisksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DisksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDisksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DisksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/base.py index 80ee7c27b3c7..14c494099f2b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/rest.py index 016b26cbee57..f303b6be791b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/disks/transports/rest.py @@ -1176,6 +1176,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DisksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py index 35bdbed63343..aa8209a1b3d0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/client.py @@ -108,7 +108,7 @@ class ExternalVpnGatewaysClient(metaclass=ExternalVpnGatewaysClientMeta): """The ExternalVpnGateways API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ExternalVpnGatewaysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/README.rst index cd3c299d7402..320610bc2897 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ExternalVpnGatewaysTransport` is the ABC for all transports. -- public child `ExternalVpnGatewaysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ExternalVpnGatewaysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseExternalVpnGatewaysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ExternalVpnGatewaysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ExternalVpnGatewaysTransport`` is the ABC for all transports. + +- public child ``ExternalVpnGatewaysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ExternalVpnGatewaysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseExternalVpnGatewaysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ExternalVpnGatewaysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py index c7e32fb5c0b6..7aab6df407e1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py index ad4b36265c9d..bdba7700555c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py @@ -483,6 +483,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ExternalVpnGatewaysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py index 9092004305fa..6773650d9a1b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/client.py @@ -108,7 +108,7 @@ class FirewallPoliciesClient(metaclass=FirewallPoliciesClientMeta): """The FirewallPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = FirewallPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/README.rst index da518d84e3bc..9d5ff4de4201 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirewallPoliciesTransport` is the ABC for all transports. -- public child `FirewallPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirewallPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirewallPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirewallPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirewallPoliciesTransport`` is the ABC for all transports. + +- public child ``FirewallPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirewallPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirewallPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirewallPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/base.py index 22dd71a5f0c3..097ee1fa592c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/rest.py index e506049ed9b5..516993ccdcad 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewall_policies/transports/rest.py @@ -1145,6 +1145,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirewallPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py index 13f8ccaa05b8..51d9b8aa2975 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/client.py @@ -108,7 +108,7 @@ class FirewallsClient(metaclass=FirewallsClientMeta): """The Firewalls API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = FirewallsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/README.rst index 530e5fd90230..96ec573ff8db 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirewallsTransport` is the ABC for all transports. -- public child `FirewallsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirewallsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirewallsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirewallsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirewallsTransport`` is the ABC for all transports. + +- public child ``FirewallsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirewallsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirewallsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirewallsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/base.py index fa325f22000b..54e22a7a8725 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/rest.py index 6a5b5842a9d3..6a7b8f4f6d38 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/firewalls/transports/rest.py @@ -520,6 +520,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirewallsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py index ab63696b0966..0a4708688a10 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/client.py @@ -108,7 +108,7 @@ class ForwardingRulesClient(metaclass=ForwardingRulesClientMeta): """The ForwardingRules API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ForwardingRulesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/README.rst index 2031ab456efd..a0f5ffb4d25e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ForwardingRulesTransport` is the ABC for all transports. -- public child `ForwardingRulesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ForwardingRulesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseForwardingRulesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ForwardingRulesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ForwardingRulesTransport`` is the ABC for all transports. + +- public child ``ForwardingRulesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ForwardingRulesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseForwardingRulesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ForwardingRulesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/base.py index 429cedec9c76..1e70e09d3821 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py index b48d42da923f..72a2301f1bd8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py @@ -588,6 +588,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ForwardingRulesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py index 5fb00c1df7d2..ed184c0bd0e4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/client.py @@ -108,7 +108,7 @@ class FutureReservationsClient(metaclass=FutureReservationsClientMeta): """The FutureReservations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = FutureReservationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/README.rst index 1ad7099aa56e..f24ce6af2984 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FutureReservationsTransport` is the ABC for all transports. -- public child `FutureReservationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FutureReservationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFutureReservationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FutureReservationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FutureReservationsTransport`` is the ABC for all transports. + +- public child ``FutureReservationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FutureReservationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFutureReservationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FutureReservationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/base.py index a8ad7bf155d5..ae3b1edc7d3c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/rest.py index 8e2368460985..877576cd9416 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/future_reservations/transports/rest.py @@ -539,6 +539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FutureReservationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py index 51926816216d..2ce055e3e0e9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/client.py @@ -108,7 +108,7 @@ class GlobalAddressesClient(metaclass=GlobalAddressesClientMeta): """The GlobalAddresses API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = GlobalAddressesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/README.rst index 7b9ed8452847..fde4fceeffc0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalAddressesTransport` is the ABC for all transports. -- public child `GlobalAddressesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalAddressesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalAddressesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalAddressesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalAddressesTransport`` is the ABC for all transports. + +- public child ``GlobalAddressesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalAddressesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalAddressesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalAddressesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/base.py index eaeb3f037ab4..2487775790a3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/rest.py index 7691473488e4..1a48432cd029 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_addresses/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalAddressesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py index 91eeaa3c5b2a..2f0715706747 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/client.py @@ -108,7 +108,7 @@ class GlobalForwardingRulesClient(metaclass=GlobalForwardingRulesClientMeta): """The GlobalForwardingRules API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = GlobalForwardingRulesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/README.rst index 41f595a75512..932a36928fd4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalForwardingRulesTransport` is the ABC for all transports. -- public child `GlobalForwardingRulesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalForwardingRulesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalForwardingRulesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalForwardingRulesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalForwardingRulesTransport`` is the ABC for all transports. + +- public child ``GlobalForwardingRulesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalForwardingRulesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalForwardingRulesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalForwardingRulesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py index 5765e75e8dd4..80ffab97a754 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py index f735e60db1bc..86ae94cfd540 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py @@ -535,6 +535,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalForwardingRulesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py index 9644b3b5e056..f7064a88fad7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/client.py @@ -110,7 +110,7 @@ class GlobalNetworkEndpointGroupsClient( """The GlobalNetworkEndpointGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = GlobalNetworkEndpointGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/README.rst index 1ef884d89ba4..40166d97f8f0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalNetworkEndpointGroupsTransport` is the ABC for all transports. -- public child `GlobalNetworkEndpointGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalNetworkEndpointGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalNetworkEndpointGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalNetworkEndpointGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalNetworkEndpointGroupsTransport`` is the ABC for all transports. + +- public child ``GlobalNetworkEndpointGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalNetworkEndpointGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalNetworkEndpointGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalNetworkEndpointGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py index 06dc088fa11a..a209cec92a3f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py index e13c1c347bec..575412b327f4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalNetworkEndpointGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py index 7484a8c4c8a8..45406a5f37ad 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/client.py @@ -105,7 +105,7 @@ class GlobalOperationsClient(metaclass=GlobalOperationsClientMeta): """The GlobalOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = GlobalOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/README.rst index 53a0a6ba4b78..709065f32a00 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalOperationsTransport` is the ABC for all transports. -- public child `GlobalOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalOperationsTransport`` is the ABC for all transports. + +- public child ``GlobalOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/base.py index c2b6ec289041..bb35d62c27fa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/rest.py index 46c3317b179c..e608b754d394 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_operations/transports/rest.py @@ -428,6 +428,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py index 56a6462bd1e8..2be6dcfd0184 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/client.py @@ -107,7 +107,7 @@ class GlobalOrganizationOperationsClient( """The GlobalOrganizationOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -414,7 +418,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -513,7 +517,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -618,7 +622,7 @@ def __init__( self._universe_domain = GlobalOrganizationOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/README.rst index be5a7191aa48..4a1267b5e4bf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalOrganizationOperationsTransport` is the ABC for all transports. -- public child `GlobalOrganizationOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalOrganizationOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalOrganizationOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalOrganizationOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalOrganizationOperationsTransport`` is the ABC for all transports. + +- public child ``GlobalOrganizationOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalOrganizationOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalOrganizationOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalOrganizationOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/base.py index f60e158bf125..8feb0077af12 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py index 42bfcad1a76c..01afe382e489 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py @@ -321,6 +321,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalOrganizationOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py index 2211d3abf809..73a08ffc9442 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/client.py @@ -110,7 +110,7 @@ class GlobalPublicDelegatedPrefixesClient( """The GlobalPublicDelegatedPrefixes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/README.rst index b7dd1788312e..0531b7ff843c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GlobalPublicDelegatedPrefixesTransport` is the ABC for all transports. -- public child `GlobalPublicDelegatedPrefixesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GlobalPublicDelegatedPrefixesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGlobalPublicDelegatedPrefixesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GlobalPublicDelegatedPrefixesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GlobalPublicDelegatedPrefixesTransport`` is the ABC for all transports. + +- public child ``GlobalPublicDelegatedPrefixesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GlobalPublicDelegatedPrefixesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGlobalPublicDelegatedPrefixesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GlobalPublicDelegatedPrefixesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py index c1f827e77b9a..2583c6231aeb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py index 789dbb33205a..815c760daf2a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py @@ -432,6 +432,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GlobalPublicDelegatedPrefixesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py index f1eb9fc4a6c1..b8b6963e6a83 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/client.py @@ -108,7 +108,7 @@ class HealthChecksClient(metaclass=HealthChecksClientMeta): """The HealthChecks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = HealthChecksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/README.rst index 3b5402d90312..efebd296f212 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HealthChecksTransport` is the ABC for all transports. -- public child `HealthChecksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HealthChecksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHealthChecksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HealthChecksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HealthChecksTransport`` is the ABC for all transports. + +- public child ``HealthChecksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HealthChecksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHealthChecksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HealthChecksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/base.py index ebdcd1b339a2..99a4afb3f5b1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/rest.py index 82fdbcc8c562..b67060ef664d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/health_checks/transports/rest.py @@ -589,6 +589,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[HealthChecksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py index 235af04fdce8..e5a4347758dc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/client.py @@ -104,7 +104,7 @@ class ImageFamilyViewsClient(metaclass=ImageFamilyViewsClientMeta): """The ImageFamilyViews API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -605,7 +609,7 @@ def __init__( self._universe_domain = ImageFamilyViewsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/README.rst index c62510ee57ac..2fc816570f86 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ImageFamilyViewsTransport` is the ABC for all transports. -- public child `ImageFamilyViewsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ImageFamilyViewsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseImageFamilyViewsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ImageFamilyViewsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ImageFamilyViewsTransport`` is the ABC for all transports. + +- public child ``ImageFamilyViewsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ImageFamilyViewsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseImageFamilyViewsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ImageFamilyViewsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/base.py index c90c4774be5e..d2913751bc54 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/rest.py index e73b0ab62eb4..04ea1c5bcf5f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/image_family_views/transports/rest.py @@ -203,6 +203,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ImageFamilyViewsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py index 82b297d79eed..20657c9f18a8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/client.py @@ -108,7 +108,7 @@ class ImagesClient(metaclass=ImagesClientMeta): """The Images API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = ImagesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/README.rst index 4d4c30630dc1..dd9e3b477504 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ImagesTransport` is the ABC for all transports. -- public child `ImagesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ImagesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseImagesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ImagesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ImagesTransport`` is the ABC for all transports. + +- public child ``ImagesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ImagesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseImagesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ImagesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/base.py index b286307402e3..7634db55196f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/rest.py index aaaa71892cd4..8fd4f3640553 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/images/transports/rest.py @@ -729,6 +729,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ImagesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py index 70f9edd3615e..ea3f42e7aa10 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/client.py @@ -115,7 +115,7 @@ class InstanceGroupManagerResizeRequestsClient( """The InstanceGroupManagerResizeRequests API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -422,7 +426,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -523,7 +527,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -630,7 +634,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/README.rst index a0e4e899d30c..7eeef33a7059 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceGroupManagerResizeRequestsTransport` is the ABC for all transports. -- public child `InstanceGroupManagerResizeRequestsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceGroupManagerResizeRequestsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceGroupManagerResizeRequestsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceGroupManagerResizeRequestsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceGroupManagerResizeRequestsTransport`` is the ABC for all transports. + +- public child ``InstanceGroupManagerResizeRequestsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceGroupManagerResizeRequestsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceGroupManagerResizeRequestsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceGroupManagerResizeRequestsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/base.py index 0abc67600b3a..7747d5aab5f4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/rest.py index 55dbff6e2e9c..313fed8cb557 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_manager_resize_requests/transports/rest.py @@ -436,6 +436,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceGroupManagerResizeRequestsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py index 9d7c540c59e2..619a9e9e0837 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/client.py @@ -108,7 +108,7 @@ class InstanceGroupManagersClient(metaclass=InstanceGroupManagersClientMeta): """The InstanceGroupManagers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = InstanceGroupManagersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/README.rst index dd9373c3ddf2..ecbbc1f2cc32 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceGroupManagersTransport` is the ABC for all transports. -- public child `InstanceGroupManagersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceGroupManagersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceGroupManagersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceGroupManagersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceGroupManagersTransport`` is the ABC for all transports. + +- public child ``InstanceGroupManagersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceGroupManagersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceGroupManagersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceGroupManagersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/base.py index 3d92b17de019..59f19abb209e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py index a46bd57ed3e0..afed486845d8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py @@ -1504,6 +1504,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceGroupManagersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py index 03ac668cc162..cbcc58650eff 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/client.py @@ -108,7 +108,7 @@ class InstanceGroupsClient(metaclass=InstanceGroupsClientMeta): """The InstanceGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = InstanceGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/README.rst index a8d509774e2e..c977e93b2874 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceGroupsTransport` is the ABC for all transports. -- public child `InstanceGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceGroupsTransport`` is the ABC for all transports. + +- public child ``InstanceGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/base.py index 077e0a360a26..dbc9615e6ba3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/rest.py index 4db32694dd9c..64725afa6917 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_groups/transports/rest.py @@ -709,6 +709,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py index 0fd487ffb9f8..4fa54c0d70e7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/client.py @@ -107,7 +107,7 @@ class InstanceSettingsServiceClient(metaclass=InstanceSettingsServiceClientMeta) """The InstanceSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = InstanceSettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/README.rst index 886a1d3cc987..f3e4963e3c9a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceSettingsServiceTransport` is the ABC for all transports. -- public child `InstanceSettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceSettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceSettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceSettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceSettingsServiceTransport`` is the ABC for all transports. + +- public child ``InstanceSettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceSettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceSettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceSettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/base.py index b5b46f083136..c2dace806619 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/rest.py index ca0ac26ff451..795fc47365ff 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_settings_service/transports/rest.py @@ -257,6 +257,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceSettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py index 355592a27173..351dbcefb190 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/client.py @@ -108,7 +108,7 @@ class InstanceTemplatesClient(metaclass=InstanceTemplatesClientMeta): """The InstanceTemplates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = InstanceTemplatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/README.rst index 804386249c2b..c6f61c70b033 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstanceTemplatesTransport` is the ABC for all transports. -- public child `InstanceTemplatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstanceTemplatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstanceTemplatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstanceTemplatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstanceTemplatesTransport`` is the ABC for all transports. + +- public child ``InstanceTemplatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstanceTemplatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstanceTemplatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstanceTemplatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/base.py index 596a6cf492bf..d1dc9272ea44 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/rest.py index 00824c7cecf2..a2116f2dfe64 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instance_templates/transports/rest.py @@ -595,6 +595,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstanceTemplatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py index 311d7584205a..a013a0fc6953 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/client.py @@ -108,7 +108,7 @@ class InstancesClient(metaclass=InstancesClientMeta): """The Instances API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = InstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/README.rst index 452ca471f507..2834efc80854 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstancesTransport` is the ABC for all transports. -- public child `InstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstancesTransport`` is the ABC for all transports. + +- public child ``InstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/base.py index 9ca55c3563f0..8839645667a6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/rest.py index 3a514d5700b2..b5c4befb88bd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instances/transports/rest.py @@ -2971,6 +2971,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py index 7c143c6ec6e9..8044b37dead0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/client.py @@ -108,7 +108,7 @@ class InstantSnapshotsClient(metaclass=InstantSnapshotsClientMeta): """The InstantSnapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = InstantSnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/README.rst index 8d75b3145d2e..48a2bb891830 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InstantSnapshotsTransport` is the ABC for all transports. -- public child `InstantSnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InstantSnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInstantSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InstantSnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InstantSnapshotsTransport`` is the ABC for all transports. + +- public child ``InstantSnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InstantSnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInstantSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InstantSnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/base.py index b337d03a3235..e6097268545d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/rest.py index 32f4edb619e5..8a7bcb765ed8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/instant_snapshots/transports/rest.py @@ -649,6 +649,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InstantSnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py index f07b30d1f1ec..03134373247d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/client.py @@ -110,7 +110,7 @@ class InterconnectAttachmentGroupsClient( """The InterconnectAttachmentGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -621,7 +625,7 @@ def __init__( self._universe_domain = InterconnectAttachmentGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/README.rst index 0834929c9de6..df645cdecc7f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectAttachmentGroupsTransport` is the ABC for all transports. -- public child `InterconnectAttachmentGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectAttachmentGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectAttachmentGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectAttachmentGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectAttachmentGroupsTransport`` is the ABC for all transports. + +- public child ``InterconnectAttachmentGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectAttachmentGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectAttachmentGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectAttachmentGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/base.py index eaa016d4eb2a..e6bfed2f65c4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/rest.py index 68af67808106..db5e9297c8b7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachment_groups/transports/rest.py @@ -664,6 +664,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectAttachmentGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py index 890482d2a570..8290d10781c4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/client.py @@ -108,7 +108,7 @@ class InterconnectAttachmentsClient(metaclass=InterconnectAttachmentsClientMeta) """The InterconnectAttachments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = InterconnectAttachmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/README.rst index 39532a50c7e0..6fb7b9a998f3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectAttachmentsTransport` is the ABC for all transports. -- public child `InterconnectAttachmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectAttachmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectAttachmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectAttachmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectAttachmentsTransport`` is the ABC for all transports. + +- public child ``InterconnectAttachmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectAttachmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectAttachmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectAttachmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py index 2d25a88a2815..f3a0ffc78d4f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py index 5cab81081c98..e072cdaba25c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py @@ -545,6 +545,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectAttachmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py index cddfd2ff5a28..7531e39cc37a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/client.py @@ -108,7 +108,7 @@ class InterconnectGroupsClient(metaclass=InterconnectGroupsClientMeta): """The InterconnectGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = InterconnectGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/README.rst index aff13520eab7..9d1ce51d663d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectGroupsTransport` is the ABC for all transports. -- public child `InterconnectGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectGroupsTransport`` is the ABC for all transports. + +- public child ``InterconnectGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/base.py index 29bbd37a0ca8..e6b19a04af6a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/rest.py index 89a584f9f8d8..0a6fc459db6e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_groups/transports/rest.py @@ -709,6 +709,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py index 92fbda162c5e..e8b438d7566e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/client.py @@ -105,7 +105,7 @@ class InterconnectLocationsClient(metaclass=InterconnectLocationsClientMeta): """The InterconnectLocations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -610,7 +614,7 @@ def __init__( self._universe_domain = InterconnectLocationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/README.rst index a98caceeb490..50aad743a229 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectLocationsTransport` is the ABC for all transports. -- public child `InterconnectLocationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectLocationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectLocationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectLocationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectLocationsTransport`` is the ABC for all transports. + +- public child ``InterconnectLocationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectLocationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectLocationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectLocationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/base.py index b10a10168f92..f0c3d420c601 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py index cd986e6e7006..267726fdc483 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py @@ -264,6 +264,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectLocationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py index ccf7e754aa04..7b2f07b50604 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/client.py @@ -107,7 +107,7 @@ class InterconnectRemoteLocationsClient( """The InterconnectRemoteLocations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = InterconnectRemoteLocationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/README.rst index 403edd2aacf5..15b3e70d7286 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectRemoteLocationsTransport` is the ABC for all transports. -- public child `InterconnectRemoteLocationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectRemoteLocationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectRemoteLocationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectRemoteLocationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectRemoteLocationsTransport`` is the ABC for all transports. + +- public child ``InterconnectRemoteLocationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectRemoteLocationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectRemoteLocationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectRemoteLocationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/base.py index 4afc5fb59291..6e40e9ca5ff0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/rest.py index 8514cbcb034b..78c1504cd10b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnect_remote_locations/transports/rest.py @@ -269,6 +269,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectRemoteLocationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py index 956320500f3c..4db3fec7b8d1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/client.py @@ -108,7 +108,7 @@ class InterconnectsClient(metaclass=InterconnectsClientMeta): """The Interconnects API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = InterconnectsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/README.rst index a4959f4e15f6..8593d0e6cbae 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InterconnectsTransport` is the ABC for all transports. -- public child `InterconnectsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InterconnectsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInterconnectsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InterconnectsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InterconnectsTransport`` is the ABC for all transports. + +- public child ``InterconnectsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InterconnectsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInterconnectsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InterconnectsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/base.py index 36e7b8b34c69..f23890b8b80c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/rest.py index 8bdaf62caa90..84512ac040aa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/interconnects/transports/rest.py @@ -591,6 +591,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InterconnectsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py index f1b8a7a505a4..e347243172b6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/client.py @@ -104,7 +104,7 @@ class LicenseCodesClient(metaclass=LicenseCodesClientMeta): """The LicenseCodes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -603,7 +607,7 @@ def __init__( self._universe_domain = LicenseCodesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/README.rst index d23b8f4b2467..bc2b0d3463ea 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LicenseCodesTransport` is the ABC for all transports. -- public child `LicenseCodesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LicenseCodesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLicenseCodesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LicenseCodesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LicenseCodesTransport`` is the ABC for all transports. + +- public child ``LicenseCodesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LicenseCodesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLicenseCodesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LicenseCodesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/base.py index 17346157633e..b0e36286fe0f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/rest.py index d896ec38fe2c..d23651ac2903 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/license_codes/transports/rest.py @@ -260,6 +260,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LicenseCodesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py index cdb773478ed5..bc1520698991 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/client.py @@ -108,7 +108,7 @@ class LicensesClient(metaclass=LicensesClientMeta): """The Licenses API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = LicensesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/README.rst index 58d11e1a7eb5..310e46bc9c74 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LicensesTransport` is the ABC for all transports. -- public child `LicensesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LicensesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLicensesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LicensesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LicensesTransport`` is the ABC for all transports. + +- public child ``LicensesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LicensesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLicensesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LicensesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/base.py index b3850c608562..9cb366c48c3b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/rest.py index fb204fd26d60..982a87851de8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/licenses/transports/rest.py @@ -578,6 +578,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LicensesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py index 72aae241e848..726b75d982a5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/client.py @@ -108,7 +108,7 @@ class MachineImagesClient(metaclass=MachineImagesClientMeta): """The MachineImages API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = MachineImagesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/README.rst index ddd13a3780af..91e0c8aae5aa 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MachineImagesTransport` is the ABC for all transports. -- public child `MachineImagesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MachineImagesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMachineImagesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MachineImagesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MachineImagesTransport`` is the ABC for all transports. + +- public child ``MachineImagesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MachineImagesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMachineImagesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MachineImagesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/base.py index e2fc8f86debc..43c399c7c65d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/rest.py index 48bc2a4fc809..7bbe1bd1dfdd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_images/transports/rest.py @@ -584,6 +584,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MachineImagesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py index 2a286821c81d..4e241ffe9876 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/client.py @@ -105,7 +105,7 @@ class MachineTypesClient(metaclass=MachineTypesClientMeta): """The MachineTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = MachineTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/README.rst index ed40ee8f5462..4dcfe7c23385 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MachineTypesTransport` is the ABC for all transports. -- public child `MachineTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MachineTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMachineTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MachineTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MachineTypesTransport`` is the ABC for all transports. + +- public child ``MachineTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MachineTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMachineTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MachineTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/base.py index 5cde134cac2e..336d40c892f4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/rest.py index e783a2252245..ddc34f73434e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/machine_types/transports/rest.py @@ -314,6 +314,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MachineTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py index ee40177ef7d1..887dda2a49db 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/client.py @@ -108,7 +108,7 @@ class NetworkAttachmentsClient(metaclass=NetworkAttachmentsClientMeta): """The NetworkAttachments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = NetworkAttachmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/README.rst index 597522afb370..77bc6885baed 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkAttachmentsTransport` is the ABC for all transports. -- public child `NetworkAttachmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkAttachmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkAttachmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkAttachmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkAttachmentsTransport`` is the ABC for all transports. + +- public child ``NetworkAttachmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkAttachmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkAttachmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkAttachmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/base.py index e35dd89d0393..9c535bde4bdd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/rest.py index b45c7b17db5f..8887af56c3ea 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_attachments/transports/rest.py @@ -651,6 +651,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkAttachmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py index ac01eb90cd17..5513ea0b4c03 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/client.py @@ -110,7 +110,7 @@ class NetworkEdgeSecurityServicesClient( """The NetworkEdgeSecurityServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = NetworkEdgeSecurityServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/README.rst index 3c603c1b90cc..b5262a6b51cd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkEdgeSecurityServicesTransport` is the ABC for all transports. -- public child `NetworkEdgeSecurityServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkEdgeSecurityServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkEdgeSecurityServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkEdgeSecurityServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkEdgeSecurityServicesTransport`` is the ABC for all transports. + +- public child ``NetworkEdgeSecurityServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkEdgeSecurityServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkEdgeSecurityServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkEdgeSecurityServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/base.py index d8abcbde9730..fbb3fca19fe3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/rest.py index 663f5848ad26..7d102f1cb3db 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_edge_security_services/transports/rest.py @@ -435,6 +435,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkEdgeSecurityServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py index 3a730b0cc81d..67e0cea15acc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/client.py @@ -108,7 +108,7 @@ class NetworkEndpointGroupsClient(metaclass=NetworkEndpointGroupsClientMeta): """The NetworkEndpointGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = NetworkEndpointGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/README.rst index 172d7d0b7d8d..eb3be0b4093d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkEndpointGroupsTransport` is the ABC for all transports. -- public child `NetworkEndpointGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkEndpointGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkEndpointGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkEndpointGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkEndpointGroupsTransport`` is the ABC for all transports. + +- public child ``NetworkEndpointGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkEndpointGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkEndpointGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkEndpointGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py index 919c86420275..9d0a4adb968a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py index dc08edae834d..8382e6a671e8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py @@ -667,6 +667,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkEndpointGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py index 90e6054eb935..1d024fb37a6d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/client.py @@ -108,7 +108,7 @@ class NetworkFirewallPoliciesClient(metaclass=NetworkFirewallPoliciesClientMeta) """The NetworkFirewallPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = NetworkFirewallPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/README.rst index 9b286ee5b8d1..03ed2a3e73c4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkFirewallPoliciesTransport` is the ABC for all transports. -- public child `NetworkFirewallPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkFirewallPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkFirewallPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkFirewallPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkFirewallPoliciesTransport`` is the ABC for all transports. + +- public child ``NetworkFirewallPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkFirewallPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkFirewallPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkFirewallPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/base.py index 53e29bd9bdea..2b84fc66e103 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/rest.py index dde0e8916d23..221b74f65a45 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_firewall_policies/transports/rest.py @@ -1328,6 +1328,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkFirewallPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py index fa2b0ee68cfc..80379ce560cd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/client.py @@ -105,7 +105,7 @@ class NetworkProfilesClient(metaclass=NetworkProfilesClientMeta): """The NetworkProfiles API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = NetworkProfilesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/README.rst index a640a3575956..b9ee5bdc47e7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworkProfilesTransport` is the ABC for all transports. -- public child `NetworkProfilesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworkProfilesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworkProfilesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworkProfilesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworkProfilesTransport`` is the ABC for all transports. + +- public child ``NetworkProfilesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworkProfilesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworkProfilesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworkProfilesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/base.py index e92b02924fac..6144557ca12b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/rest.py index bb7414e394fe..43a7a5fce698 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/network_profiles/transports/rest.py @@ -261,6 +261,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworkProfilesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py index d9eb8be45fb9..6019e1698a8d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/client.py @@ -108,7 +108,7 @@ class NetworksClient(metaclass=NetworksClientMeta): """The Networks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = NetworksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/README.rst index d6735c6e0f0f..9eeb5d9187c7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetworksTransport` is the ABC for all transports. -- public child `NetworksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetworksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetworksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetworksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetworksTransport`` is the ABC for all transports. + +- public child ``NetworksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetworksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetworksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetworksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/base.py index 7f1181589b3e..28b39d5fce6a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/rest.py index 53962e8e4dde..bc977729ffdb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/networks/transports/rest.py @@ -804,6 +804,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetworksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py index 85f6c2061e7a..3eec8c9d1eda 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/client.py @@ -108,7 +108,7 @@ class NodeGroupsClient(metaclass=NodeGroupsClientMeta): """The NodeGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = NodeGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/README.rst index 12d7d0818a62..f87033a02559 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeGroupsTransport` is the ABC for all transports. -- public child `NodeGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeGroupsTransport`` is the ABC for all transports. + +- public child ``NodeGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/base.py index f4bfe977afa9..91dbb78bf6bb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/rest.py index 32d2418c73e3..2eee806fa5ad 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_groups/transports/rest.py @@ -966,6 +966,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py index 0602b32a630d..88c7d5eb2531 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/client.py @@ -108,7 +108,7 @@ class NodeTemplatesClient(metaclass=NodeTemplatesClientMeta): """The NodeTemplates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = NodeTemplatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/README.rst index f7d8910f07ec..ca407846760d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeTemplatesTransport` is the ABC for all transports. -- public child `NodeTemplatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeTemplatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeTemplatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeTemplatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeTemplatesTransport`` is the ABC for all transports. + +- public child ``NodeTemplatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeTemplatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeTemplatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeTemplatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/base.py index 3b32f1f20732..2df9ef398fd0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/rest.py index f2dd42deafc4..723401070ba1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_templates/transports/rest.py @@ -589,6 +589,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeTemplatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py index 4cd8345b4f89..754a9d4f0046 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/client.py @@ -105,7 +105,7 @@ class NodeTypesClient(metaclass=NodeTypesClientMeta): """The NodeTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = NodeTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/README.rst index 1053ced918d8..8e0a48dd683f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeTypesTransport` is the ABC for all transports. -- public child `NodeTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeTypesTransport`` is the ABC for all transports. + +- public child ``NodeTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/base.py index 183f7ec7c506..a309b4023243 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/rest.py index 7a69a6139e97..961ef21dc1b0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/node_types/transports/rest.py @@ -309,6 +309,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py index 43199bde4a8d..241e1709fac4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/client.py @@ -110,7 +110,7 @@ class OrganizationSecurityPoliciesClient( """The OrganizationSecurityPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -621,7 +625,7 @@ def __init__( self._universe_domain = OrganizationSecurityPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/README.rst index 1985deee532e..ecefdbba5679 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`OrganizationSecurityPoliciesTransport` is the ABC for all transports. -- public child `OrganizationSecurityPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `OrganizationSecurityPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseOrganizationSecurityPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `OrganizationSecurityPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``OrganizationSecurityPoliciesTransport`` is the ABC for all transports. + +- public child ``OrganizationSecurityPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``OrganizationSecurityPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseOrganizationSecurityPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``OrganizationSecurityPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/base.py index e6a3ee116f03..4585239d6223 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/rest.py index 30d3e41f6a6c..0ccdc1a9e88b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/organization_security_policies/transports/rest.py @@ -1049,6 +1049,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[OrganizationSecurityPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py index a94e3a2d8a40..00c461890fae 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/client.py @@ -108,7 +108,7 @@ class PacketMirroringsClient(metaclass=PacketMirroringsClientMeta): """The PacketMirrorings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = PacketMirroringsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/README.rst index 969577889999..a6bfdd7b1fdc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PacketMirroringsTransport` is the ABC for all transports. -- public child `PacketMirroringsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PacketMirroringsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePacketMirroringsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PacketMirroringsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PacketMirroringsTransport`` is the ABC for all transports. + +- public child ``PacketMirroringsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PacketMirroringsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePacketMirroringsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PacketMirroringsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py index 9c2bb6f06e26..b8d4f422fdb9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py index b0f85704b2fb..7672acee5746 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py @@ -539,6 +539,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PacketMirroringsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py index f0334d564339..dc5de6955604 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/client.py @@ -108,7 +108,7 @@ class PreviewFeaturesClient(metaclass=PreviewFeaturesClientMeta): """The PreviewFeatures API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = PreviewFeaturesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/README.rst index 808797795f8f..842e5308bb7a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PreviewFeaturesTransport` is the ABC for all transports. -- public child `PreviewFeaturesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PreviewFeaturesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePreviewFeaturesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PreviewFeaturesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PreviewFeaturesTransport`` is the ABC for all transports. + +- public child ``PreviewFeaturesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PreviewFeaturesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePreviewFeaturesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PreviewFeaturesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/base.py index 18ad38607029..3ab6a2526b80 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/rest.py index daf3a212d253..82ec3558cca4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/preview_features/transports/rest.py @@ -313,6 +313,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PreviewFeaturesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py index e42ad8b2f50b..f79684b64c7b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/client.py @@ -108,7 +108,7 @@ class ProjectsClient(metaclass=ProjectsClientMeta): """The Projects API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = ProjectsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/README.rst index e832f0d51f32..ed2db28f745e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProjectsTransport` is the ABC for all transports. -- public child `ProjectsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProjectsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProjectsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProjectsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProjectsTransport`` is the ABC for all transports. + +- public child ``ProjectsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProjectsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProjectsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProjectsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/base.py index 592f7b9e6637..c155a4fda03c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/rest.py index 49fc5cbed18a..ea7669f6a36a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/projects/transports/rest.py @@ -921,6 +921,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProjectsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py index 0546252fe4d4..46cb4714bc60 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/client.py @@ -108,7 +108,7 @@ class PublicAdvertisedPrefixesClient(metaclass=PublicAdvertisedPrefixesClientMet """The PublicAdvertisedPrefixes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = PublicAdvertisedPrefixesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/README.rst index 58df8e61afd1..49134c3896db 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PublicAdvertisedPrefixesTransport` is the ABC for all transports. -- public child `PublicAdvertisedPrefixesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PublicAdvertisedPrefixesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePublicAdvertisedPrefixesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PublicAdvertisedPrefixesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PublicAdvertisedPrefixesTransport`` is the ABC for all transports. + +- public child ``PublicAdvertisedPrefixesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PublicAdvertisedPrefixesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePublicAdvertisedPrefixesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PublicAdvertisedPrefixesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py index 4acab28a02d1..6d858e8fc423 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py index 4df2c46f39ba..d1178d8d0f29 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py @@ -540,6 +540,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PublicAdvertisedPrefixesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py index 7d90ecc28fc8..ca303a52f949 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/client.py @@ -108,7 +108,7 @@ class PublicDelegatedPrefixesClient(metaclass=PublicDelegatedPrefixesClientMeta) """The PublicDelegatedPrefixes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = PublicDelegatedPrefixesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/README.rst index bf9786004e2f..802b7328bf16 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PublicDelegatedPrefixesTransport` is the ABC for all transports. -- public child `PublicDelegatedPrefixesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PublicDelegatedPrefixesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePublicDelegatedPrefixesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PublicDelegatedPrefixesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PublicDelegatedPrefixesTransport`` is the ABC for all transports. + +- public child ``PublicDelegatedPrefixesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PublicDelegatedPrefixesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePublicDelegatedPrefixesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PublicDelegatedPrefixesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py index dec613504237..26365c879e36 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py index 317d09eeef4d..e716dda95dab 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py @@ -600,6 +600,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PublicDelegatedPrefixesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py index 512de0cb4be8..e811524ffb44 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/client.py @@ -108,7 +108,7 @@ class RegionAutoscalersClient(metaclass=RegionAutoscalersClientMeta): """The RegionAutoscalers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionAutoscalersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/README.rst index baedafa8805e..e8ea3fe9ab18 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionAutoscalersTransport` is the ABC for all transports. -- public child `RegionAutoscalersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionAutoscalersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionAutoscalersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionAutoscalersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionAutoscalersTransport`` is the ABC for all transports. + +- public child ``RegionAutoscalersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionAutoscalersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionAutoscalersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionAutoscalersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/base.py index dce51c5fb751..2eee5b727557 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py index ef2a2d6bd28e..7ca62138fde0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionAutoscalersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py index 5eb8a9a01ef4..75a345fe87ab 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/client.py @@ -108,7 +108,7 @@ class RegionBackendServicesClient(metaclass=RegionBackendServicesClientMeta): """The RegionBackendServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionBackendServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/README.rst index 99f43788575c..6efaddab1d5c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionBackendServicesTransport` is the ABC for all transports. -- public child `RegionBackendServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionBackendServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionBackendServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionBackendServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionBackendServicesTransport`` is the ABC for all transports. + +- public child ``RegionBackendServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionBackendServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionBackendServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionBackendServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/base.py index 7f92f8875625..2f8b19bf0d63 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/rest.py index a991b28c0bfd..f737a6077be8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_backend_services/transports/rest.py @@ -824,6 +824,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionBackendServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py index 0e50a5393976..6194d6253ba9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/client.py @@ -108,7 +108,7 @@ class RegionCommitmentsClient(metaclass=RegionCommitmentsClientMeta): """The RegionCommitments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionCommitmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/README.rst index ce87aa795eac..568a06ef3572 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionCommitmentsTransport` is the ABC for all transports. -- public child `RegionCommitmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionCommitmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionCommitmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionCommitmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionCommitmentsTransport`` is the ABC for all transports. + +- public child ``RegionCommitmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionCommitmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionCommitmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionCommitmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/base.py index 8a486ee4207c..7c983ac2c212 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/rest.py index a3aee94bacd1..e2f1a6b99c42 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_commitments/transports/rest.py @@ -424,6 +424,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionCommitmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py index 6d8029280849..e6515b2ad883 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/client.py @@ -110,7 +110,7 @@ class RegionCompositeHealthChecksClient( """The RegionCompositeHealthChecks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionCompositeHealthChecksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/README.rst index 97612e7c69fa..c671f10ebb42 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionCompositeHealthChecksTransport` is the ABC for all transports. -- public child `RegionCompositeHealthChecksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionCompositeHealthChecksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionCompositeHealthChecksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionCompositeHealthChecksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionCompositeHealthChecksTransport`` is the ABC for all transports. + +- public child ``RegionCompositeHealthChecksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionCompositeHealthChecksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionCompositeHealthChecksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionCompositeHealthChecksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/base.py index c1df8f40ef55..c1510e8bcb49 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/rest.py index 823f9ed40956..08591735c4b4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_composite_health_checks/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionCompositeHealthChecksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py index c6f9d498dfe5..3b44e5aeb917 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/client.py @@ -105,7 +105,7 @@ class RegionDiskTypesClient(metaclass=RegionDiskTypesClientMeta): """The RegionDiskTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = RegionDiskTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/README.rst index aab6392320a5..4bc73728d645 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionDiskTypesTransport` is the ABC for all transports. -- public child `RegionDiskTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionDiskTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionDiskTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionDiskTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionDiskTypesTransport`` is the ABC for all transports. + +- public child ``RegionDiskTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionDiskTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionDiskTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionDiskTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/base.py index 53886a050599..356ff52d58ba 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/rest.py index 15c5996b528d..507c007545cd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disk_types/transports/rest.py @@ -259,6 +259,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionDiskTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py index 691505fee8fd..a988ec77a72c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/client.py @@ -108,7 +108,7 @@ class RegionDisksClient(metaclass=RegionDisksClientMeta): """The RegionDisks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RegionDisksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/README.rst index e9e430ff6f3d..9845c29f10e3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionDisksTransport` is the ABC for all transports. -- public child `RegionDisksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionDisksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionDisksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionDisksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionDisksTransport`` is the ABC for all transports. + +- public child ``RegionDisksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionDisksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionDisksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionDisksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/base.py index 748305dd2c7e..ee1c2d390d2f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/rest.py index b8e70ab8ca00..834c763bbbf4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_disks/transports/rest.py @@ -1081,6 +1081,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionDisksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py index a59d8032deb2..93fdb50ae11c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/client.py @@ -113,7 +113,7 @@ class RegionHealthAggregationPoliciesClient( """The RegionHealthAggregationPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -420,7 +424,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -519,7 +523,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/README.rst index 09c62d1c2230..6ee13339bc2e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthAggregationPoliciesTransport` is the ABC for all transports. -- public child `RegionHealthAggregationPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthAggregationPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthAggregationPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthAggregationPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthAggregationPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionHealthAggregationPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthAggregationPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthAggregationPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthAggregationPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/base.py index f64153e3b6a3..1715636b2268 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/rest.py index a0c8c5bdf3df..235522ba9eac 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_aggregation_policies/transports/rest.py @@ -553,6 +553,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthAggregationPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py index e1f078309af9..39553fd85b22 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/client.py @@ -108,7 +108,7 @@ class RegionHealthCheckServicesClient(metaclass=RegionHealthCheckServicesClientM """The RegionHealthCheckServices API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionHealthCheckServicesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/README.rst index d6dfc409ab15..8dbfe234aade 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthCheckServicesTransport` is the ABC for all transports. -- public child `RegionHealthCheckServicesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthCheckServicesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthCheckServicesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthCheckServicesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthCheckServicesTransport`` is the ABC for all transports. + +- public child ``RegionHealthCheckServicesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthCheckServicesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthCheckServicesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthCheckServicesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/base.py index 844889aafd7f..fc31d7192714 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py index eaf834b414cc..c892f198f460 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthCheckServicesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py index e9cd50cb1846..da5eecc62968 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/client.py @@ -108,7 +108,7 @@ class RegionHealthChecksClient(metaclass=RegionHealthChecksClientMeta): """The RegionHealthChecks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionHealthChecksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/README.rst index 2f361d99ebbc..77fd6d188bc6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthChecksTransport` is the ABC for all transports. -- public child `RegionHealthChecksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthChecksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthChecksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthChecksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthChecksTransport`` is the ABC for all transports. + +- public child ``RegionHealthChecksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthChecksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthChecksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthChecksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/base.py index 73be4bfdc0e1..2b0e0030a199 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/rest.py index fc0add36eabc..4735d1a011c1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_checks/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthChecksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py index a7bbff8afee3..5ba685079b02 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/client.py @@ -108,7 +108,7 @@ class RegionHealthSourcesClient(metaclass=RegionHealthSourcesClientMeta): """The RegionHealthSources API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionHealthSourcesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/README.rst index 8365e0728465..b098080ff5bc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionHealthSourcesTransport` is the ABC for all transports. -- public child `RegionHealthSourcesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionHealthSourcesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionHealthSourcesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionHealthSourcesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionHealthSourcesTransport`` is the ABC for all transports. + +- public child ``RegionHealthSourcesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionHealthSourcesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionHealthSourcesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionHealthSourcesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/base.py index dff6706a9302..04180c3d8ad8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/rest.py index 79dd5feca542..3e6d8d833cc7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_health_sources/transports/rest.py @@ -537,6 +537,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionHealthSourcesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py index f0d839e994c4..2c4c6242b1b3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/client.py @@ -110,7 +110,7 @@ class RegionInstanceGroupManagersClient( """The RegionInstanceGroupManagers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionInstanceGroupManagersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/README.rst index 57ef26008635..a3f74cd30679 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceGroupManagersTransport` is the ABC for all transports. -- public child `RegionInstanceGroupManagersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceGroupManagersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceGroupManagersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceGroupManagersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceGroupManagersTransport`` is the ABC for all transports. + +- public child ``RegionInstanceGroupManagersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceGroupManagersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceGroupManagersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceGroupManagersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py index e2e1e0fb8a11..6e42deb3a5ed 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py index 114b3c219bd2..20036fa6e951 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py @@ -1447,6 +1447,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceGroupManagersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py index be1628d70822..c7b990e83fc2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/client.py @@ -108,7 +108,7 @@ class RegionInstanceGroupsClient(metaclass=RegionInstanceGroupsClientMeta): """The RegionInstanceGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionInstanceGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/README.rst index d6a6c7775f98..b798bb2438f0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceGroupsTransport` is the ABC for all transports. -- public child `RegionInstanceGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceGroupsTransport`` is the ABC for all transports. + +- public child ``RegionInstanceGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/base.py index d73fa4905b24..528cb2c4c51a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py index 33a63e626c50..b74e34a884f7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py @@ -435,6 +435,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py index 1e9189b176e4..e1f5ad5754c8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/client.py @@ -108,7 +108,7 @@ class RegionInstanceTemplatesClient(metaclass=RegionInstanceTemplatesClientMeta) """The RegionInstanceTemplates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionInstanceTemplatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/README.rst index 261e60771474..ea64dd44f8cc 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstanceTemplatesTransport` is the ABC for all transports. -- public child `RegionInstanceTemplatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstanceTemplatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstanceTemplatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstanceTemplatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstanceTemplatesTransport`` is the ABC for all transports. + +- public child ``RegionInstanceTemplatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstanceTemplatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstanceTemplatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstanceTemplatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/base.py index 413b8178744d..fd0b558c77d2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/rest.py index 99504433dc74..be4589403565 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instance_templates/transports/rest.py @@ -371,6 +371,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstanceTemplatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py index 224befc8e091..fa4deb9e8f48 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/client.py @@ -107,7 +107,7 @@ class RegionInstancesClient(metaclass=RegionInstancesClientMeta): """The RegionInstances API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -507,7 +511,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = RegionInstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/README.rst index d32a0b4eca29..7dfbb6d5199c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstancesTransport` is the ABC for all transports. -- public child `RegionInstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstancesTransport`` is the ABC for all transports. + +- public child ``RegionInstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/base.py index fff7432e5e2b..e058972e1d29 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/rest.py index 13afa1f720b6..df004ef9425c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instances/transports/rest.py @@ -203,6 +203,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py index db528fda871f..dd9ade250cc1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/client.py @@ -108,7 +108,7 @@ class RegionInstantSnapshotsClient(metaclass=RegionInstantSnapshotsClientMeta): """The RegionInstantSnapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionInstantSnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/README.rst index d91f1e70c759..5c5dfbef391a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionInstantSnapshotsTransport` is the ABC for all transports. -- public child `RegionInstantSnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionInstantSnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionInstantSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionInstantSnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionInstantSnapshotsTransport`` is the ABC for all transports. + +- public child ``RegionInstantSnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionInstantSnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionInstantSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionInstantSnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/base.py index 56c00cb5d5c3..230644ccc904 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/rest.py index b349302f4464..6b52d5929f1a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_instant_snapshots/transports/rest.py @@ -594,6 +594,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionInstantSnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py index 6efde83b562b..06e73abe7ca9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/client.py @@ -110,7 +110,7 @@ class RegionNetworkEndpointGroupsClient( """The RegionNetworkEndpointGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionNetworkEndpointGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/README.rst index 219c26060241..e8571d46b424 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNetworkEndpointGroupsTransport` is the ABC for all transports. -- public child `RegionNetworkEndpointGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNetworkEndpointGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNetworkEndpointGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNetworkEndpointGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNetworkEndpointGroupsTransport`` is the ABC for all transports. + +- public child ``RegionNetworkEndpointGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNetworkEndpointGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNetworkEndpointGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNetworkEndpointGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py index a06e4919e183..7f5be9915407 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py index 6928526415bf..f11f86643e39 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py @@ -551,6 +551,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNetworkEndpointGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py index 373ed6d7bc55..dd14446877b8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/client.py @@ -110,7 +110,7 @@ class RegionNetworkFirewallPoliciesClient( """The RegionNetworkFirewallPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -417,7 +421,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -516,7 +520,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -623,7 +627,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/README.rst index c1f92c8931dc..681974e0a1be 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNetworkFirewallPoliciesTransport` is the ABC for all transports. -- public child `RegionNetworkFirewallPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNetworkFirewallPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNetworkFirewallPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNetworkFirewallPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNetworkFirewallPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionNetworkFirewallPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNetworkFirewallPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNetworkFirewallPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNetworkFirewallPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/base.py index d69fc0227aa7..670e64e1a916 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/rest.py index 0413a0e8396d..e1b3858f0d77 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_network_firewall_policies/transports/rest.py @@ -1104,6 +1104,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNetworkFirewallPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py index 2ac33d025bb5..40156a2cfff6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/client.py @@ -110,7 +110,7 @@ class RegionNotificationEndpointsClient( """The RegionNotificationEndpoints API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = RegionNotificationEndpointsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/README.rst index 306a49513d33..fce4db242cf4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionNotificationEndpointsTransport` is the ABC for all transports. -- public child `RegionNotificationEndpointsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionNotificationEndpointsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionNotificationEndpointsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionNotificationEndpointsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionNotificationEndpointsTransport`` is the ABC for all transports. + +- public child ``RegionNotificationEndpointsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionNotificationEndpointsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionNotificationEndpointsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionNotificationEndpointsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py index 39cdd4a53c17..d8bc6c0ae8a1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py index 77776a3e65f5..67a08f1a7e80 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py @@ -496,6 +496,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionNotificationEndpointsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py index 9dd89cfeefe9..97f97a62cc1a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/client.py @@ -105,7 +105,7 @@ class RegionOperationsClient(metaclass=RegionOperationsClientMeta): """The RegionOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = RegionOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/README.rst index aba34e5181d4..1c7b7c6c6452 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionOperationsTransport` is the ABC for all transports. -- public child `RegionOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionOperationsTransport`` is the ABC for all transports. + +- public child ``RegionOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/base.py index 86a408835699..af328a872e47 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/rest.py index 920e47a5524b..d90b8b326be6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_operations/transports/rest.py @@ -369,6 +369,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py index 91002b072567..6d103611235d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/client.py @@ -108,7 +108,7 @@ class RegionSecurityPoliciesClient(metaclass=RegionSecurityPoliciesClientMeta): """The RegionSecurityPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionSecurityPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/README.rst index bc650e76362b..5310bdd303a6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSecurityPoliciesTransport` is the ABC for all transports. -- public child `RegionSecurityPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSecurityPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSecurityPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSecurityPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSecurityPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionSecurityPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSecurityPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSecurityPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSecurityPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/base.py index 67d0123b9b7e..f6a7ca7cf820 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/rest.py index 3dc9ee912da5..db4be7fba89a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_security_policies/transports/rest.py @@ -702,6 +702,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSecurityPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py index 080afa420889..72da7a7702b9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/client.py @@ -108,7 +108,7 @@ class RegionSslCertificatesClient(metaclass=RegionSslCertificatesClientMeta): """The RegionSslCertificates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionSslCertificatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/README.rst index 54eded552b4b..c9bc987092c7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSslCertificatesTransport` is the ABC for all transports. -- public child `RegionSslCertificatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSslCertificatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSslCertificatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSslCertificatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSslCertificatesTransport`` is the ABC for all transports. + +- public child ``RegionSslCertificatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSslCertificatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSslCertificatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSslCertificatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py index 0d255e2cef7d..7eec252560fb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py index dc64159686b9..6db5fff60ead 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py @@ -370,6 +370,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSslCertificatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py index 574a4a5c7bdb..1067db3d0257 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/client.py @@ -108,7 +108,7 @@ class RegionSslPoliciesClient(metaclass=RegionSslPoliciesClientMeta): """The RegionSslPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = RegionSslPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/README.rst index 807618502323..38caef77a5db 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionSslPoliciesTransport` is the ABC for all transports. -- public child `RegionSslPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionSslPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionSslPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionSslPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionSslPoliciesTransport`` is the ABC for all transports. + +- public child ``RegionSslPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionSslPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionSslPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionSslPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/base.py index 1427e4f38a24..60109a3cfb88 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/rest.py index d1a513149467..e6456193aa99 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_ssl_policies/transports/rest.py @@ -479,6 +479,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionSslPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py index 046235518bf6..b692ef904122 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/client.py @@ -108,7 +108,7 @@ class RegionTargetHttpProxiesClient(metaclass=RegionTargetHttpProxiesClientMeta) """The RegionTargetHttpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionTargetHttpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/README.rst index 23946266929c..4b4a06daf2cf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionTargetHttpProxiesTransport` is the ABC for all transports. -- public child `RegionTargetHttpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionTargetHttpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionTargetHttpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionTargetHttpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionTargetHttpProxiesTransport`` is the ABC for all transports. + +- public child ``RegionTargetHttpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionTargetHttpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionTargetHttpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionTargetHttpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py index 2c4227e60b1a..eb5f84e6c64c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py index 2ec8aae55e17..9fc4da31b236 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py @@ -425,6 +425,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionTargetHttpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py index c6e049e80c5b..f2cbd333085f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/client.py @@ -108,7 +108,7 @@ class RegionTargetHttpsProxiesClient(metaclass=RegionTargetHttpsProxiesClientMet """The RegionTargetHttpsProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = RegionTargetHttpsProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/README.rst index cf57d11919f8..cf8b6e9c5d95 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionTargetHttpsProxiesTransport` is the ABC for all transports. -- public child `RegionTargetHttpsProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionTargetHttpsProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionTargetHttpsProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionTargetHttpsProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionTargetHttpsProxiesTransport`` is the ABC for all transports. + +- public child ``RegionTargetHttpsProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionTargetHttpsProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionTargetHttpsProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionTargetHttpsProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py index 75485c624006..faecc771d371 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py index c98b51f90c78..ca53cad9be0b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py @@ -538,6 +538,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionTargetHttpsProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py index 0d681742e7c5..7fc4363e05cf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/client.py @@ -108,7 +108,7 @@ class RegionTargetTcpProxiesClient(metaclass=RegionTargetTcpProxiesClientMeta): """The RegionTargetTcpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = RegionTargetTcpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/README.rst index 1885a11205b3..ada713b1429e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionTargetTcpProxiesTransport` is the ABC for all transports. -- public child `RegionTargetTcpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionTargetTcpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionTargetTcpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionTargetTcpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionTargetTcpProxiesTransport`` is the ABC for all transports. + +- public child ``RegionTargetTcpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionTargetTcpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionTargetTcpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionTargetTcpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/base.py index 497f9573bc02..8b7bf94337e6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/rest.py index e03428f5c7c3..bdd8dc7face7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_target_tcp_proxies/transports/rest.py @@ -370,6 +370,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionTargetTcpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py index 46e14bce6530..124ee107e116 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/client.py @@ -108,7 +108,7 @@ class RegionUrlMapsClient(metaclass=RegionUrlMapsClientMeta): """The RegionUrlMaps API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RegionUrlMapsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/README.rst index 1720d990b31c..ac5b043653cb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionUrlMapsTransport` is the ABC for all transports. -- public child `RegionUrlMapsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionUrlMapsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionUrlMapsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionUrlMapsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionUrlMapsTransport`` is the ABC for all transports. + +- public child ``RegionUrlMapsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionUrlMapsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionUrlMapsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionUrlMapsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/base.py index 45d10229680c..e20e95ae1381 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/rest.py index c4a6e93f2a72..516c41b59722 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_url_maps/transports/rest.py @@ -529,6 +529,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionUrlMapsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py index 66d6594cf5c7..16fcf3074343 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/client.py @@ -105,7 +105,7 @@ class RegionZonesClient(metaclass=RegionZonesClientMeta): """The RegionZones API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = RegionZonesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/README.rst index a1291ba0f15f..9cdcc421a8f8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionZonesTransport` is the ABC for all transports. -- public child `RegionZonesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionZonesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionZonesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionZonesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionZonesTransport`` is the ABC for all transports. + +- public child ``RegionZonesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionZonesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionZonesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionZonesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/base.py index c9c993fe9c20..0378a550361b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/rest.py index bfb37becadcf..f4adfbc3ce53 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/region_zones/transports/rest.py @@ -201,6 +201,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionZonesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py index f4c601793bb9..a27ea9e4e8e6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/client.py @@ -105,7 +105,7 @@ class RegionsClient(metaclass=RegionsClientMeta): """The Regions API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = RegionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/README.rst index 2dc13d2da1b9..d0dde73d6fe7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RegionsTransport` is the ABC for all transports. -- public child `RegionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RegionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRegionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RegionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RegionsTransport`` is the ABC for all transports. + +- public child ``RegionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RegionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRegionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RegionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/base.py index eaf4bd6add04..ee07983e5dcf 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/rest.py index 6552dfee79e6..f098cf511911 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/regions/transports/rest.py @@ -253,6 +253,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RegionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py index 9335da665867..f82194ba905d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/client.py @@ -108,7 +108,7 @@ class ReservationBlocksClient(metaclass=ReservationBlocksClientMeta): """The ReservationBlocks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ReservationBlocksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/README.rst index ead61ffe03c8..98651b5a7928 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationBlocksTransport` is the ABC for all transports. -- public child `ReservationBlocksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationBlocksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationBlocksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationBlocksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationBlocksTransport`` is the ABC for all transports. + +- public child ``ReservationBlocksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationBlocksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationBlocksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationBlocksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/base.py index a490b66ea7ef..cde8320844e7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/rest.py index ce6d27e01c56..77aafe18692f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_blocks/transports/rest.py @@ -491,6 +491,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationBlocksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py index bd168dcbe21b..7ba65db8b8b3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/client.py @@ -108,7 +108,7 @@ class ReservationSlotsClient(metaclass=ReservationSlotsClientMeta): """The ReservationSlots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ReservationSlotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/README.rst index 3e36921f3fe9..a67caf4b207b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationSlotsTransport` is the ABC for all transports. -- public child `ReservationSlotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationSlotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationSlotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationSlotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationSlotsTransport`` is the ABC for all transports. + +- public child ``ReservationSlotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationSlotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationSlotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationSlotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/base.py index 40f7300ecae8..8c0b956f11ed 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/rest.py index 2fc0ba9ed22b..aff880471062 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_slots/transports/rest.py @@ -374,6 +374,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationSlotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py index 17c8e580f595..b330aa7e5f2b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/client.py @@ -108,7 +108,7 @@ class ReservationSubBlocksClient(metaclass=ReservationSubBlocksClientMeta): """The ReservationSubBlocks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ReservationSubBlocksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/README.rst index 5c23b59d8c44..30d2fda9b293 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationSubBlocksTransport` is the ABC for all transports. -- public child `ReservationSubBlocksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationSubBlocksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationSubBlocksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationSubBlocksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationSubBlocksTransport`` is the ABC for all transports. + +- public child ``ReservationSubBlocksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationSubBlocksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationSubBlocksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationSubBlocksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/base.py index 38140d0e0d68..6c24b31e3c6c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/rest.py index 868dd8f96ed5..5742a78b8223 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservation_sub_blocks/transports/rest.py @@ -602,6 +602,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationSubBlocksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py index bd5b010f7d64..86af910a0f0d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/client.py @@ -108,7 +108,7 @@ class ReservationsClient(metaclass=ReservationsClientMeta): """The Reservations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = ReservationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/README.rst index 26061ab20fdb..09fa3f67538b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReservationsTransport` is the ABC for all transports. -- public child `ReservationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReservationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReservationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReservationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReservationsTransport`` is the ABC for all transports. + +- public child ``ReservationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReservationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReservationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReservationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/base.py index 9333f91ee33a..c34e75e9b9fd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/rest.py index d833f6f669c6..99e611b8de3b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/reservations/transports/rest.py @@ -754,6 +754,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReservationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py index ce704151e64a..4ee30d546df5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/client.py @@ -108,7 +108,7 @@ class ResourcePoliciesClient(metaclass=ResourcePoliciesClientMeta): """The ResourcePolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = ResourcePoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/README.rst index e08e21143072..3ee061bde40b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ResourcePoliciesTransport` is the ABC for all transports. -- public child `ResourcePoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ResourcePoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseResourcePoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ResourcePoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ResourcePoliciesTransport`` is the ABC for all transports. + +- public child ``ResourcePoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ResourcePoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseResourcePoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ResourcePoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/base.py index c4ee6f39cbd0..00a25bd38029 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/rest.py index b02bb91e3d2f..d897c8b00fe5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/resource_policies/transports/rest.py @@ -649,6 +649,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ResourcePoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py index fd133111be9d..e026fdc5de4e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/client.py @@ -108,7 +108,7 @@ class RoutersClient(metaclass=RoutersClientMeta): """The Routers API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RoutersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/README.rst index 1d5f11e98ca6..e826f22dc584 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RoutersTransport` is the ABC for all transports. -- public child `RoutersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RoutersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRoutersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RoutersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RoutersTransport`` is the ABC for all transports. + +- public child ``RoutersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RoutersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRoutersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RoutersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/base.py index 6ac0a02949fc..dac5f85beff1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/rest.py index 595d501f7ead..9f183f0fe2bb 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routers/transports/rest.py @@ -1079,6 +1079,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RoutersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py index c76f307bf572..1f2fc93abb95 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/client.py @@ -108,7 +108,7 @@ class RoutesClient(metaclass=RoutesClientMeta): """The Routes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = RoutesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/README.rst index ece3f327f1db..59b24c7b8607 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RoutesTransport` is the ABC for all transports. -- public child `RoutesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RoutesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRoutesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RoutesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RoutesTransport`` is the ABC for all transports. + +- public child ``RoutesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RoutesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRoutesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RoutesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/base.py index 74b44c34336c..19d1fb9d3c0c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/rest.py index e06ca72f3695..013263636f98 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/routes/transports/rest.py @@ -413,6 +413,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RoutesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py index 66ac255af6a5..3497f817ca0c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/client.py @@ -108,7 +108,7 @@ class SecurityPoliciesClient(metaclass=SecurityPoliciesClientMeta): """The SecurityPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = SecurityPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/README.rst index 0ccd9c25c159..1061ac468325 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SecurityPoliciesTransport` is the ABC for all transports. -- public child `SecurityPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SecurityPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSecurityPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SecurityPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SecurityPoliciesTransport`` is the ABC for all transports. + +- public child ``SecurityPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SecurityPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSecurityPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SecurityPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/base.py index d50fed195dc1..f8e3f415574f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/rest.py index 1d6ef34505b3..f1d4fde5e3e3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/security_policies/transports/rest.py @@ -812,6 +812,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SecurityPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py index ba23f823098e..5621701b39d9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/client.py @@ -108,7 +108,7 @@ class ServiceAttachmentsClient(metaclass=ServiceAttachmentsClientMeta): """The ServiceAttachments API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = ServiceAttachmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/README.rst index 5f7c8c3d83fa..19ad54459a96 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServiceAttachmentsTransport` is the ABC for all transports. -- public child `ServiceAttachmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServiceAttachmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServiceAttachmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServiceAttachmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServiceAttachmentsTransport`` is the ABC for all transports. + +- public child ``ServiceAttachmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServiceAttachmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServiceAttachmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServiceAttachmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/base.py index df2a5ec597f9..456c626eeeb9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/rest.py index e3f8fbc6a49d..0f40ff03af12 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/service_attachments/transports/rest.py @@ -651,6 +651,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ServiceAttachmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py index 63a89a46643b..d34a156504c6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/client.py @@ -107,7 +107,7 @@ class SnapshotSettingsServiceClient(metaclass=SnapshotSettingsServiceClientMeta) """The SnapshotSettings API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -115,7 +115,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -125,6 +125,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -509,7 +513,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = SnapshotSettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/README.rst index 68c71745a361..0a85f1b33870 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnapshotSettingsServiceTransport` is the ABC for all transports. -- public child `SnapshotSettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnapshotSettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnapshotSettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnapshotSettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnapshotSettingsServiceTransport`` is the ABC for all transports. + +- public child ``SnapshotSettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnapshotSettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnapshotSettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnapshotSettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/base.py index 49be42ce4452..35fb80b6bc4f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/rest.py index 9d4b27c86fd8..f7bcb743e5ca 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshot_settings_service/transports/rest.py @@ -257,6 +257,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SnapshotSettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py index 5ad2a4bafe43..e936a4b591c9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/client.py @@ -108,7 +108,7 @@ class SnapshotsClient(metaclass=SnapshotsClientMeta): """The Snapshots API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SnapshotsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/README.rst index b80ab398fdb8..ed5078590d73 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnapshotsTransport` is the ABC for all transports. -- public child `SnapshotsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnapshotsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnapshotsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnapshotsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnapshotsTransport`` is the ABC for all transports. + +- public child ``SnapshotsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnapshotsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnapshotsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnapshotsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/base.py index acf7da137284..533173f97d7e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/rest.py index ec1792a67989..db11ebf78027 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/snapshots/transports/rest.py @@ -578,6 +578,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SnapshotsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py index 30b03bdb311c..6a73fe3443bd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/client.py @@ -108,7 +108,7 @@ class SslCertificatesClient(metaclass=SslCertificatesClientMeta): """The SslCertificates API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = SslCertificatesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/README.rst index adaacba051cd..54488d94eb3c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SslCertificatesTransport` is the ABC for all transports. -- public child `SslCertificatesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SslCertificatesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSslCertificatesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SslCertificatesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SslCertificatesTransport`` is the ABC for all transports. + +- public child ``SslCertificatesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SslCertificatesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSslCertificatesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SslCertificatesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/base.py index d84b5339478b..02582f13e421 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py index 4e3f3fb32cd4..3296568c56a6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py @@ -426,6 +426,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SslCertificatesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py index 53a73f2fe598..5c57970da56a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/client.py @@ -108,7 +108,7 @@ class SslPoliciesClient(metaclass=SslPoliciesClientMeta): """The SslPolicies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SslPoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/README.rst index 90c2c96db3de..c0fe30afaa5b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SslPoliciesTransport` is the ABC for all transports. -- public child `SslPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SslPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSslPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SslPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SslPoliciesTransport`` is the ABC for all transports. + +- public child ``SslPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SslPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSslPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SslPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/base.py index 9d9e52c29f10..ee7d871b714c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/rest.py index 158c35462ee0..fc84975a69c1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/ssl_policies/transports/rest.py @@ -528,6 +528,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SslPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py index 5251193ccfe1..ec81cd2dd123 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/client.py @@ -105,7 +105,7 @@ class StoragePoolTypesClient(metaclass=StoragePoolTypesClientMeta): """The StoragePoolTypes API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -606,7 +610,7 @@ def __init__( self._universe_domain = StoragePoolTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/README.rst index eb123fb58f19..ab99ff687c6b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`StoragePoolTypesTransport` is the ABC for all transports. -- public child `StoragePoolTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `StoragePoolTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseStoragePoolTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `StoragePoolTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``StoragePoolTypesTransport`` is the ABC for all transports. + +- public child ``StoragePoolTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``StoragePoolTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseStoragePoolTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``StoragePoolTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/base.py index 99345ae052fb..cfa09e213147 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/rest.py index 46eb1d60bdef..2d2ccfaeb4b6 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pool_types/transports/rest.py @@ -318,6 +318,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[StoragePoolTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py index 9e9eea8e6aa9..c15fb4900a03 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/client.py @@ -108,7 +108,7 @@ class StoragePoolsClient(metaclass=StoragePoolsClientMeta): """The StoragePools API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = StoragePoolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/README.rst index f0bef4dd7f4e..989226566992 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`StoragePoolsTransport` is the ABC for all transports. -- public child `StoragePoolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `StoragePoolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseStoragePoolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `StoragePoolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``StoragePoolsTransport`` is the ABC for all transports. + +- public child ``StoragePoolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``StoragePoolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseStoragePoolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``StoragePoolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/base.py index 6a959892da1f..40decc3fafc3 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/rest.py index 6a04daa55581..f94aef7c9ae4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/storage_pools/transports/rest.py @@ -699,6 +699,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[StoragePoolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py index 27eb1ab43044..c19979951499 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/client.py @@ -108,7 +108,7 @@ class SubnetworksClient(metaclass=SubnetworksClientMeta): """The Subnetworks API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = SubnetworksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/README.rst index eb4732e3d7f1..bb2d45cfcb5c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SubnetworksTransport` is the ABC for all transports. -- public child `SubnetworksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SubnetworksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSubnetworksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SubnetworksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SubnetworksTransport`` is the ABC for all transports. + +- public child ``SubnetworksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SubnetworksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSubnetworksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SubnetworksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/base.py index 306ecc828969..5480f665a7d0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/rest.py index 9aa810d40132..764b4dd0c601 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/subnetworks/transports/rest.py @@ -811,6 +811,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SubnetworksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py index 6741fe9af107..6022e31f37c7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/client.py @@ -108,7 +108,7 @@ class TargetGrpcProxiesClient(metaclass=TargetGrpcProxiesClientMeta): """The TargetGrpcProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetGrpcProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/README.rst index 52ce0ef73ecc..11862ec53a41 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetGrpcProxiesTransport` is the ABC for all transports. -- public child `TargetGrpcProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetGrpcProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetGrpcProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetGrpcProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetGrpcProxiesTransport`` is the ABC for all transports. + +- public child ``TargetGrpcProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetGrpcProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetGrpcProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetGrpcProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py index 3ac0cac1b64b..ff8f13c79b09 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py index 72b5392fac40..c90357eafbd7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py @@ -421,6 +421,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetGrpcProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py index 969aa46d8963..621c77a66f07 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/client.py @@ -108,7 +108,7 @@ class TargetHttpProxiesClient(metaclass=TargetHttpProxiesClientMeta): """The TargetHttpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetHttpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/README.rst index d7c24090549d..1096201d216a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetHttpProxiesTransport` is the ABC for all transports. -- public child `TargetHttpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetHttpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetHttpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetHttpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetHttpProxiesTransport`` is the ABC for all transports. + +- public child ``TargetHttpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetHttpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetHttpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetHttpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/base.py index 09e0e587ef46..44eb0c227cc0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py index b9d50d3930e8..1b5c7956d098 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetHttpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py index 0eb9acf8bedc..76c432a14e23 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/client.py @@ -108,7 +108,7 @@ class TargetHttpsProxiesClient(metaclass=TargetHttpsProxiesClientMeta): """The TargetHttpsProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetHttpsProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/README.rst index e4a84921dff6..a977b5c1e9d7 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetHttpsProxiesTransport` is the ABC for all transports. -- public child `TargetHttpsProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetHttpsProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetHttpsProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetHttpsProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetHttpsProxiesTransport`` is the ABC for all transports. + +- public child ``TargetHttpsProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetHttpsProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetHttpsProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetHttpsProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/base.py index f280f5fa602c..a7d0fbb823c9 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py index d3ca9f2b0845..8d797748c083 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py @@ -759,6 +759,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetHttpsProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py index f03f5f97885c..65bcec7f7ca2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/client.py @@ -108,7 +108,7 @@ class TargetInstancesClient(metaclass=TargetInstancesClientMeta): """The TargetInstances API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = TargetInstancesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/README.rst index f09666e9ceff..d98f543bdcc0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetInstancesTransport` is the ABC for all transports. -- public child `TargetInstancesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetInstancesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetInstancesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetInstancesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetInstancesTransport`` is the ABC for all transports. + +- public child ``TargetInstancesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetInstancesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetInstancesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetInstancesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/base.py index 97c21f24cdf1..84bcfc54f83e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/rest.py index 956c74cfa222..a4869c67a726 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_instances/transports/rest.py @@ -542,6 +542,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetInstancesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py index d7cc7b392810..03c25e567699 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/client.py @@ -108,7 +108,7 @@ class TargetPoolsClient(metaclass=TargetPoolsClientMeta): """The TargetPools API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = TargetPoolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/README.rst index 661878aeb974..8d69e5b6f1ac 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetPoolsTransport` is the ABC for all transports. -- public child `TargetPoolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetPoolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetPoolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetPoolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetPoolsTransport`` is the ABC for all transports. + +- public child ``TargetPoolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetPoolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetPoolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetPoolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/base.py index 97cac8586530..61c2237722b0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/rest.py index d09add05306a..b0b84ed30f6f 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_pools/transports/rest.py @@ -867,6 +867,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetPoolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py index be8561d63bd0..776e4eae6390 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/client.py @@ -108,7 +108,7 @@ class TargetSslProxiesClient(metaclass=TargetSslProxiesClientMeta): """The TargetSslProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = TargetSslProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/README.rst index c4fd45add5f1..5046d955895e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetSslProxiesTransport` is the ABC for all transports. -- public child `TargetSslProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetSslProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetSslProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetSslProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetSslProxiesTransport`` is the ABC for all transports. + +- public child ``TargetSslProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetSslProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetSslProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetSslProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py index 922dd832957e..689b39085a6b 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py index a60f611ccc45..ced90ae922cd 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py @@ -707,6 +707,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetSslProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py index 71c1d8009e71..0bae20e4e7ab 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/client.py @@ -108,7 +108,7 @@ class TargetTcpProxiesClient(metaclass=TargetTcpProxiesClientMeta): """The TargetTcpProxies API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = TargetTcpProxiesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/README.rst index 3040978bc37f..e7b7b4662228 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetTcpProxiesTransport` is the ABC for all transports. -- public child `TargetTcpProxiesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetTcpProxiesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetTcpProxiesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetTcpProxiesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetTcpProxiesTransport`` is the ABC for all transports. + +- public child ``TargetTcpProxiesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetTcpProxiesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetTcpProxiesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetTcpProxiesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py index bac20c3ec033..e40ca8d8cb0a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py index 688476078e26..807ff6694a53 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py @@ -597,6 +597,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetTcpProxiesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py index 1f10bd1e58c4..a5b5bc1d775e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/client.py @@ -108,7 +108,7 @@ class TargetVpnGatewaysClient(metaclass=TargetVpnGatewaysClientMeta): """The TargetVpnGateways API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TargetVpnGatewaysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/README.rst index 729cd35a377a..3d2a7424b7c0 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TargetVpnGatewaysTransport` is the ABC for all transports. -- public child `TargetVpnGatewaysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TargetVpnGatewaysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTargetVpnGatewaysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TargetVpnGatewaysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TargetVpnGatewaysTransport`` is the ABC for all transports. + +- public child ``TargetVpnGatewaysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TargetVpnGatewaysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTargetVpnGatewaysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TargetVpnGatewaysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py index a7e85e6c4f03..a4d0c3d69419 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py index f7c630802340..227d46b5ccab 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py @@ -481,6 +481,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TargetVpnGatewaysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py index 36406d9b32dc..5abc480aeaf4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/client.py @@ -108,7 +108,7 @@ class UrlMapsClient(metaclass=UrlMapsClientMeta): """The UrlMaps API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = UrlMapsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/README.rst index 03f5dbb958f1..4c9396f6b7b2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UrlMapsTransport` is the ABC for all transports. -- public child `UrlMapsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UrlMapsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUrlMapsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UrlMapsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UrlMapsTransport`` is the ABC for all transports. + +- public child ``UrlMapsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UrlMapsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUrlMapsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UrlMapsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/base.py index 4ea8af1d6b2a..673311002b82 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/rest.py index 68e1e5889801..92a7cc0e952c 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/url_maps/transports/rest.py @@ -685,6 +685,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UrlMapsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py index 7615250629f0..d0bc2931006d 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/client.py @@ -108,7 +108,7 @@ class VpnGatewaysClient(metaclass=VpnGatewaysClientMeta): """The VpnGateways API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = VpnGatewaysClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/README.rst index 1c5d4b400fdb..72c21068bf55 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VpnGatewaysTransport` is the ABC for all transports. -- public child `VpnGatewaysGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VpnGatewaysGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVpnGatewaysRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VpnGatewaysRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VpnGatewaysTransport`` is the ABC for all transports. + +- public child ``VpnGatewaysGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VpnGatewaysGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVpnGatewaysRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VpnGatewaysRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/base.py index 20002bbe7670..b7d651472739 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py index d13bc734e1d4..d0fcbe88fc69 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py @@ -591,6 +591,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VpnGatewaysRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py index 329c90ca9a88..25cb855e3707 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/client.py @@ -108,7 +108,7 @@ class VpnTunnelsClient(metaclass=VpnTunnelsClientMeta): """The VpnTunnels API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = VpnTunnelsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/README.rst index 1bf067e72e57..ca4198c01932 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VpnTunnelsTransport` is the ABC for all transports. -- public child `VpnTunnelsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VpnTunnelsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVpnTunnelsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VpnTunnelsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VpnTunnelsTransport`` is the ABC for all transports. + +- public child ``VpnTunnelsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VpnTunnelsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVpnTunnelsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VpnTunnelsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py index 8db4da007ddc..fe8b5da5ed06 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py index 85a3afda5454..86453910d141 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py @@ -469,6 +469,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VpnTunnelsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py index f1c58fdbae24..6851e3a8e4a2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/client.py @@ -108,7 +108,7 @@ class WireGroupsClient(metaclass=WireGroupsClientMeta): """The WireGroups API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = WireGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/README.rst index e5b31cbf4bec..c32f386d68a2 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WireGroupsTransport` is the ABC for all transports. -- public child `WireGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WireGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWireGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WireGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WireGroupsTransport`` is the ABC for all transports. + +- public child ``WireGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WireGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWireGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WireGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/base.py index 590939a74b32..d1f9b46359f8 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ self._extended_operations_services: Dict[str, Any] = {} @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/rest.py index 4856566087e9..ebae62aff786 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/wire_groups/transports/rest.py @@ -409,6 +409,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WireGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py index 9fa6761b1149..bc05ca89ed8e 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/client.py @@ -105,7 +105,7 @@ class ZoneOperationsClient(metaclass=ZoneOperationsClientMeta): """The ZoneOperations API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = ZoneOperationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/README.rst index eb93acc7255e..fbf08fe656d4 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ZoneOperationsTransport` is the ABC for all transports. -- public child `ZoneOperationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ZoneOperationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseZoneOperationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ZoneOperationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ZoneOperationsTransport`` is the ABC for all transports. + +- public child ``ZoneOperationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ZoneOperationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseZoneOperationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ZoneOperationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/base.py index 90891e2672c0..9387be994e1a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/rest.py index baf01a2c1442..0c45273b3bea 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zone_operations/transports/rest.py @@ -369,6 +369,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ZoneOperationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py index cddbeb60bdce..8b1ded04367a 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/client.py @@ -105,7 +105,7 @@ class ZonesClient(metaclass=ZonesClientMeta): """The Zones API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -113,7 +113,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -123,6 +123,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -408,7 +412,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -505,7 +509,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +608,7 @@ def __init__( self._universe_domain = ZonesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/README.rst b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/README.rst index 6c572dcd2511..6eff58d762a1 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/README.rst +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ZonesTransport` is the ABC for all transports. -- public child `ZonesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ZonesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseZonesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ZonesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ZonesTransport`` is the ABC for all transports. + +- public child ``ZonesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ZonesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseZonesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ZonesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/base.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/base.py index 4fa33e5f4737..ad927e493d96 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/base.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/rest.py b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/rest.py index bc3a0725be75..4b4994ea84b5 100644 --- a/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/rest.py +++ b/packages/google-cloud-compute/google/cloud/compute_v1/services/zones/transports/rest.py @@ -251,6 +251,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ZonesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-compute/noxfile.py b/packages/google-cloud-compute/noxfile.py index 54b28d93a5f0..5f45c32df58b 100644 --- a/packages/google-cloud-compute/noxfile.py +++ b/packages/google-cloud-compute/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-compute/setup.py b/packages/google-cloud-compute/setup.py index 5dc7009a76a1..cac8550333b5 100644 --- a/packages/google-cloud-compute/setup.py +++ b/packages/google-cloud-compute/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-compute" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-compute/testing/constraints-3.7.txt b/packages/google-cloud-compute/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-compute/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-compute/testing/constraints-3.8.txt b/packages/google-cloud-compute/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-compute/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-compute/testing/constraints-3.9.txt b/packages/google-cloud-compute/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-compute/testing/constraints-3.9.txt +++ b/packages/google-cloud-compute/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_accelerator_types.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_accelerator_types.py index 9010cf1a9e92..711473e2b856 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_accelerator_types.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_accelerator_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AcceleratorTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): AcceleratorTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AcceleratorTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2004,8 +2009,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2076,17 +2082,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = AcceleratorTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2146,8 +2155,9 @@ def test_get_rest_bad_request(request_type=compute.GetAcceleratorTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2228,17 +2238,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = AcceleratorTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AcceleratorTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2289,8 +2299,9 @@ def test_list_rest_bad_request(request_type=compute.ListAcceleratorTypesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2359,17 +2370,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = AcceleratorTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AcceleratorTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AcceleratorTypesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2524,11 +2537,14 @@ def test_accelerator_types_base_transport(): def test_accelerator_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AcceleratorTypesTransport( @@ -2549,9 +2565,12 @@ def test_accelerator_types_base_transport_with_credentials_file(): def test_accelerator_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.accelerator_types.transports.AcceleratorTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AcceleratorTypesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_addresses.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_addresses.py index 345a2c74b45d..f79968a11254 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_addresses.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_addresses.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AddressesClient._get_default_mtls_endpoint(None) is None assert AddressesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AddressesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AddressesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3843,8 +3847,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3913,17 +3918,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AddressesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AddressesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3976,8 +3983,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4080,17 +4088,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4139,8 +4145,9 @@ def test_get_rest_bad_request(request_type=compute.GetAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4239,17 +4246,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4298,8 +4303,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4492,17 +4498,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4551,8 +4555,9 @@ def test_list_rest_bad_request(request_type=compute.ListAddressesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4619,17 +4624,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4678,8 +4681,9 @@ def test_move_rest_bad_request(request_type=compute.MoveAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4864,17 +4868,15 @@ def test_move_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AddressesRestInterceptor, "post_move") as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_move_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_move") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4923,8 +4925,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsAddressReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5106,17 +5109,17 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AddressesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.AddressesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AddressesRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5169,8 +5172,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5309,17 +5313,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = AddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AddressesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.AddressesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AddressesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AddressesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.AddressesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AddressesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5581,11 +5588,14 @@ def test_addresses_base_transport(): def test_addresses_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.addresses.transports.AddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.addresses.transports.AddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AddressesTransport( @@ -5605,9 +5615,12 @@ def test_addresses_base_transport_with_credentials_file(): def test_addresses_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.addresses.transports.AddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.addresses.transports.AddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AddressesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_advice.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_advice.py index 2f23ca3cfca2..255007786e89 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_advice.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_advice.py @@ -114,6 +114,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AdviceClient._get_default_mtls_endpoint(None) is None assert AdviceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AdviceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AdviceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1398,8 +1400,9 @@ def test_calendar_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1537,17 +1540,17 @@ def test_calendar_mode_rest_interceptors(null_interceptor): ) client = AdviceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AdviceRestInterceptor, "post_calendar_mode" - ) as post, mock.patch.object( - transports.AdviceRestInterceptor, "post_calendar_mode_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AdviceRestInterceptor, "pre_calendar_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AdviceRestInterceptor, "post_calendar_mode" + ) as post, + mock.patch.object( + transports.AdviceRestInterceptor, "post_calendar_mode_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AdviceRestInterceptor, "pre_calendar_mode") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1658,11 +1661,14 @@ def test_advice_base_transport(): def test_advice_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.advice.transports.AdviceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.advice.transports.AdviceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdviceTransport( @@ -1682,9 +1688,12 @@ def test_advice_base_transport_with_credentials_file(): def test_advice_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.advice.transports.AdviceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.advice.transports.AdviceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AdviceTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_autoscalers.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_autoscalers.py index 003a74949c3b..1059e88f2ffc 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_autoscalers.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_autoscalers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutoscalersClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AutoscalersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AutoscalersClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3862,8 +3866,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3934,17 +3939,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalersRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3997,8 +4004,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4103,17 +4111,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4164,8 +4170,9 @@ def test_get_rest_bad_request(request_type=compute.GetAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4248,17 +4255,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_get") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4307,8 +4312,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4524,17 +4530,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4585,8 +4589,9 @@ def test_list_rest_bad_request(request_type=compute.ListAutoscalersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4655,17 +4660,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_list") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4714,8 +4717,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4931,17 +4935,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4992,8 +4994,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5134,17 +5137,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalersRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5197,8 +5203,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5414,17 +5421,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = AutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.AutoscalersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutoscalersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AutoscalersRestInterceptor, "post_update") as post, + mock.patch.object( + transports.AutoscalersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AutoscalersRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5684,11 +5689,14 @@ def test_autoscalers_base_transport(): def test_autoscalers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoscalersTransport( @@ -5708,9 +5716,12 @@ def test_autoscalers_base_transport_with_credentials_file(): def test_autoscalers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.autoscalers.transports.AutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoscalersTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_buckets.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_buckets.py index a864a8b9ab22..4cd27b01ac5f 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_buckets.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_buckets.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackendBucketsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( BackendBucketsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BackendBucketsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5184,8 +5189,9 @@ def test_add_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5365,18 +5371,20 @@ def test_add_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_add_signed_url_key" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_add_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_add_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_add_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_add_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_add_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5427,8 +5435,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5533,17 +5542,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5596,8 +5607,9 @@ def test_delete_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5702,18 +5714,20 @@ def test_delete_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_delete_signed_url_key" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_delete_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_delete_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_delete_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_delete_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_delete_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5764,8 +5778,9 @@ def test_get_rest_bad_request(request_type=compute.GetBackendBucketRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5850,17 +5865,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.BackendBucketsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendBucketsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5913,8 +5926,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5981,17 +5995,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6042,8 +6059,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6264,17 +6282,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6325,8 +6345,9 @@ def test_list_rest_bad_request(request_type=compute.ListBackendBucketsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6395,17 +6416,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendBucketsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6456,8 +6477,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchBackendBucketRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6678,17 +6700,17 @@ def test_patch_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendBucketsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6741,8 +6763,9 @@ def test_set_edge_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6925,18 +6948,20 @@ def test_set_edge_security_policy_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_set_edge_security_policy" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_set_edge_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_set_edge_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_set_edge_security_policy" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_set_edge_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_set_edge_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6989,8 +7014,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7173,17 +7199,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7236,8 +7265,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7378,18 +7408,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7442,8 +7474,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateBackendBucketRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7664,17 +7697,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = BackendBucketsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.BackendBucketsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendBucketsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendBucketsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8024,11 +8059,14 @@ def test_backend_buckets_base_transport(): def test_backend_buckets_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendBucketsTransport( @@ -8048,9 +8086,12 @@ def test_backend_buckets_base_transport_with_credentials_file(): def test_backend_buckets_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.backend_buckets.transports.BackendBucketsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendBucketsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_services.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_services.py index b7b6dd7b2ac4..b963be850f90 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_services.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_backend_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackendServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( BackendServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BackendServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -6561,8 +6566,9 @@ def test_add_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6742,18 +6748,20 @@ def test_add_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_add_signed_url_key" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_add_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_add_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_add_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_add_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_add_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6806,8 +6814,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6878,17 +6887,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6944,8 +6956,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7050,17 +7063,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7113,8 +7128,9 @@ def test_delete_signed_url_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7219,18 +7235,20 @@ def test_delete_signed_url_key_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_delete_signed_url_key" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_delete_signed_url_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_delete_signed_url_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_delete_signed_url_key" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_delete_signed_url_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_delete_signed_url_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7281,8 +7299,9 @@ def test_get_rest_bad_request(request_type=compute.GetBackendServiceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7408,17 +7427,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendServicesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7471,8 +7490,9 @@ def test_get_effective_security_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7536,19 +7556,22 @@ def test_get_effective_security_policies_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_get_effective_security_policies", - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_get_effective_security_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get_effective_security_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_get_effective_security_policies", + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_get_effective_security_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "pre_get_effective_security_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7608,8 +7631,9 @@ def test_get_health_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7748,17 +7772,19 @@ def test_get_health_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_health" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_health_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get_health" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_health" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_health_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_get_health" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7813,8 +7839,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7881,17 +7908,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7942,8 +7972,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8318,17 +8349,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8379,8 +8412,9 @@ def test_list_rest_bad_request(request_type=compute.ListBackendServicesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8449,17 +8483,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.BackendServicesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8512,8 +8546,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8582,17 +8617,19 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_list_usable_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_list_usable_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8645,8 +8682,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchBackendServiceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9021,17 +9059,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9084,8 +9124,9 @@ def test_set_edge_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9268,18 +9309,20 @@ def test_set_edge_security_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_edge_security_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_set_edge_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_set_edge_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_set_edge_security_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_set_edge_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_set_edge_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9332,8 +9375,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9516,17 +9560,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9579,8 +9626,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9763,18 +9811,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_set_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9827,8 +9877,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9969,18 +10020,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10033,8 +10086,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10409,17 +10463,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = BackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.BackendServicesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackendServicesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.BackendServicesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackendServicesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10878,11 +10934,14 @@ def test_backend_services_base_transport(): def test_backend_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendServicesTransport( @@ -10902,9 +10961,12 @@ def test_backend_services_base_transport_with_credentials_file(): def test_backend_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.backend_services.transports.BackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackendServicesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_cross_site_networks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_cross_site_networks.py index 22de129d0c88..28f56eff2beb 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_cross_site_networks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_cross_site_networks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CrossSiteNetworksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): CrossSiteNetworksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CrossSiteNetworksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2960,8 +2965,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteCrossSiteNetworkRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3066,17 +3072,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3127,8 +3135,9 @@ def test_get_rest_bad_request(request_type=compute.GetCrossSiteNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3201,17 +3210,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3262,8 +3273,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertCrossSiteNetworkRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3449,17 +3461,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3510,8 +3524,9 @@ def test_list_rest_bad_request(request_type=compute.ListCrossSiteNetworksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3584,17 +3599,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3647,8 +3664,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchCrossSiteNetworkReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3834,17 +3852,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = CrossSiteNetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CrossSiteNetworksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CrossSiteNetworksRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4039,11 +4059,14 @@ def test_cross_site_networks_base_transport(): def test_cross_site_networks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CrossSiteNetworksTransport( @@ -4063,9 +4086,12 @@ def test_cross_site_networks_base_transport_with_credentials_file(): def test_cross_site_networks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.cross_site_networks.transports.CrossSiteNetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CrossSiteNetworksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disk_types.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disk_types.py index 25d87b4c5014..946c48450895 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disk_types.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disk_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DiskTypesClient._get_default_mtls_endpoint(None) is None assert DiskTypesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -134,6 +135,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DiskTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DiskTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1952,8 +1956,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2022,17 +2027,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = DiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DiskTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2092,9 @@ def test_get_rest_bad_request(request_type=compute.GetDiskTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2165,17 +2173,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = DiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DiskTypesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DiskTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2224,8 +2230,9 @@ def test_list_rest_bad_request(request_type=compute.ListDiskTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2292,17 +2299,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = DiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.DiskTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DiskTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DiskTypesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.DiskTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DiskTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2453,11 +2458,14 @@ def test_disk_types_base_transport(): def test_disk_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiskTypesTransport( @@ -2478,9 +2486,12 @@ def test_disk_types_base_transport_with_credentials_file(): def test_disk_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.disk_types.transports.DiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DiskTypesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disks.py index 74c9575ac7c8..49a4275658b2 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_disks.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DisksClient._get_default_mtls_endpoint(None) is None assert DisksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DisksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert DisksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -8116,8 +8118,9 @@ def test_add_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8305,17 +8308,19 @@ def test_add_resource_policies_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_add_resource_policies" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_add_resource_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_add_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_add_resource_policies" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_add_resource_policies_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_add_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8368,8 +8373,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8438,17 +8444,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8499,8 +8507,9 @@ def test_bulk_insert_rest_bad_request(request_type=compute.BulkInsertDiskRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8681,17 +8690,15 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_bulk_insert") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_bulk_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8742,8 +8749,9 @@ def test_bulk_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8926,17 +8934,19 @@ def test_bulk_set_labels_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_set_labels" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_bulk_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_bulk_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_bulk_set_labels" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_bulk_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_bulk_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8989,8 +8999,9 @@ def test_create_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9206,17 +9217,19 @@ def test_create_snapshot_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_create_snapshot" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_create_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_create_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_create_snapshot" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_create_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_create_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9267,8 +9280,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9371,17 +9385,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9430,8 +9442,9 @@ def test_get_rest_bad_request(request_type=compute.GetDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9578,17 +9591,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9637,8 +9648,9 @@ def test_get_iam_policy_rest_bad_request(request_type=compute.GetIamPolicyDiskRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9703,17 +9715,17 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_get_iam_policy") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9764,8 +9776,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10001,17 +10014,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10060,8 +10071,9 @@ def test_list_rest_bad_request(request_type=compute.ListDisksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10128,17 +10140,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10189,8 +10199,9 @@ def test_remove_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10378,17 +10389,20 @@ def test_remove_resource_policies_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_remove_resource_policies" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_remove_resource_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_remove_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_remove_resource_policies" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, + "post_remove_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_remove_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10439,8 +10453,9 @@ def test_resize_rest_bad_request(request_type=compute.ResizeDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10617,17 +10632,15 @@ def test_resize_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_resize") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_resize") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10676,8 +10689,9 @@ def test_set_iam_policy_rest_bad_request(request_type=compute.SetIamPolicyDiskRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10858,17 +10872,17 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_set_iam_policy") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10919,8 +10933,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11102,17 +11117,15 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_set_labels") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11163,8 +11176,9 @@ def test_start_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11352,17 +11366,20 @@ def test_start_async_replication_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_start_async_replication" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_start_async_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_start_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_start_async_replication" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, + "post_start_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_start_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11415,8 +11432,9 @@ def test_stop_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11519,17 +11537,19 @@ def test_stop_async_replication_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_stop_async_replication" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_stop_async_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_stop_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_stop_async_replication" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_stop_async_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_stop_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11582,8 +11602,9 @@ def test_stop_group_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11771,18 +11792,20 @@ def test_stop_group_async_replication_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_stop_group_async_replication" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, - "post_stop_group_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_stop_group_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_stop_group_async_replication" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, + "post_stop_group_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_stop_group_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11835,8 +11858,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11975,17 +11999,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DisksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DisksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12038,8 +12064,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12275,17 +12302,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = DisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DisksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.DisksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DisksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DisksRestInterceptor, "post_update") as post, + mock.patch.object( + transports.DisksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DisksRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12784,11 +12809,14 @@ def test_disks_base_transport(): def test_disks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.disks.transports.DisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.disks.transports.DisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DisksTransport( @@ -12808,9 +12836,12 @@ def test_disks_base_transport_with_credentials_file(): def test_disks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.disks.transports.DisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.disks.transports.DisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DisksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py index 47fb565a3c3d..b0432917b9f5 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ExternalVpnGatewaysClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ExternalVpnGatewaysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ExternalVpnGatewaysClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3132,8 +3137,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteExternalVpnGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3238,17 +3244,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3299,8 +3307,9 @@ def test_get_rest_bad_request(request_type=compute.GetExternalVpnGatewayRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3377,17 +3386,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3438,8 +3449,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertExternalVpnGatewayRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3638,17 +3650,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3699,8 +3713,9 @@ def test_list_rest_bad_request(request_type=compute.ListExternalVpnGatewaysReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3771,17 +3786,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3836,8 +3853,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4021,17 +4039,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4084,8 +4105,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4226,18 +4248,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ExternalVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ExternalVpnGatewaysRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExternalVpnGatewaysRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4457,11 +4481,14 @@ def test_external_vpn_gateways_base_transport(): def test_external_vpn_gateways_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExternalVpnGatewaysTransport( @@ -4481,9 +4508,12 @@ def test_external_vpn_gateways_base_transport_with_credentials_file(): def test_external_vpn_gateways_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.external_vpn_gateways.transports.ExternalVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExternalVpnGatewaysTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewall_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewall_policies.py index 10e8b5747d3c..bab66ab12348 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewall_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewall_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirewallPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): FirewallPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FirewallPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -6579,8 +6584,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6769,17 +6775,20 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_association_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_association" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_add_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6830,8 +6839,9 @@ def test_add_rule_rest_bad_request(request_type=compute.AddRuleFirewallPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7069,17 +7079,19 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_add_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7132,8 +7144,9 @@ def test_clone_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7238,17 +7251,19 @@ def test_clone_rules_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_clone_rules" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_clone_rules_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_clone_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_clone_rules" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_clone_rules_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_clone_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7299,8 +7314,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteFirewallPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7405,17 +7421,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7466,8 +7484,9 @@ def test_get_rest_bad_request(request_type=compute.GetFirewallPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7556,17 +7575,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallPoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7619,8 +7638,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7691,17 +7711,20 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_association_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_association" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7756,8 +7779,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7824,17 +7848,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7885,8 +7912,9 @@ def test_get_rule_rest_bad_request(request_type=compute.GetRuleFirewallPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7973,17 +8001,19 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_get_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8034,8 +8064,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertFirewallPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8306,17 +8337,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8367,8 +8400,9 @@ def test_list_rest_bad_request(request_type=compute.ListFirewallPoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8435,17 +8469,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8498,8 +8534,9 @@ def test_list_associations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8562,18 +8599,20 @@ def test_list_associations_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_list_associations" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_list_associations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_list_associations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_list_associations" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_list_associations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_list_associations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8629,8 +8668,9 @@ def test_move_rest_bad_request(request_type=compute.MoveFirewallPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8735,17 +8775,19 @@ def test_move_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_move" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_move_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_move" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8796,8 +8838,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchFirewallPolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9068,17 +9111,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9131,8 +9176,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9370,17 +9416,19 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_patch_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_patch_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9433,8 +9481,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9539,18 +9588,20 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_association" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_remove_association" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_remove_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9603,8 +9654,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9709,17 +9761,19 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_remove_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_remove_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9772,8 +9826,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9963,17 +10018,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10026,8 +10084,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10168,18 +10227,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = FirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirewallPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallPoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10655,11 +10716,14 @@ def test_firewall_policies_base_transport(): def test_firewall_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallPoliciesTransport( @@ -10679,9 +10743,12 @@ def test_firewall_policies_base_transport_with_credentials_file(): def test_firewall_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.firewall_policies.transports.FirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewalls.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewalls.py index 4caf656a584b..f8eeff97dd11 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewalls.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_firewalls.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirewallsClient._get_default_mtls_endpoint(None) is None assert FirewallsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FirewallsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FirewallsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3461,8 +3465,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3565,17 +3570,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3624,8 +3627,9 @@ def test_get_rest_bad_request(request_type=compute.GetFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3716,17 +3720,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3775,8 +3777,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3987,17 +3990,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4046,8 +4047,9 @@ def test_list_rest_bad_request(request_type=compute.ListFirewallsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4114,17 +4116,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4173,8 +4173,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4385,17 +4386,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4446,8 +4445,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4586,17 +4586,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.FirewallsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirewallsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4649,8 +4652,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateFirewallRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4861,17 +4865,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = FirewallsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirewallsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.FirewallsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirewallsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirewallsRestInterceptor, "post_update") as post, + mock.patch.object( + transports.FirewallsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirewallsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5108,11 +5110,14 @@ def test_firewalls_base_transport(): def test_firewalls_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallsTransport( @@ -5132,9 +5137,12 @@ def test_firewalls_base_transport_with_credentials_file(): def test_firewalls_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.firewalls.transports.FirewallsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirewallsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_forwarding_rules.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_forwarding_rules.py index ed4faaa535e9..ee798bbe2b36 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_forwarding_rules.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_forwarding_rules.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ForwardingRulesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( ForwardingRulesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ForwardingRulesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4118,8 +4123,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4190,17 +4196,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4260,8 +4269,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteForwardingRuleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4370,17 +4380,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4435,8 +4447,9 @@ def test_get_rest_bad_request(request_type=compute.GetForwardingRuleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4578,17 +4591,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ForwardingRulesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4639,8 +4652,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertForwardingRuleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4867,17 +4881,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4928,8 +4944,9 @@ def test_list_rest_bad_request(request_type=compute.ListForwardingRulesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4998,17 +5015,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ForwardingRulesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5063,8 +5080,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchForwardingRuleRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5295,17 +5313,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5358,8 +5378,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5543,17 +5564,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5610,8 +5633,9 @@ def test_set_target_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5794,17 +5818,19 @@ def test_set_target_rest_interceptors(null_interceptor): ) client = ForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_target" - ) as post, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "post_set_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ForwardingRulesRestInterceptor, "pre_set_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_target" + ) as post, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "post_set_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ForwardingRulesRestInterceptor, "pre_set_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6062,11 +6088,14 @@ def test_forwarding_rules_base_transport(): def test_forwarding_rules_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ForwardingRulesTransport( @@ -6086,9 +6115,12 @@ def test_forwarding_rules_base_transport_with_credentials_file(): def test_forwarding_rules_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.forwarding_rules.transports.ForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ForwardingRulesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_future_reservations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_future_reservations.py index 672560f443c5..fb38e9b35fdb 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_future_reservations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_future_reservations.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FutureReservationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): FutureReservationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FutureReservationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3789,8 +3794,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3863,18 +3869,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3934,8 +3942,9 @@ def test_cancel_rest_bad_request(request_type=compute.CancelFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4044,17 +4053,19 @@ def test_cancel_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_cancel" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_cancel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_cancel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_cancel" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_cancel_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_cancel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4109,8 +4120,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4219,17 +4231,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4284,8 +4298,9 @@ def test_get_rest_bad_request(request_type=compute.GetFutureReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4389,17 +4404,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4450,8 +4467,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4719,17 +4737,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4780,8 +4800,9 @@ def test_list_rest_bad_request(request_type=compute.ListFutureReservationsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4854,17 +4875,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4924,8 +4947,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateFutureReservationReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5197,17 +5221,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = FutureReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.FutureReservationsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FutureReservationsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FutureReservationsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5444,11 +5470,14 @@ def test_future_reservations_base_transport(): def test_future_reservations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FutureReservationsTransport( @@ -5468,9 +5497,12 @@ def test_future_reservations_base_transport_with_credentials_file(): def test_future_reservations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.future_reservations.transports.FutureReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FutureReservationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_addresses.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_addresses.py index cd80d727b951..8f1b678abc70 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_addresses.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_addresses.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalAddressesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( GlobalAddressesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalAddressesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3500,8 +3505,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteGlobalAddressRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3606,17 +3612,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3667,8 +3675,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3769,17 +3778,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalAddressesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3830,8 +3839,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertGlobalAddressRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4026,17 +4036,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4087,8 +4099,9 @@ def test_list_rest_bad_request(request_type=compute.ListGlobalAddressesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4157,17 +4170,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalAddressesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4218,8 +4231,9 @@ def test_move_rest_bad_request(request_type=compute.MoveGlobalAddressRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4406,17 +4420,17 @@ def test_move_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_move_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_move" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_move_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalAddressesRestInterceptor, "pre_move") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4469,8 +4483,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4654,17 +4669,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4717,8 +4734,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4859,18 +4877,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = GlobalAddressesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.GlobalAddressesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalAddressesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalAddressesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5111,11 +5131,14 @@ def test_global_addresses_base_transport(): def test_global_addresses_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalAddressesTransport( @@ -5135,9 +5158,12 @@ def test_global_addresses_base_transport_with_credentials_file(): def test_global_addresses_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.global_addresses.transports.GlobalAddressesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalAddressesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py index 304937642067..619db1a23725 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalForwardingRulesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): GlobalForwardingRulesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalForwardingRulesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3750,8 +3755,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3856,17 +3862,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3917,8 +3925,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalForwardingRuleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4056,17 +4065,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4119,8 +4130,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4347,17 +4359,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4408,8 +4422,9 @@ def test_list_rest_bad_request(request_type=compute.ListGlobalForwardingRulesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4478,17 +4493,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4539,8 +4556,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchGlobalForwardingRuleRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4767,17 +4785,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4830,8 +4850,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5015,17 +5036,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5078,8 +5102,9 @@ def test_set_target_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5258,17 +5283,20 @@ def test_set_target_rest_interceptors(null_interceptor): ) client = GlobalForwardingRulesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_target" - ) as post, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "post_set_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalForwardingRulesRestInterceptor, "pre_set_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "post_set_target" + ) as post, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, + "post_set_target_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalForwardingRulesRestInterceptor, "pre_set_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5505,11 +5533,14 @@ def test_global_forwarding_rules_base_transport(): def test_global_forwarding_rules_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalForwardingRulesTransport( @@ -5529,9 +5560,12 @@ def test_global_forwarding_rules_base_transport_with_credentials_file(): def test_global_forwarding_rules_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.global_forwarding_rules.transports.GlobalForwardingRulesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalForwardingRulesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py index 4ebf16a75d33..b2c1dd7ef608 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalNetworkEndpointGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): GlobalNetworkEndpointGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalNetworkEndpointGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3712,8 +3717,9 @@ def test_attach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3915,20 +3921,22 @@ def test_attach_network_endpoints_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints", - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "pre_attach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints", + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "pre_attach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3981,8 +3989,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4087,18 +4096,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4151,8 +4162,9 @@ def test_detach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4354,20 +4366,22 @@ def test_detach_network_endpoints_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints", - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "pre_detach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints", + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "pre_detach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4420,8 +4434,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4510,17 +4525,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4575,8 +4593,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4790,18 +4809,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4854,8 +4875,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4924,17 +4946,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4989,8 +5014,9 @@ def test_list_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5059,20 +5085,22 @@ def test_list_network_endpoints_rest_interceptors(null_interceptor): ) client = GlobalNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints", - ) as post, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalNetworkEndpointGroupsRestInterceptor, - "pre_list_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints", + ) as post, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalNetworkEndpointGroupsRestInterceptor, + "pre_list_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5320,11 +5348,14 @@ def test_global_network_endpoint_groups_base_transport(): def test_global_network_endpoint_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalNetworkEndpointGroupsTransport( @@ -5344,9 +5375,12 @@ def test_global_network_endpoint_groups_base_transport_with_credentials_file(): def test_global_network_endpoint_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.global_network_endpoint_groups.transports.GlobalNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalNetworkEndpointGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_operations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_operations.py index 5b3e13f51909..a2fc91807588 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_operations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): GlobalOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2357,8 +2362,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2429,17 +2435,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2492,8 +2501,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteGlobalOperationReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2553,17 +2563,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2619,8 +2631,9 @@ def test_get_rest_bad_request(request_type=compute.GetGlobalOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2725,17 +2738,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GlobalOperationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2786,8 +2799,9 @@ def test_list_rest_bad_request(request_type=compute.ListGlobalOperationsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2856,17 +2870,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2917,8 +2933,9 @@ def test_wait_rest_bad_request(request_type=compute.WaitGlobalOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3023,17 +3040,19 @@ def test_wait_rest_interceptors(null_interceptor): ) client = GlobalOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_wait" - ) as post, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "post_wait_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOperationsRestInterceptor, "pre_wait" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_wait" + ) as post, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "post_wait_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOperationsRestInterceptor, "pre_wait" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3228,11 +3247,14 @@ def test_global_operations_base_transport(): def test_global_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOperationsTransport( @@ -3252,9 +3274,12 @@ def test_global_operations_base_transport_with_credentials_file(): def test_global_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.global_operations.transports.GlobalOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOperationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_organization_operations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_organization_operations.py index ac6603ea03da..f1884db2b801 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_organization_operations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_organization_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalOrganizationOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): GlobalOrganizationOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalOrganizationOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1784,8 +1789,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1847,18 +1853,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalOrganizationOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1916,8 +1924,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2022,17 +2031,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalOrganizationOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2097,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2155,18 +2168,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalOrganizationOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalOrganizationOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalOrganizationOperationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2319,11 +2334,14 @@ def test_global_organization_operations_base_transport(): def test_global_organization_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOrganizationOperationsTransport( @@ -2343,9 +2361,12 @@ def test_global_organization_operations_base_transport_with_credentials_file(): def test_global_organization_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.global_organization_operations.transports.GlobalOrganizationOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalOrganizationOperationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py index 8f12f899a1a2..f083036e6a6f 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GlobalPublicDelegatedPrefixesClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): GlobalPublicDelegatedPrefixesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GlobalPublicDelegatedPrefixesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2994,8 +2999,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3100,18 +3106,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3164,8 +3172,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3260,18 +3269,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3326,8 +3337,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3541,18 +3553,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3605,8 +3619,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3675,18 +3690,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3741,8 +3758,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3956,18 +3974,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = GlobalPublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GlobalPublicDelegatedPrefixesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4162,11 +4182,14 @@ def test_global_public_delegated_prefixes_base_transport(): def test_global_public_delegated_prefixes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalPublicDelegatedPrefixesTransport( @@ -4186,9 +4209,12 @@ def test_global_public_delegated_prefixes_base_transport_with_credentials_file() def test_global_public_delegated_prefixes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.global_public_delegated_prefixes.transports.GlobalPublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GlobalPublicDelegatedPrefixesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_health_checks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_health_checks.py index daea6ee6d650..57d35e1619ee 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_health_checks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_health_checks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert HealthChecksClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert HealthChecksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + HealthChecksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3735,8 +3740,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3807,17 +3813,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.HealthChecksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3870,8 +3878,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3976,17 +3985,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4037,8 +4046,9 @@ def test_get_rest_bad_request(request_type=compute.GetHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4125,17 +4135,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.HealthChecksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4184,8 +4192,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4429,17 +4438,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4490,8 +4499,9 @@ def test_list_rest_bad_request(request_type=compute.ListHealthChecksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4560,17 +4570,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.HealthChecksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4621,8 +4629,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,17 +4875,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.HealthChecksRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4929,8 +4936,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5071,18 +5079,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HealthChecksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5135,8 +5145,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5380,17 +5391,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = HealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.HealthChecksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HealthChecksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.HealthChecksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.HealthChecksRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5650,11 +5661,14 @@ def test_health_checks_base_transport(): def test_health_checks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HealthChecksTransport( @@ -5674,9 +5688,12 @@ def test_health_checks_base_transport_with_credentials_file(): def test_health_checks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.health_checks.transports.HealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HealthChecksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_image_family_views.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_image_family_views.py index ebba14684dc1..eef955a50d1a 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_image_family_views.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_image_family_views.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ImageFamilyViewsClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): ImageFamilyViewsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ImageFamilyViewsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1450,8 +1455,9 @@ def test_get_rest_bad_request(request_type=compute.GetImageFamilyViewRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1511,17 +1517,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ImageFamilyViewsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImageFamilyViewsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ImageFamilyViewsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImageFamilyViewsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImageFamilyViewsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ImageFamilyViewsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImageFamilyViewsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1630,11 +1636,14 @@ def test_image_family_views_base_transport(): def test_image_family_views_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageFamilyViewsTransport( @@ -1655,9 +1664,12 @@ def test_image_family_views_base_transport_with_credentials_file(): def test_image_family_views_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.image_family_views.transports.ImageFamilyViewsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImageFamilyViewsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_images.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_images.py index 287f364a2399..63e5e2471cf4 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_images.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_images.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ImagesClient._get_default_mtls_endpoint(None) is None assert ImagesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ImagesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ImagesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -4439,8 +4441,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4543,17 +4546,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4602,8 +4603,9 @@ def test_deprecate_rest_bad_request(request_type=compute.DeprecateImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4786,17 +4788,15 @@ def test_deprecate_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_deprecate" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_deprecate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_deprecate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_deprecate") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_deprecate_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_deprecate") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4845,8 +4845,9 @@ def test_get_rest_bad_request(request_type=compute.GetImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4955,17 +4956,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5016,8 +5015,9 @@ def test_get_from_family_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5126,17 +5126,19 @@ def test_get_from_family_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_from_family" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_from_family_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_get_from_family" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_from_family" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_from_family_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_get_from_family" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5187,8 +5189,9 @@ def test_get_iam_policy_rest_bad_request(request_type=compute.GetIamPolicyImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5253,17 +5256,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5314,8 +5319,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5543,17 +5549,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5602,8 +5606,9 @@ def test_list_rest_bad_request(request_type=compute.ListImagesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5670,17 +5675,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5729,8 +5732,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5958,17 +5962,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6017,8 +6019,9 @@ def test_set_iam_policy_rest_bad_request(request_type=compute.SetIamPolicyImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6199,17 +6202,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6260,8 +6265,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsImageRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6443,17 +6449,15 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ImagesRestInterceptor, "post_set_labels") as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ImagesRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6504,8 +6508,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6644,17 +6649,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ImagesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ImagesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ImagesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ImagesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ImagesRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ImagesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6979,11 +6986,14 @@ def test_images_base_transport(): def test_images_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.images.transports.ImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.images.transports.ImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImagesTransport( @@ -7003,9 +7013,12 @@ def test_images_base_transport_with_credentials_file(): def test_images_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.images.transports.ImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.images.transports.ImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ImagesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_manager_resize_requests.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_manager_resize_requests.py index 2ff9b6503a58..83b1706a529d 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_manager_resize_requests.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_manager_resize_requests.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( InstanceGroupManagerResizeRequestsClient._get_default_mtls_endpoint(None) @@ -155,6 +156,12 @@ def test__get_default_mtls_endpoint(): ) == non_googleapi ) + assert ( + InstanceGroupManagerResizeRequestsClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3161,8 +3168,9 @@ def test_cancel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3272,18 +3280,20 @@ def test_cancel_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_cancel" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_cancel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_cancel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_cancel" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_cancel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_cancel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3341,8 +3351,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3452,18 +3463,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3521,8 +3534,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3608,18 +3622,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3681,8 +3697,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3927,18 +3944,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3995,8 +4014,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4071,18 +4091,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceGroupManagerResizeRequestsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagerResizeRequestsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4282,11 +4304,14 @@ def test_instance_group_manager_resize_requests_base_transport(): def test_instance_group_manager_resize_requests_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagerResizeRequestsTransport( @@ -4306,9 +4331,12 @@ def test_instance_group_manager_resize_requests_base_transport_with_credentials_ def test_instance_group_manager_resize_requests_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instance_group_manager_resize_requests.transports.InstanceGroupManagerResizeRequestsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagerResizeRequestsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_managers.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_managers.py index c49d44797c8f..43af0e917d14 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_managers.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_group_managers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceGroupManagersClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InstanceGroupManagersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceGroupManagersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -10856,8 +10861,9 @@ def test_abandon_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11051,18 +11057,20 @@ def test_abandon_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_abandon_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_abandon_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_abandon_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_abandon_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_abandon_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_abandon_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11115,8 +11123,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11187,18 +11196,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11260,8 +11271,9 @@ def test_apply_updates_to_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11458,20 +11470,22 @@ def test_apply_updates_to_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_apply_updates_to_instances", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_apply_updates_to_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11528,8 +11542,9 @@ def test_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11735,18 +11750,20 @@ def test_create_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_create_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_create_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_create_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11803,8 +11820,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11913,17 +11931,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11980,8 +12000,9 @@ def test_delete_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12176,18 +12197,20 @@ def test_delete_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_delete_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_delete_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_delete_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_delete_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_delete_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_delete_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12244,8 +12267,9 @@ def test_delete_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12441,20 +12465,22 @@ def test_delete_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_delete_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_delete_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12509,8 +12535,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceGroupManagerReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12616,17 +12643,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12681,8 +12710,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12999,17 +13029,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13060,8 +13092,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstanceGroupManagersReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13130,17 +13163,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13199,8 +13234,9 @@ def test_list_errors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13267,18 +13303,20 @@ def test_list_errors_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list_errors" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_errors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list_errors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_list_errors" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_errors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_list_errors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13340,8 +13378,9 @@ def test_list_managed_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13410,18 +13449,22 @@ def test_list_managed_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_list_managed_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_managed_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list_managed_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_managed_instances", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_managed_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_list_managed_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13485,8 +13528,9 @@ def test_list_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13555,19 +13599,22 @@ def test_list_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_list_per_instance_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_list_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13627,8 +13674,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInstanceGroupManagerRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13949,17 +13997,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14016,8 +14066,9 @@ def test_patch_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14223,20 +14274,22 @@ def test_patch_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_patch_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_patch_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14293,8 +14346,9 @@ def test_recreate_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14488,18 +14542,20 @@ def test_recreate_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_recreate_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_recreate_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_recreate_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_recreate_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_recreate_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_recreate_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14556,8 +14612,9 @@ def test_resize_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14666,17 +14723,19 @@ def test_resize_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resize" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_resize" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14733,8 +14792,9 @@ def test_resume_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14928,18 +14988,20 @@ def test_resume_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_resume_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_resume_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_resume_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_resume_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_resume_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_resume_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14996,8 +15058,9 @@ def test_set_instance_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15191,18 +15254,21 @@ def test_set_instance_template_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_set_instance_template" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_set_instance_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_set_instance_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_instance_template", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_instance_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_set_instance_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15259,8 +15325,9 @@ def test_set_target_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15455,18 +15522,20 @@ def test_set_target_pools_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_set_target_pools" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_set_target_pools_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_set_target_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_set_target_pools" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_set_target_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_set_target_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15523,8 +15592,9 @@ def test_start_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15718,18 +15788,20 @@ def test_start_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_start_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_start_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_start_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_start_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_start_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_start_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15786,8 +15858,9 @@ def test_stop_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15982,18 +16055,20 @@ def test_stop_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_stop_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_stop_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_stop_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_stop_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_stop_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_stop_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16050,8 +16125,9 @@ def test_suspend_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16246,18 +16322,20 @@ def test_suspend_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "post_suspend_instances" - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_suspend_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, "pre_suspend_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "post_suspend_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_suspend_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, "pre_suspend_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16314,8 +16392,9 @@ def test_update_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16523,20 +16602,22 @@ def test_update_per_instance_configs_rest_interceptors(null_interceptor): ) client = InstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs", - ) as post, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupManagersRestInterceptor, - "pre_update_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs", + ) as post, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupManagersRestInterceptor, + "pre_update_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17150,11 +17231,14 @@ def test_instance_group_managers_base_transport(): def test_instance_group_managers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagersTransport( @@ -17174,9 +17258,12 @@ def test_instance_group_managers_base_transport_with_credentials_file(): def test_instance_group_managers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instance_group_managers.transports.InstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupManagersTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_groups.py index 2b2f1ddb8d72..1f3c2be532c3 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( InstanceGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4638,8 +4643,9 @@ def test_add_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4833,17 +4839,19 @@ def test_add_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_add_instances" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_add_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_add_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_add_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_add_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_add_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4896,8 +4904,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4968,17 +4977,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5038,8 +5050,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstanceGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5148,17 +5161,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5213,8 +5228,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5303,17 +5319,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstanceGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstanceGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5364,8 +5378,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstanceGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5556,17 +5571,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5617,8 +5634,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstanceGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5687,17 +5705,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstanceGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5754,8 +5772,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5913,17 +5932,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5985,8 +6007,9 @@ def test_remove_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6180,17 +6203,20 @@ def test_remove_instances_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_remove_instances" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_remove_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_remove_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_remove_instances" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_remove_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_remove_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6247,8 +6273,9 @@ def test_set_named_ports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6443,17 +6470,20 @@ def test_set_named_ports_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_set_named_ports" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_set_named_ports_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_set_named_ports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_set_named_ports" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_set_named_ports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_set_named_ports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6506,8 +6536,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6648,18 +6679,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstanceGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6963,11 +6996,14 @@ def test_instance_groups_base_transport(): def test_instance_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupsTransport( @@ -6987,9 +7023,12 @@ def test_instance_groups_base_transport_with_credentials_file(): def test_instance_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instance_groups.transports.InstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_settings_service.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_settings_service.py index f1f73cf1b824..1aba412c73a7 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_settings_service.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_settings_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceSettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): InstanceSettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceSettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1903,8 +1908,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1971,17 +1977,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2032,8 +2040,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInstanceSettingRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2217,17 +2226,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InstanceSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceSettingsServiceRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceSettingsServiceRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2359,11 +2371,14 @@ def test_instance_settings_service_base_transport(): def test_instance_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceSettingsServiceTransport( @@ -2383,9 +2398,12 @@ def test_instance_settings_service_base_transport_with_credentials_file(): def test_instance_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instance_settings_service.transports.InstanceSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceSettingsServiceTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_templates.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_templates.py index fd887d4d9eb3..fd1d0dd27dbd 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_templates.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instance_templates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstanceTemplatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InstanceTemplatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstanceTemplatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3384,8 +3389,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3454,18 +3460,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3521,8 +3529,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstanceTemplateRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3627,17 +3636,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3688,8 +3699,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceTemplateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3766,17 +3778,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3829,8 +3843,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3897,17 +3912,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3958,8 +3976,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstanceTemplateRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4344,17 +4363,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4405,8 +4426,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstanceTemplatesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4475,17 +4497,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4540,8 +4564,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4724,17 +4749,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4787,8 +4815,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4929,18 +4958,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstanceTemplatesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstanceTemplatesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5202,11 +5233,14 @@ def test_instance_templates_base_transport(): def test_instance_templates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceTemplatesTransport( @@ -5226,9 +5260,12 @@ def test_instance_templates_base_transport_with_credentials_file(): def test_instance_templates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instance_templates.transports.InstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceTemplatesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instances.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instances.py index 9de72c1263c6..255a71a8a812 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instances.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instances.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstancesClient._get_default_mtls_endpoint(None) is None assert InstancesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert InstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + InstancesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -21174,8 +21178,9 @@ def test_add_access_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21361,17 +21366,19 @@ def test_add_access_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_access_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_access_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_add_access_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_access_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_access_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_add_access_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21424,8 +21431,9 @@ def test_add_network_interface_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21641,17 +21649,20 @@ def test_add_network_interface_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_network_interface" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_network_interface_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_add_network_interface" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_network_interface" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_add_network_interface_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_add_network_interface" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21704,8 +21715,9 @@ def test_add_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21893,17 +21905,20 @@ def test_add_resource_policies_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_resource_policies" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_add_resource_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_add_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_add_resource_policies" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_add_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_add_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21956,8 +21971,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22026,17 +22042,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22089,8 +22107,9 @@ def test_attach_disk_rest_bad_request(request_type=compute.AttachDiskInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22316,17 +22335,19 @@ def test_attach_disk_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_attach_disk" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_attach_disk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_attach_disk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_attach_disk" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_attach_disk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_attach_disk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22377,8 +22398,9 @@ def test_bulk_insert_rest_bad_request(request_type=compute.BulkInsertInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22759,17 +22781,19 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_bulk_insert" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_bulk_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22820,8 +22844,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22924,17 +22949,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22985,8 +23008,9 @@ def test_delete_access_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23089,17 +23113,20 @@ def test_delete_access_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_access_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_access_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete_access_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_access_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_delete_access_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_delete_access_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23152,8 +23179,9 @@ def test_delete_network_interface_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23256,18 +23284,20 @@ def test_delete_network_interface_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_delete_network_interface" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_delete_network_interface_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_delete_network_interface" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_delete_network_interface" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_delete_network_interface_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_delete_network_interface" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23318,8 +23348,9 @@ def test_detach_disk_rest_bad_request(request_type=compute.DetachDiskInstanceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23422,17 +23453,19 @@ def test_detach_disk_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_detach_disk" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_detach_disk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_detach_disk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_detach_disk" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_detach_disk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_detach_disk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23483,8 +23516,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23597,17 +23631,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23658,8 +23690,9 @@ def test_get_effective_firewalls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23717,18 +23750,20 @@ def test_get_effective_firewalls_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_effective_firewalls" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_get_effective_firewalls_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_effective_firewalls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_effective_firewalls" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_effective_firewalls_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_effective_firewalls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23786,8 +23821,9 @@ def test_get_guest_attributes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23856,17 +23892,20 @@ def test_get_guest_attributes_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_guest_attributes" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_guest_attributes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_guest_attributes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_guest_attributes" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_guest_attributes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_guest_attributes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23919,8 +23958,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23985,17 +24025,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24048,8 +24090,9 @@ def test_get_screenshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24112,17 +24155,19 @@ def test_get_screenshot_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_screenshot" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_screenshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_screenshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_screenshot" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_screenshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_screenshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24175,8 +24220,9 @@ def test_get_serial_port_output_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24245,17 +24291,20 @@ def test_get_serial_port_output_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_serial_port_output" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_serial_port_output_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_serial_port_output" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_serial_port_output" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_serial_port_output_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_serial_port_output" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24308,8 +24357,9 @@ def test_get_shielded_instance_identity_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24370,18 +24420,20 @@ def test_get_shielded_instance_identity_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_get_shielded_instance_identity" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_get_shielded_instance_identity_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_get_shielded_instance_identity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_get_shielded_instance_identity" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_get_shielded_instance_identity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_get_shielded_instance_identity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24434,8 +24486,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24847,17 +24900,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24906,8 +24957,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstancesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24974,17 +25026,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25035,8 +25085,9 @@ def test_list_referrers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25103,17 +25154,19 @@ def test_list_referrers_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_referrers" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_list_referrers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_list_referrers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_referrers" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_list_referrers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_list_referrers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25168,8 +25221,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25272,17 +25326,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_perform_maintenance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25335,8 +25392,9 @@ def test_remove_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25524,18 +25582,20 @@ def test_remove_resource_policies_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_remove_resource_policies" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_remove_resource_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_remove_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_remove_resource_policies" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_remove_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_remove_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25588,8 +25648,9 @@ def test_report_host_as_faulty_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25780,17 +25841,20 @@ def test_report_host_as_faulty_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_report_host_as_faulty" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_report_host_as_faulty_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_report_host_as_faulty" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_report_host_as_faulty" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_report_host_as_faulty_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_report_host_as_faulty" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25841,8 +25905,9 @@ def test_reset_rest_bad_request(request_type=compute.ResetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25945,17 +26010,15 @@ def test_reset_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_reset" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_reset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_reset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_reset") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_reset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_reset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26004,8 +26067,9 @@ def test_resume_rest_bad_request(request_type=compute.ResumeInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26108,17 +26172,15 @@ def test_resume_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_resume" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_resume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_resume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_resume") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_resume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_resume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26169,8 +26231,9 @@ def test_send_diagnostic_interrupt_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26228,18 +26291,20 @@ def test_send_diagnostic_interrupt_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_send_diagnostic_interrupt" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_send_diagnostic_interrupt_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_send_diagnostic_interrupt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_send_diagnostic_interrupt" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_send_diagnostic_interrupt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_send_diagnostic_interrupt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26297,8 +26362,9 @@ def test_set_deletion_protection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26401,18 +26467,20 @@ def test_set_deletion_protection_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_deletion_protection" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_deletion_protection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_deletion_protection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_deletion_protection" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_deletion_protection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_deletion_protection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26465,8 +26533,9 @@ def test_set_disk_auto_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26569,17 +26638,20 @@ def test_set_disk_auto_delete_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_disk_auto_delete" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_disk_auto_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_disk_auto_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_disk_auto_delete" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_disk_auto_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_disk_auto_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26632,8 +26704,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26814,17 +26887,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26875,8 +26950,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsInstanceReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27060,17 +27136,17 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27123,8 +27199,9 @@ def test_set_machine_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27314,17 +27391,20 @@ def test_set_machine_resources_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_resources" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_resources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_machine_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_machine_resources" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_machine_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_machine_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27377,8 +27457,9 @@ def test_set_machine_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27566,17 +27647,19 @@ def test_set_machine_type_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_type" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_machine_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_machine_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_machine_type" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_machine_type_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_machine_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27627,8 +27710,9 @@ def test_set_metadata_rest_bad_request(request_type=compute.SetMetadataInstanceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27803,17 +27887,19 @@ def test_set_metadata_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_metadata" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_metadata" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_metadata_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27866,8 +27952,9 @@ def test_set_min_cpu_platform_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28055,17 +28142,20 @@ def test_set_min_cpu_platform_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_min_cpu_platform" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_min_cpu_platform_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_min_cpu_platform" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_min_cpu_platform" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_min_cpu_platform_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_min_cpu_platform" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28116,8 +28206,9 @@ def test_set_name_rest_bad_request(request_type=compute.SetNameInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28299,17 +28390,15 @@ def test_set_name_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_name" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_name_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_name" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_set_name") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_name_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_set_name") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28360,8 +28449,9 @@ def test_set_scheduling_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28554,17 +28644,19 @@ def test_set_scheduling_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_scheduling" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_scheduling_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_scheduling" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_scheduling" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_scheduling_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_scheduling" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28617,8 +28709,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28810,17 +28903,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_security_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28873,8 +28969,9 @@ def test_set_service_account_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29063,17 +29160,20 @@ def test_set_service_account_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_service_account" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_service_account_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_service_account" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_service_account" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_service_account_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_set_service_account" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29126,8 +29226,9 @@ def test_set_shielded_instance_integrity_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29315,20 +29416,22 @@ def test_set_shielded_instance_integrity_policy_rest_interceptors(null_intercept ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_shielded_instance_integrity_policy", - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_set_shielded_instance_integrity_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, - "pre_set_shielded_instance_integrity_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_shielded_instance_integrity_policy", + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_set_shielded_instance_integrity_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, + "pre_set_shielded_instance_integrity_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29379,8 +29482,9 @@ def test_set_tags_rest_bad_request(request_type=compute.SetTagsInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29554,17 +29658,15 @@ def test_set_tags_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_tags" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_set_tags_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_set_tags" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_set_tags") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_set_tags_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_set_tags") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29615,8 +29717,9 @@ def test_simulate_maintenance_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29719,18 +29822,20 @@ def test_simulate_maintenance_event_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_simulate_maintenance_event" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_simulate_maintenance_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_simulate_maintenance_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_simulate_maintenance_event" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_simulate_maintenance_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_simulate_maintenance_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29781,8 +29886,9 @@ def test_start_rest_bad_request(request_type=compute.StartInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29885,17 +29991,15 @@ def test_start_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_start" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_start_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_start" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_start") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_start_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_start") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29946,8 +30050,9 @@ def test_start_with_encryption_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30146,18 +30251,20 @@ def test_start_with_encryption_key_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_start_with_encryption_key" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_start_with_encryption_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_start_with_encryption_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_start_with_encryption_key" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_start_with_encryption_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_start_with_encryption_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30208,8 +30315,9 @@ def test_stop_rest_bad_request(request_type=compute.StopInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30312,17 +30420,15 @@ def test_stop_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_stop" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_stop_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_stop" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_stop") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_stop_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_stop") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30371,8 +30477,9 @@ def test_suspend_rest_bad_request(request_type=compute.SuspendInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30475,17 +30582,15 @@ def test_suspend_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_suspend" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_suspend_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_suspend" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_suspend") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_suspend_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_suspend") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30536,8 +30641,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30676,17 +30782,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30739,8 +30848,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31152,17 +31262,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InstancesRestInterceptor, "post_update") as post, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstancesRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31213,8 +31321,9 @@ def test_update_access_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31400,17 +31509,20 @@ def test_update_access_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_access_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_access_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_access_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_access_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_access_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_access_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31463,8 +31575,9 @@ def test_update_display_device_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31639,17 +31752,20 @@ def test_update_display_device_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_display_device" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_display_device_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_display_device" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_display_device" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_display_device_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_display_device" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31702,8 +31818,9 @@ def test_update_network_interface_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31919,18 +32036,20 @@ def test_update_network_interface_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_network_interface" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_update_network_interface_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_network_interface" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_network_interface" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_network_interface_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_network_interface" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31983,8 +32102,9 @@ def test_update_shielded_instance_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32167,18 +32287,20 @@ def test_update_shielded_instance_config_rest_interceptors(null_interceptor): ) client = InstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstancesRestInterceptor, "post_update_shielded_instance_config" - ) as post, mock.patch.object( - transports.InstancesRestInterceptor, - "post_update_shielded_instance_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstancesRestInterceptor, "pre_update_shielded_instance_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstancesRestInterceptor, "post_update_shielded_instance_config" + ) as post, + mock.patch.object( + transports.InstancesRestInterceptor, + "post_update_shielded_instance_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstancesRestInterceptor, "pre_update_shielded_instance_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33393,11 +33515,14 @@ def test_instances_base_transport(): def test_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstancesTransport( @@ -33417,9 +33542,12 @@ def test_instances_base_transport_with_credentials_file(): def test_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instances.transports.InstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstancesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instant_snapshots.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instant_snapshots.py index f714af7a190e..15ef714dd234 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instant_snapshots.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_instant_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InstantSnapshotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InstantSnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InstantSnapshotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3897,8 +3902,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3969,17 +3975,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4039,8 +4048,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInstantSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4149,17 +4159,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4214,8 +4226,9 @@ def test_get_rest_bad_request(request_type=compute.GetInstantSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4314,17 +4327,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InstantSnapshotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4377,8 +4390,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4445,17 +4459,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4506,8 +4523,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInstantSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4707,17 +4725,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4768,8 +4788,9 @@ def test_list_rest_bad_request(request_type=compute.ListInstantSnapshotsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4838,17 +4859,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4903,8 +4926,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5087,17 +5111,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5150,8 +5177,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5335,17 +5363,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5398,8 +5428,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5540,18 +5571,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InstantSnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InstantSnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5834,11 +5867,14 @@ def test_instant_snapshots_base_transport(): def test_instant_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstantSnapshotsTransport( @@ -5858,9 +5894,12 @@ def test_instant_snapshots_base_transport_with_credentials_file(): def test_instant_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.instant_snapshots.transports.InstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstantSnapshotsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachment_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachment_groups.py index fd33c77da7d9..84d2a2840c50 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachment_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachment_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectAttachmentGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): InterconnectAttachmentGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectAttachmentGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3893,8 +3898,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3999,18 +4005,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4063,8 +4071,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4141,17 +4150,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4209,8 +4221,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4277,18 +4290,21 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_iam_policy", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4341,8 +4357,9 @@ def test_get_operational_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4411,20 +4428,22 @@ def test_get_operational_status_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_get_operational_status", - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_get_operational_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "pre_get_operational_status", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_operational_status", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_get_operational_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "pre_get_operational_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4486,8 +4505,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4724,18 +4744,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4788,8 +4810,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4862,18 +4885,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4931,8 +4956,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5169,18 +5195,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5233,8 +5261,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5417,18 +5446,21 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_set_iam_policy", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5481,8 +5513,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5625,20 +5658,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentGroupsRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentGroupsRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5923,11 +5958,14 @@ def test_interconnect_attachment_groups_base_transport(): def test_interconnect_attachment_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentGroupsTransport( @@ -5947,9 +5985,12 @@ def test_interconnect_attachment_groups_base_transport_with_credentials_file(): def test_interconnect_attachment_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.interconnect_attachment_groups.transports.InterconnectAttachmentGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachments.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachments.py index 2b7e9a5e94c3..e83da8f659b9 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachments.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_attachments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectAttachmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InterconnectAttachmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectAttachmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3768,8 +3773,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3840,18 +3846,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3913,8 +3921,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4023,17 +4032,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4088,8 +4100,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectAttachmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4254,17 +4267,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4319,8 +4334,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4568,17 +4584,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4629,8 +4648,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectAttachmentsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4699,17 +4719,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4768,8 +4790,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5021,17 +5044,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5084,8 +5110,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5269,18 +5296,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InterconnectAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, - "post_set_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectAttachmentsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectAttachmentsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5517,11 +5546,14 @@ def test_interconnect_attachments_base_transport(): def test_interconnect_attachments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentsTransport( @@ -5541,9 +5573,12 @@ def test_interconnect_attachments_base_transport_with_credentials_file(): def test_interconnect_attachments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.interconnect_attachments.transports.InterconnectAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectAttachmentsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_groups.py index b6869d3074c8..5cd936c9bc03 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InterconnectGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4223,8 +4228,9 @@ def test_create_members_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4435,18 +4441,20 @@ def test_create_members_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_create_members" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_create_members_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_create_members" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_create_members" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_create_members_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_create_members" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4497,8 +4505,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInterconnectGroupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4603,17 +4612,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4664,8 +4675,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4740,17 +4752,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4803,8 +4817,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4871,18 +4886,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4935,8 +4952,9 @@ def test_get_operational_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5001,18 +5019,20 @@ def test_get_operational_status_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_get_operational_status" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_get_operational_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_get_operational_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_get_operational_status" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_get_operational_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_get_operational_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5068,8 +5088,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInterconnectGroupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5298,17 +5319,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5359,8 +5382,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectGroupsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5433,17 +5457,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5499,8 +5525,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInterconnectGroupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5729,17 +5756,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5792,8 +5821,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5976,18 +6006,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6040,8 +6072,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6182,18 +6215,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = InterconnectGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InterconnectGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6499,11 +6534,14 @@ def test_interconnect_groups_base_transport(): def test_interconnect_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectGroupsTransport( @@ -6523,9 +6561,12 @@ def test_interconnect_groups_base_transport_with_credentials_file(): def test_interconnect_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.interconnect_groups.transports.InterconnectGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_locations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_locations.py index 34448902f9ee..e113a5cdb807 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_locations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_locations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectLocationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): InterconnectLocationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectLocationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1728,8 +1733,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectLocationReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1832,17 +1838,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1895,8 +1903,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectLocationsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1965,17 +1974,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectLocationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectLocationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2109,11 +2120,14 @@ def test_interconnect_locations_base_transport(): def test_interconnect_locations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectLocationsTransport( @@ -2134,9 +2148,12 @@ def test_interconnect_locations_base_transport_with_credentials_file(): def test_interconnect_locations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.interconnect_locations.transports.InterconnectLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectLocationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_remote_locations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_remote_locations.py index a8e7d5ff0083..dd9a9225889d 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_remote_locations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnect_remote_locations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectRemoteLocationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): InterconnectRemoteLocationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectRemoteLocationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1781,8 +1786,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1881,17 +1887,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectRemoteLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1946,8 +1955,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2016,17 +2026,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectRemoteLocationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectRemoteLocationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectRemoteLocationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2163,11 +2176,14 @@ def test_interconnect_remote_locations_base_transport(): def test_interconnect_remote_locations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectRemoteLocationsTransport( @@ -2188,9 +2204,12 @@ def test_interconnect_remote_locations_base_transport_with_credentials_file(): def test_interconnect_remote_locations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.interconnect_remote_locations.transports.InterconnectRemoteLocationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectRemoteLocationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnects.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnects.py index 980306d0b315..1c769031edde 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnects.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_interconnects.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InterconnectsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( InterconnectsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InterconnectsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3658,8 +3663,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteInterconnectRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3764,17 +3770,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3825,8 +3831,9 @@ def test_get_rest_bad_request(request_type=compute.GetInterconnectRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3947,17 +3954,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InterconnectsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4008,8 +4013,9 @@ def test_get_diagnostics_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4069,17 +4075,20 @@ def test_get_diagnostics_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_diagnostics" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_diagnostics_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_get_diagnostics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_get_diagnostics" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, + "post_get_diagnostics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_get_diagnostics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4137,8 +4146,9 @@ def test_get_macsec_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4201,17 +4211,20 @@ def test_get_macsec_config_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_macsec_config" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_get_macsec_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_get_macsec_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_get_macsec_config" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, + "post_get_macsec_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_get_macsec_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4267,8 +4280,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertInterconnectRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4526,17 +4540,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4587,8 +4601,9 @@ def test_list_rest_bad_request(request_type=compute.ListInterconnectsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4657,17 +4672,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.InterconnectsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4718,8 +4731,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchInterconnectRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4977,17 +4991,17 @@ def test_patch_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.InterconnectsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5038,8 +5052,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsInterconnectR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5223,17 +5238,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = InterconnectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.InterconnectsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.InterconnectsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.InterconnectsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.InterconnectsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5493,11 +5510,14 @@ def test_interconnects_base_transport(): def test_interconnects_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectsTransport( @@ -5517,9 +5537,12 @@ def test_interconnects_base_transport_with_credentials_file(): def test_interconnects_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.interconnects.transports.InterconnectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InterconnectsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_license_codes.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_license_codes.py index 5a6615af7f1d..58bb3d3dd6d8 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_license_codes.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_license_codes.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LicenseCodesClient._get_default_mtls_endpoint(None) is None assert ( @@ -135,6 +136,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert LicenseCodesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + LicenseCodesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1610,8 +1615,9 @@ def test_get_rest_bad_request(request_type=compute.GetLicenseCodeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1688,17 +1694,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = LicenseCodesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseCodesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.LicenseCodesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseCodesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicenseCodesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.LicenseCodesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicenseCodesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1749,8 +1753,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1891,18 +1896,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = LicenseCodesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseCodesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.LicenseCodesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseCodesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseCodesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.LicenseCodesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseCodesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2038,11 +2045,14 @@ def test_license_codes_base_transport(): def test_license_codes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseCodesTransport( @@ -2063,9 +2073,12 @@ def test_license_codes_base_transport_with_credentials_file(): def test_license_codes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.license_codes.transports.LicenseCodesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseCodesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_licenses.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_licenses.py index 4676a62ee927..fe4543df7d47 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_licenses.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_licenses.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LicensesClient._get_default_mtls_endpoint(None) is None assert LicensesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -132,6 +133,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert LicensesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert LicensesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -3523,8 +3525,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3627,17 +3630,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3686,8 +3687,9 @@ def test_get_rest_bad_request(request_type=compute.GetLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3788,17 +3790,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3849,8 +3849,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3915,17 +3916,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicensesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicensesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3976,8 +3979,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4180,17 +4184,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4239,8 +4241,9 @@ def test_list_rest_bad_request(request_type=compute.ListLicensesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4305,17 +4308,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4368,8 +4369,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4550,17 +4552,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicensesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicensesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4613,8 +4617,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4753,17 +4758,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicensesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.LicensesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicensesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4816,8 +4824,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateLicenseRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5020,17 +5029,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = LicensesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicensesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.LicensesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicensesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LicensesRestInterceptor, "post_update") as post, + mock.patch.object( + transports.LicensesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LicensesRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5288,11 +5295,14 @@ def test_licenses_base_transport(): def test_licenses_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.licenses.transports.LicensesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.licenses.transports.LicensesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicensesTransport( @@ -5312,9 +5322,12 @@ def test_licenses_base_transport_with_credentials_file(): def test_licenses_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.licenses.transports.LicensesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.licenses.transports.LicensesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicensesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_images.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_images.py index d39a1878f894..89d71e67398c 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_images.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_images.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MachineImagesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( MachineImagesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MachineImagesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3496,8 +3501,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteMachineImageRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3602,17 +3608,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3663,8 +3669,9 @@ def test_get_rest_bad_request(request_type=compute.GetMachineImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3753,17 +3760,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineImagesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3814,8 +3819,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3882,17 +3888,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3943,8 +3951,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertMachineImageRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4372,17 +4381,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4433,8 +4442,9 @@ def test_list_rest_bad_request(request_type=compute.ListMachineImagesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4503,17 +4513,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineImagesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineImagesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4566,8 +4574,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4750,17 +4759,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4811,8 +4822,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsMachineImageR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4996,17 +5008,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5059,8 +5073,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5201,18 +5216,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = MachineImagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineImagesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.MachineImagesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MachineImagesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineImagesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.MachineImagesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MachineImagesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5474,11 +5491,14 @@ def test_machine_images_base_transport(): def test_machine_images_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineImagesTransport( @@ -5498,9 +5518,12 @@ def test_machine_images_base_transport_with_credentials_file(): def test_machine_images_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.machine_images.transports.MachineImagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineImagesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_types.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_types.py index 0c008f2a6759..23b463e9a5d7 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_types.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_machine_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MachineTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -136,6 +137,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MachineTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MachineTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1965,8 +1970,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2037,17 +2043,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = MachineTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MachineTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2100,8 +2108,9 @@ def test_get_rest_bad_request(request_type=compute.GetMachineTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2190,17 +2199,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = MachineTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineTypesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2249,8 +2256,9 @@ def test_list_rest_bad_request(request_type=compute.ListMachineTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2319,17 +2327,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = MachineTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.MachineTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MachineTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.MachineTypesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.MachineTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.MachineTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2482,11 +2488,14 @@ def test_machine_types_base_transport(): def test_machine_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineTypesTransport( @@ -2507,9 +2516,12 @@ def test_machine_types_base_transport_with_credentials_file(): def test_machine_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.machine_types.transports.MachineTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MachineTypesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_attachments.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_attachments.py index 473cbf5d711b..e4d21a40d43c 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_attachments.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_attachments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkAttachmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): NetworkAttachmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkAttachmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3943,8 +3948,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4013,18 +4019,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4084,8 +4092,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNetworkAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4194,17 +4203,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4259,8 +4270,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkAttachmentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4353,17 +4365,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4416,8 +4430,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4484,18 +4499,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4546,8 +4563,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNetworkAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4761,17 +4779,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4822,8 +4842,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkAttachmentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4892,17 +4913,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4959,8 +4982,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNetworkAttachmentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5178,17 +5202,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5241,8 +5267,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5425,18 +5452,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5489,8 +5518,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5631,18 +5661,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworkAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkAttachmentsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkAttachmentsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5925,11 +5957,14 @@ def test_network_attachments_base_transport(): def test_network_attachments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkAttachmentsTransport( @@ -5949,9 +5984,12 @@ def test_network_attachments_base_transport_with_credentials_file(): def test_network_attachments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.network_attachments.transports.NetworkAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkAttachmentsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_edge_security_services.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_edge_security_services.py index febfab72709d..1874f84356e8 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_edge_security_services.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_edge_security_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkEdgeSecurityServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): NetworkEdgeSecurityServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkEdgeSecurityServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3138,8 +3143,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3212,18 +3218,21 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3285,8 +3294,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3395,18 +3405,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3463,8 +3475,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3549,17 +3562,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3614,8 +3630,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3810,18 +3827,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3878,8 +3897,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4078,18 +4098,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworkEdgeSecurityServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEdgeSecurityServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4284,11 +4306,14 @@ def test_network_edge_security_services_base_transport(): def test_network_edge_security_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEdgeSecurityServicesTransport( @@ -4308,9 +4333,12 @@ def test_network_edge_security_services_base_transport_with_credentials_file(): def test_network_edge_security_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.network_edge_security_services.transports.NetworkEdgeSecurityServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEdgeSecurityServicesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py index 81fa141d301d..3d2560bec696 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkEndpointGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): NetworkEndpointGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkEndpointGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4294,8 +4299,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4366,18 +4372,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4439,8 +4447,9 @@ def test_attach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4644,18 +4653,22 @@ def test_attach_network_endpoints_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_attach_network_endpoints" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_attach_network_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints", + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "pre_attach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4712,8 +4725,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4822,17 +4836,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4889,8 +4905,9 @@ def test_detach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5094,18 +5111,22 @@ def test_detach_network_endpoints_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_detach_network_endpoints" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_detach_network_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints", + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "pre_detach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5160,8 +5181,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkEndpointGroupReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5254,17 +5276,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5319,8 +5343,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5534,17 +5559,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5595,8 +5622,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkEndpointGroupsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5665,17 +5693,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5734,8 +5764,9 @@ def test_list_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5893,18 +5924,22 @@ def test_list_network_endpoints_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_list_network_endpoints" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_list_network_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints", + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "pre_list_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5962,8 +5997,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6104,18 +6140,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkEndpointGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkEndpointGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6404,11 +6442,14 @@ def test_network_endpoint_groups_base_transport(): def test_network_endpoint_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEndpointGroupsTransport( @@ -6428,9 +6469,12 @@ def test_network_endpoint_groups_base_transport_with_credentials_file(): def test_network_endpoint_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.network_endpoint_groups.transports.NetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkEndpointGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_firewall_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_firewall_policies.py index 809ad2294ed9..98bfcea5918c 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_firewall_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_firewall_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkFirewallPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): NetworkFirewallPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkFirewallPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -8311,8 +8316,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8501,18 +8507,20 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_add_association" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8565,8 +8573,9 @@ def test_add_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8804,20 +8813,22 @@ def test_add_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_add_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_add_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_add_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_add_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8870,8 +8881,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9109,17 +9121,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9172,8 +9187,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9244,18 +9260,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9313,8 +9331,9 @@ def test_clone_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9419,18 +9438,20 @@ def test_clone_rules_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_clone_rules" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_clone_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_clone_rules" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_clone_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9483,8 +9504,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9589,17 +9611,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9650,8 +9675,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkFirewallPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9740,17 +9766,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9803,8 +9831,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9875,18 +9904,20 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_association" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9941,8 +9972,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10009,18 +10041,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10073,8 +10107,9 @@ def test_get_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10161,20 +10196,22 @@ def test_get_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_get_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_get_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_get_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10227,8 +10264,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10315,17 +10353,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10378,8 +10419,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10650,17 +10692,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10711,8 +10756,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkFirewallPoliciesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10779,17 +10825,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10840,8 +10888,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNetworkFirewallPolicyR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11112,17 +11161,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11175,8 +11227,9 @@ def test_patch_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11416,20 +11469,22 @@ def test_patch_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_patch_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_patch_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_patch_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_patch_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11482,8 +11537,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11721,18 +11777,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11785,8 +11843,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11891,18 +11950,20 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_association" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_association" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_association" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11955,8 +12016,9 @@ def test_remove_packet_mirroring_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12061,20 +12123,22 @@ def test_remove_packet_mirroring_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_packet_mirroring_rule", - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_packet_mirroring_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "pre_remove_packet_mirroring_rule", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_packet_mirroring_rule", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_packet_mirroring_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_remove_packet_mirroring_rule", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12127,8 +12191,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12233,18 +12298,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12297,8 +12364,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12481,18 +12549,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12545,8 +12615,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12687,18 +12758,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetworkFirewallPoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworkFirewallPoliciesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13243,11 +13318,14 @@ def test_network_firewall_policies_base_transport(): def test_network_firewall_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkFirewallPoliciesTransport( @@ -13267,9 +13345,12 @@ def test_network_firewall_policies_base_transport_with_credentials_file(): def test_network_firewall_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.network_firewall_policies.transports.NetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkFirewallPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_profiles.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_profiles.py index 1778f95d9044..c5efecc06c15 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_profiles.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_network_profiles.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworkProfilesClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( NetworkProfilesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NetworkProfilesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1698,8 +1703,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkProfileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1776,17 +1782,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworkProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworkProfilesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1837,8 +1843,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworkProfilesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1911,17 +1918,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworkProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworkProfilesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.NetworkProfilesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworkProfilesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2058,11 +2065,14 @@ def test_network_profiles_base_transport(): def test_network_profiles_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkProfilesTransport( @@ -2083,9 +2093,12 @@ def test_network_profiles_base_transport_with_credentials_file(): def test_network_profiles_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.network_profiles.transports.NetworkProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworkProfilesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_networks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_networks.py index b76a654a9b03..02f17315e3ae 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_networks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_networks.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetworksClient._get_default_mtls_endpoint(None) is None assert NetworksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -132,6 +133,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NetworksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert NetworksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -5369,8 +5371,9 @@ def test_add_peering_rest_bad_request(request_type=compute.AddPeeringNetworkRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5584,17 +5587,17 @@ def test_add_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_add_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_add_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_add_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_add_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_add_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_add_peering") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5645,8 +5648,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5749,17 +5753,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5808,8 +5810,9 @@ def test_get_rest_bad_request(request_type=compute.GetNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5905,17 +5908,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5966,8 +5967,9 @@ def test_get_effective_firewalls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6025,17 +6027,20 @@ def test_get_effective_firewalls_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_get_effective_firewalls" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_get_effective_firewalls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_get_effective_firewalls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_get_effective_firewalls" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_get_effective_firewalls_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_get_effective_firewalls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6091,8 +6096,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6321,17 +6327,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6380,8 +6384,9 @@ def test_list_rest_bad_request(request_type=compute.ListNetworksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6448,17 +6453,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6509,8 +6512,9 @@ def test_list_peering_routes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6577,17 +6581,19 @@ def test_list_peering_routes_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_list_peering_routes" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_list_peering_routes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_list_peering_routes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_list_peering_routes" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_list_peering_routes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_list_peering_routes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6640,8 +6646,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6870,17 +6877,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetworksRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetworksRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6931,8 +6936,9 @@ def test_remove_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7116,17 +7122,19 @@ def test_remove_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_remove_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_remove_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_remove_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_remove_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_remove_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_remove_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7179,8 +7187,9 @@ def test_request_remove_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7368,17 +7377,20 @@ def test_request_remove_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_request_remove_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_request_remove_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_request_remove_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_request_remove_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_request_remove_peering_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_request_remove_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7431,8 +7443,9 @@ def test_switch_to_custom_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7535,17 +7548,20 @@ def test_switch_to_custom_mode_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_switch_to_custom_mode" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_switch_to_custom_mode_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_switch_to_custom_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_switch_to_custom_mode" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, + "post_switch_to_custom_mode_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_switch_to_custom_mode" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7598,8 +7614,9 @@ def test_update_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7813,17 +7830,19 @@ def test_update_peering_rest_interceptors(null_interceptor): ) client = NetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetworksRestInterceptor, "post_update_peering" - ) as post, mock.patch.object( - transports.NetworksRestInterceptor, "post_update_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetworksRestInterceptor, "pre_update_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetworksRestInterceptor, "post_update_peering" + ) as post, + mock.patch.object( + transports.NetworksRestInterceptor, "post_update_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetworksRestInterceptor, "pre_update_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8173,11 +8192,14 @@ def test_networks_base_transport(): def test_networks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.networks.transports.NetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.networks.transports.NetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworksTransport( @@ -8197,9 +8219,12 @@ def test_networks_base_transport_with_credentials_file(): def test_networks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.networks.transports.NetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.networks.transports.NetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetworksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_groups.py index 39fb5dcb76b0..997affcedcf2 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NodeGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + NodeGroupsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -6363,8 +6367,9 @@ def test_add_nodes_rest_bad_request(request_type=compute.AddNodesNodeGroupReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6550,17 +6555,17 @@ def test_add_nodes_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_add_nodes" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_add_nodes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_add_nodes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_add_nodes" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_add_nodes_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_add_nodes") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6613,8 +6618,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6685,17 +6691,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6748,8 +6756,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6854,17 +6863,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6915,8 +6922,9 @@ def test_delete_nodes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7104,17 +7112,19 @@ def test_delete_nodes_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete_nodes" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_delete_nodes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_delete_nodes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_delete_nodes" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_delete_nodes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_delete_nodes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7165,8 +7175,9 @@ def test_get_rest_bad_request(request_type=compute.GetNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7255,17 +7266,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7316,8 +7325,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7384,17 +7394,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7445,8 +7457,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7644,17 +7657,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7703,8 +7714,9 @@ def test_list_rest_bad_request(request_type=compute.ListNodeGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7773,17 +7785,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7832,8 +7842,9 @@ def test_list_nodes_rest_bad_request(request_type=compute.ListNodesNodeGroupsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7902,17 +7913,19 @@ def test_list_nodes_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list_nodes" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_list_nodes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_list_nodes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_list_nodes" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_list_nodes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_list_nodes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7965,8 +7978,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchNodeGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8164,17 +8178,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeGroupsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeGroupsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8225,8 +8237,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8417,17 +8430,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_perform_maintenance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8480,8 +8496,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8664,17 +8681,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8727,8 +8746,9 @@ def test_set_node_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8918,17 +8938,19 @@ def test_set_node_template_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_node_template" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_set_node_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_set_node_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_node_template" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_set_node_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_set_node_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8981,8 +9003,9 @@ def test_simulate_maintenance_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9172,18 +9195,20 @@ def test_simulate_maintenance_event_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_simulate_maintenance_event" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, - "post_simulate_maintenance_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_simulate_maintenance_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_simulate_maintenance_event" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, + "post_simulate_maintenance_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_simulate_maintenance_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9236,8 +9261,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9378,17 +9404,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NodeGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NodeGroupsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NodeGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9803,11 +9832,14 @@ def test_node_groups_base_transport(): def test_node_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeGroupsTransport( @@ -9827,9 +9859,12 @@ def test_node_groups_base_transport_with_credentials_file(): def test_node_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.node_groups.transports.NodeGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_templates.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_templates.py index 760f3936d724..96d61d36452f 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_templates.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_templates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeTemplatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( NodeTemplatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NodeTemplatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3439,8 +3444,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3511,17 +3517,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3578,8 +3587,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteNodeTemplateRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3688,17 +3698,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3753,8 +3763,9 @@ def test_get_rest_bad_request(request_type=compute.GetNodeTemplateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3841,17 +3852,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3902,8 +3911,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3970,17 +3980,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4031,8 +4043,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertNodeTemplateRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4232,17 +4245,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4293,8 +4306,9 @@ def test_list_rest_bad_request(request_type=compute.ListNodeTemplatesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4363,17 +4377,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTemplatesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4426,8 +4438,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4610,17 +4623,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4673,8 +4688,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4815,18 +4831,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = NodeTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.NodeTemplatesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeTemplatesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeTemplatesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5088,11 +5106,14 @@ def test_node_templates_base_transport(): def test_node_templates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTemplatesTransport( @@ -5112,9 +5133,12 @@ def test_node_templates_base_transport_with_credentials_file(): def test_node_templates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.node_templates.transports.NodeTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTemplatesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_types.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_types.py index 99741395cd5c..5eb08b6bf622 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_types.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_node_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeTypesClient._get_default_mtls_endpoint(None) is None assert NodeTypesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -134,6 +135,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NodeTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + NodeTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1952,8 +1956,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2022,17 +2027,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = NodeTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NodeTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2092,9 @@ def test_get_rest_bad_request(request_type=compute.GetNodeTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2169,17 +2177,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = NodeTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTypesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2228,8 +2234,9 @@ def test_list_rest_bad_request(request_type=compute.ListNodeTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2296,17 +2303,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = NodeTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.NodeTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NodeTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NodeTypesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.NodeTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NodeTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2457,11 +2462,14 @@ def test_node_types_base_transport(): def test_node_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTypesTransport( @@ -2482,9 +2490,12 @@ def test_node_types_base_transport_with_credentials_file(): def test_node_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.node_types.transports.NodeTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeTypesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_organization_security_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_organization_security_policies.py index 6cec75bde095..847f06eb78e4 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_organization_security_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_organization_security_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert OrganizationSecurityPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): OrganizationSecurityPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + OrganizationSecurityPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -6047,8 +6052,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6239,18 +6245,22 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_add_association", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_add_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6303,8 +6313,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6572,18 +6583,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_add_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6636,8 +6649,9 @@ def test_copy_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6742,18 +6756,20 @@ def test_copy_rules_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_copy_rules" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_copy_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_copy_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_copy_rules" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_copy_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_copy_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6806,8 +6822,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6912,18 +6929,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6976,8 +6995,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7062,17 +7082,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7125,8 +7148,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7201,18 +7225,22 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_association", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_get_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7267,8 +7295,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7339,18 +7368,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_get_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7403,8 +7434,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7762,18 +7794,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7826,8 +7860,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7894,18 +7929,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7958,8 +7995,9 @@ def test_list_associations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8026,18 +8064,22 @@ def test_list_associations_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_list_associations" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_associations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_list_associations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_associations", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_associations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_list_associations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8099,8 +8141,9 @@ def test_list_preconfigured_expression_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8166,20 +8209,22 @@ def test_list_preconfigured_expression_sets_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets", - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "pre_list_preconfigured_expression_sets", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_list_preconfigured_expression_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8243,8 +8288,9 @@ def test_move_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8349,18 +8395,20 @@ def test_move_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_move" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_move_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_move" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_move" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_move_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_move" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8413,8 +8461,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8772,18 +8821,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8836,8 +8887,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9105,18 +9157,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9169,8 +9223,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9275,19 +9330,22 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_remove_association", - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_remove_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_remove_association", + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "pre_remove_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9340,8 +9398,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9446,18 +9505,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = OrganizationSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.OrganizationSecurityPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.OrganizationSecurityPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9891,11 +9952,14 @@ def test_organization_security_policies_base_transport(): def test_organization_security_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OrganizationSecurityPoliciesTransport( @@ -9915,9 +9979,12 @@ def test_organization_security_policies_base_transport_with_credentials_file(): def test_organization_security_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.organization_security_policies.transports.OrganizationSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.OrganizationSecurityPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_packet_mirrorings.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_packet_mirrorings.py index fc5c11b62abe..ade81939bb55 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_packet_mirrorings.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_packet_mirrorings.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PacketMirroringsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PacketMirroringsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PacketMirroringsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3495,8 +3500,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3567,17 +3573,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3637,8 +3646,9 @@ def test_delete_rest_bad_request(request_type=compute.DeletePacketMirroringReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3747,17 +3757,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3812,8 +3824,9 @@ def test_get_rest_bad_request(request_type=compute.GetPacketMirroringRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3896,17 +3909,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PacketMirroringsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3957,8 +3970,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertPacketMirroringReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4161,17 +4175,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4222,8 +4238,9 @@ def test_list_rest_bad_request(request_type=compute.ListPacketMirroringsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4292,17 +4309,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4359,8 +4378,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchPacketMirroringRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4567,17 +4587,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4630,8 +4652,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4772,18 +4795,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = PacketMirroringsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.PacketMirroringsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PacketMirroringsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PacketMirroringsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5024,11 +5049,14 @@ def test_packet_mirrorings_base_transport(): def test_packet_mirrorings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PacketMirroringsTransport( @@ -5048,9 +5076,12 @@ def test_packet_mirrorings_base_transport_with_credentials_file(): def test_packet_mirrorings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.packet_mirrorings.transports.PacketMirroringsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PacketMirroringsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_preview_features.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_preview_features.py index 7ce98617dbba..15f26b6cdac9 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_preview_features.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_preview_features.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PreviewFeaturesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( PreviewFeaturesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PreviewFeaturesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2108,8 +2113,9 @@ def test_get_rest_bad_request(request_type=compute.GetPreviewFeatureRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2184,17 +2190,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = PreviewFeaturesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PreviewFeaturesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2245,8 +2251,9 @@ def test_list_rest_bad_request(request_type=compute.ListPreviewFeaturesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2317,17 +2324,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = PreviewFeaturesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PreviewFeaturesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2378,8 +2385,9 @@ def test_update_rest_bad_request(request_type=compute.UpdatePreviewFeatureReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2578,17 +2586,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = PreviewFeaturesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PreviewFeaturesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PreviewFeaturesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2741,11 +2751,14 @@ def test_preview_features_base_transport(): def test_preview_features_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PreviewFeaturesTransport( @@ -2765,9 +2778,12 @@ def test_preview_features_base_transport_with_credentials_file(): def test_preview_features_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.preview_features.transports.PreviewFeaturesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PreviewFeaturesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_projects.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_projects.py index 9c1701ddc999..22757669ca88 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_projects.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_projects.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProjectsClient._get_default_mtls_endpoint(None) is None assert ProjectsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -132,6 +133,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ProjectsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ProjectsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -6050,8 +6052,9 @@ def test_disable_xpn_host_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6154,17 +6157,19 @@ def test_disable_xpn_host_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_host" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_host_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_disable_xpn_host" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_disable_xpn_host" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_disable_xpn_host_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_disable_xpn_host" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6217,8 +6222,9 @@ def test_disable_xpn_resource_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6406,17 +6412,20 @@ def test_disable_xpn_resource_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_resource" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_disable_xpn_resource_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_disable_xpn_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_disable_xpn_resource" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_disable_xpn_resource_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_disable_xpn_resource" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6469,8 +6478,9 @@ def test_enable_xpn_host_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6573,17 +6583,19 @@ def test_enable_xpn_host_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_host" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_host_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_enable_xpn_host" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_host" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_host_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_enable_xpn_host" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6636,8 +6648,9 @@ def test_enable_xpn_resource_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6825,17 +6838,19 @@ def test_enable_xpn_resource_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_resource" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_enable_xpn_resource_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_enable_xpn_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_resource" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_enable_xpn_resource_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_enable_xpn_resource" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6886,8 +6901,9 @@ def test_get_rest_bad_request(request_type=compute.GetProjectRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6970,17 +6986,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ProjectsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ProjectsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7029,8 +7043,9 @@ def test_get_xpn_host_rest_bad_request(request_type=compute.GetXpnHostProjectReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7113,17 +7128,19 @@ def test_get_xpn_host_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_host" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_host_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_get_xpn_host" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_host" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_host_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_get_xpn_host" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7176,8 +7193,9 @@ def test_get_xpn_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7240,17 +7258,19 @@ def test_get_xpn_resources_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_resources" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_get_xpn_resources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_get_xpn_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_resources" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_get_xpn_resources_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_get_xpn_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7305,8 +7325,9 @@ def test_list_xpn_hosts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7456,17 +7477,19 @@ def test_list_xpn_hosts_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_list_xpn_hosts" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_list_xpn_hosts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_list_xpn_hosts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_list_xpn_hosts" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_list_xpn_hosts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_list_xpn_hosts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7517,8 +7540,9 @@ def test_move_disk_rest_bad_request(request_type=compute.MoveDiskProjectRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7698,17 +7722,15 @@ def test_move_disk_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_disk" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_disk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_move_disk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ProjectsRestInterceptor, "post_move_disk") as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_move_disk_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ProjectsRestInterceptor, "pre_move_disk") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7759,8 +7781,9 @@ def test_move_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7942,17 +7965,19 @@ def test_move_instance_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_instance" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_move_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_move_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_move_instance" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_move_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_move_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8005,8 +8030,9 @@ def test_set_cloud_armor_tier_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8194,17 +8220,20 @@ def test_set_cloud_armor_tier_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_cloud_armor_tier" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_cloud_armor_tier_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_cloud_armor_tier" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_cloud_armor_tier" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_cloud_armor_tier_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_cloud_armor_tier" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8257,8 +8286,9 @@ def test_set_common_instance_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8435,18 +8465,20 @@ def test_set_common_instance_metadata_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_common_instance_metadata" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, - "post_set_common_instance_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_common_instance_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_common_instance_metadata" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_common_instance_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_common_instance_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8499,8 +8531,9 @@ def test_set_default_network_tier_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8688,18 +8721,20 @@ def test_set_default_network_tier_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_default_network_tier" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, - "post_set_default_network_tier_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_default_network_tier" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_default_network_tier" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_default_network_tier_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_default_network_tier" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8752,8 +8787,9 @@ def test_set_usage_export_bucket_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8935,17 +8971,20 @@ def test_set_usage_export_bucket_rest_interceptors(null_interceptor): ) client = ProjectsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_usage_export_bucket" - ) as post, mock.patch.object( - transports.ProjectsRestInterceptor, "post_set_usage_export_bucket_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectsRestInterceptor, "pre_set_usage_export_bucket" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectsRestInterceptor, "post_set_usage_export_bucket" + ) as post, + mock.patch.object( + transports.ProjectsRestInterceptor, + "post_set_usage_export_bucket_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectsRestInterceptor, "pre_set_usage_export_bucket" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9343,11 +9382,14 @@ def test_projects_base_transport(): def test_projects_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.projects.transports.ProjectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.projects.transports.ProjectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectsTransport( @@ -9367,9 +9409,12 @@ def test_projects_base_transport_with_credentials_file(): def test_projects_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.projects.transports.ProjectsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.projects.transports.ProjectsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py index fd925829ff16..18b28a42a658 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PublicAdvertisedPrefixesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PublicAdvertisedPrefixesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PublicAdvertisedPrefixesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3760,8 +3765,9 @@ def test_announce_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3866,18 +3872,20 @@ def test_announce_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_announce" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, - "post_announce_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_announce" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_announce" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_announce_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_announce" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3930,8 +3938,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4036,17 +4045,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4097,8 +4109,9 @@ def test_get_rest_bad_request(request_type=compute.GetPublicAdvertisedPrefixeReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4187,17 +4200,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4252,8 +4267,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4458,17 +4474,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4521,8 +4540,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4591,17 +4611,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4656,8 +4679,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4862,17 +4886,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4925,8 +4952,9 @@ def test_withdraw_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5031,18 +5059,20 @@ def test_withdraw_rest_interceptors(null_interceptor): ) client = PublicAdvertisedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "post_withdraw" - ) as post, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, - "post_withdraw_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublicAdvertisedPrefixesRestInterceptor, "pre_withdraw" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "post_withdraw" + ) as post, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, + "post_withdraw_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicAdvertisedPrefixesRestInterceptor, "pre_withdraw" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5279,11 +5309,14 @@ def test_public_advertised_prefixes_base_transport(): def test_public_advertised_prefixes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicAdvertisedPrefixesTransport( @@ -5303,9 +5336,12 @@ def test_public_advertised_prefixes_base_transport_with_credentials_file(): def test_public_advertised_prefixes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.public_advertised_prefixes.transports.PublicAdvertisedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicAdvertisedPrefixesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py index 11cec2a1e134..27401d948de3 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PublicDelegatedPrefixesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): PublicDelegatedPrefixesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PublicDelegatedPrefixesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4138,8 +4143,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4210,18 +4216,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4283,8 +4291,9 @@ def test_announce_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4393,17 +4402,20 @@ def test_announce_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_announce" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_announce_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_announce" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_announce" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_announce_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_announce" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4460,8 +4472,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4570,17 +4583,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4635,8 +4651,9 @@ def test_get_rest_bad_request(request_type=compute.GetPublicDelegatedPrefixeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4735,17 +4752,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4800,8 +4819,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5015,17 +5035,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5076,8 +5099,9 @@ def test_list_rest_bad_request(request_type=compute.ListPublicDelegatedPrefixesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5146,17 +5170,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5215,8 +5241,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5434,17 +5461,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5501,8 +5531,9 @@ def test_withdraw_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5611,17 +5642,20 @@ def test_withdraw_rest_interceptors(null_interceptor): ) client = PublicDelegatedPrefixesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_withdraw" - ) as post, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "post_withdraw_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublicDelegatedPrefixesRestInterceptor, "pre_withdraw" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "post_withdraw" + ) as post, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, + "post_withdraw_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublicDelegatedPrefixesRestInterceptor, "pre_withdraw" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5879,11 +5913,14 @@ def test_public_delegated_prefixes_base_transport(): def test_public_delegated_prefixes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicDelegatedPrefixesTransport( @@ -5903,9 +5940,12 @@ def test_public_delegated_prefixes_base_transport_with_credentials_file(): def test_public_delegated_prefixes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.public_delegated_prefixes.transports.PublicDelegatedPrefixesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublicDelegatedPrefixesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_autoscalers.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_autoscalers.py index e7ba611ce2b3..fe3a957fb882 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_autoscalers.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_autoscalers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionAutoscalersClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionAutoscalersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionAutoscalersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3641,8 +3646,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionAutoscalerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3747,17 +3753,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3808,8 +3816,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionAutoscalerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3892,17 +3901,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3953,8 +3964,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionAutoscalerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4172,17 +4184,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4233,8 +4247,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionAutoscalersRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4303,17 +4318,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4366,8 +4383,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionAutoscalerReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4583,17 +4601,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4646,8 +4666,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4788,18 +4809,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4852,8 +4875,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionAutoscalerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5071,17 +5095,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionAutoscalersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionAutoscalersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionAutoscalersRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5320,11 +5346,14 @@ def test_region_autoscalers_base_transport(): def test_region_autoscalers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionAutoscalersTransport( @@ -5344,9 +5373,12 @@ def test_region_autoscalers_base_transport_with_credentials_file(): def test_region_autoscalers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_autoscalers.transports.RegionAutoscalersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionAutoscalersTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_backend_services.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_backend_services.py index 623ecec2d815..a9442219af34 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_backend_services.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_backend_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionBackendServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionBackendServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionBackendServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5011,8 +5016,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5121,17 +5127,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5186,8 +5194,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionBackendServiceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5317,17 +5326,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5384,8 +5395,9 @@ def test_get_health_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5528,17 +5540,20 @@ def test_get_health_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_health" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_health_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_get_health" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get_health" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_get_health_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_get_health" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5593,8 +5608,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5661,18 +5677,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5725,8 +5743,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6101,17 +6120,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6162,8 +6183,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionBackendServicesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6232,17 +6254,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6295,8 +6319,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6365,18 +6390,20 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_list_usable_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_list_usable_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6433,8 +6460,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionBackendServiceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6813,17 +6841,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6876,8 +6906,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7060,18 +7091,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7128,8 +7161,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7316,18 +7350,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_set_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7380,8 +7416,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7522,18 +7559,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7592,8 +7631,9 @@ def test_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7972,17 +8012,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionBackendServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionBackendServicesRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionBackendServicesRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8328,11 +8370,14 @@ def test_region_backend_services_base_transport(): def test_region_backend_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionBackendServicesTransport( @@ -8352,9 +8397,12 @@ def test_region_backend_services_base_transport_with_credentials_file(): def test_region_backend_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_backend_services.transports.RegionBackendServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionBackendServicesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_commitments.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_commitments.py index 2da6f7ee47c6..6003c06a7dd0 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_commitments.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_commitments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionCommitmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionCommitmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionCommitmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2866,8 +2871,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2938,18 +2944,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3002,8 +3010,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionCommitmentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3102,17 +3111,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3163,8 +3174,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionCommitmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3482,17 +3494,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3543,8 +3557,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionCommitmentsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3613,17 +3628,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3674,8 +3691,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionCommitmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3993,17 +4011,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionCommitmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCommitmentsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionCommitmentsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4198,11 +4218,14 @@ def test_region_commitments_base_transport(): def test_region_commitments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCommitmentsTransport( @@ -4222,9 +4245,12 @@ def test_region_commitments_base_transport_with_credentials_file(): def test_region_commitments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_commitments.transports.RegionCommitmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCommitmentsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_composite_health_checks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_composite_health_checks.py index 118ac906b721..33687fe933f3 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_composite_health_checks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_composite_health_checks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionCompositeHealthChecksClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionCompositeHealthChecksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionCompositeHealthChecksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3552,8 +3557,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3624,18 +3630,21 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3697,8 +3706,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3807,18 +3817,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3875,8 +3887,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3963,17 +3976,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4028,8 +4044,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4222,18 +4239,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4286,8 +4305,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4356,17 +4376,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4425,8 +4448,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4623,18 +4647,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4687,8 +4713,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4831,20 +4858,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionCompositeHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionCompositeHealthChecksRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionCompositeHealthChecksRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5085,11 +5114,14 @@ def test_region_composite_health_checks_base_transport(): def test_region_composite_health_checks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCompositeHealthChecksTransport( @@ -5109,9 +5141,12 @@ def test_region_composite_health_checks_base_transport_with_credentials_file(): def test_region_composite_health_checks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_composite_health_checks.transports.RegionCompositeHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionCompositeHealthChecksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disk_types.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disk_types.py index 2d36eb228b3f..0ba7778e80f5 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disk_types.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disk_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionDiskTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionDiskTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionDiskTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1718,8 +1723,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionDiskTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1800,17 +1806,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionDiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDiskTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1861,8 +1867,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionDiskTypesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1931,17 +1938,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionDiskTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDiskTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionDiskTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDiskTypesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2073,11 +2080,14 @@ def test_region_disk_types_base_transport(): def test_region_disk_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDiskTypesTransport( @@ -2098,9 +2108,12 @@ def test_region_disk_types_base_transport_with_credentials_file(): def test_region_disk_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_disk_types.transports.RegionDiskTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDiskTypesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disks.py index bc119d3a2c70..abd8194c8d28 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_disks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionDisksClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegionDisksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RegionDisksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -7424,8 +7428,9 @@ def test_add_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7615,18 +7620,20 @@ def test_add_resource_policies_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_add_resource_policies" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_add_resource_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_add_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_add_resource_policies" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_add_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_add_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7677,8 +7684,9 @@ def test_bulk_insert_rest_bad_request(request_type=compute.BulkInsertRegionDiskR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7861,17 +7869,19 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_bulk_insert" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_bulk_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7924,8 +7934,9 @@ def test_create_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8145,17 +8156,19 @@ def test_create_snapshot_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_create_snapshot" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_create_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_create_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_create_snapshot" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_create_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_create_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8206,8 +8219,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8312,17 +8326,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8373,8 +8385,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8523,17 +8536,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8584,8 +8595,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8652,17 +8664,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8713,8 +8727,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8952,17 +8967,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9013,8 +9026,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionDisksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9083,17 +9097,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9144,8 +9156,9 @@ def test_remove_resource_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9335,18 +9348,20 @@ def test_remove_resource_policies_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_remove_resource_policies" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_remove_resource_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_remove_resource_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_remove_resource_policies" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_remove_resource_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_remove_resource_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9397,8 +9412,9 @@ def test_resize_rest_bad_request(request_type=compute.ResizeRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9581,17 +9597,15 @@ def test_resize_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_resize") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_resize") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9644,8 +9658,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9828,17 +9843,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9889,8 +9906,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsRegionDiskReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10074,17 +10092,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10137,8 +10157,9 @@ def test_start_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10328,18 +10349,20 @@ def test_start_async_replication_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_start_async_replication" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_start_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_start_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_start_async_replication" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_start_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_start_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10392,8 +10415,9 @@ def test_stop_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10498,18 +10522,20 @@ def test_stop_async_replication_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_stop_async_replication" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_stop_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_stop_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_stop_async_replication" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_stop_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_stop_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10562,8 +10588,9 @@ def test_stop_group_async_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10753,18 +10780,20 @@ def test_stop_group_async_replication_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_stop_group_async_replication" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, - "post_stop_group_async_replication_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_stop_group_async_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_stop_group_async_replication" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_stop_group_async_replication_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_stop_group_async_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10817,8 +10846,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10959,17 +10989,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionDisksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11022,8 +11055,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionDiskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11261,17 +11295,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionDisksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionDisksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionDisksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionDisksRestInterceptor, "post_update") as post, + mock.patch.object( + transports.RegionDisksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionDisksRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11730,11 +11762,14 @@ def test_region_disks_base_transport(): def test_region_disks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDisksTransport( @@ -11754,9 +11789,12 @@ def test_region_disks_base_transport_with_credentials_file(): def test_region_disks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_disks.transports.RegionDisksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionDisksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_aggregation_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_aggregation_policies.py index 2e3560c0d804..60c42fb70ca7 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_aggregation_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_aggregation_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( RegionHealthAggregationPoliciesClient._get_default_mtls_endpoint(None) is None @@ -150,6 +151,12 @@ def test__get_default_mtls_endpoint(): RegionHealthAggregationPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthAggregationPoliciesClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3597,8 +3604,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3669,19 +3677,22 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_aggregated_list", - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "pre_aggregated_list", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3743,8 +3754,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3853,18 +3865,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3921,8 +3935,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4011,18 +4026,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4077,8 +4094,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4272,18 +4290,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4336,8 +4356,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4406,18 +4427,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4479,8 +4502,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4678,18 +4702,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4742,8 +4768,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4886,20 +4913,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthAggregationPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthAggregationPoliciesRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthAggregationPoliciesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5140,11 +5169,14 @@ def test_region_health_aggregation_policies_base_transport(): def test_region_health_aggregation_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthAggregationPoliciesTransport( @@ -5164,9 +5196,12 @@ def test_region_health_aggregation_policies_base_transport_with_credentials_file def test_region_health_aggregation_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_health_aggregation_policies.transports.RegionHealthAggregationPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthAggregationPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_check_services.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_check_services.py index 1467c6060294..151e53157409 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_check_services.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_check_services.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionHealthCheckServicesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionHealthCheckServicesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthCheckServicesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3528,8 +3533,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3600,18 +3606,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3673,8 +3681,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3783,17 +3792,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3848,8 +3860,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionHealthCheckServiceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3941,17 +3954,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4004,8 +4020,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4205,17 +4222,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4268,8 +4288,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4338,17 +4359,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4407,8 +4431,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4612,17 +4637,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4675,8 +4703,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4817,18 +4846,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthCheckServicesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthCheckServicesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthCheckServicesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5069,11 +5102,14 @@ def test_region_health_check_services_base_transport(): def test_region_health_check_services_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthCheckServicesTransport( @@ -5093,9 +5129,12 @@ def test_region_health_check_services_base_transport_with_credentials_file(): def test_region_health_check_services_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_health_check_services.transports.RegionHealthCheckServicesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthCheckServicesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_checks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_checks.py index 58f939f10b54..42d9bbcc8735 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_checks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_checks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionHealthChecksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionHealthChecksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthChecksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3629,8 +3634,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionHealthCheckReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3739,17 +3745,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3804,8 +3812,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionHealthCheckRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3896,17 +3905,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3957,8 +3968,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionHealthCheckReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4204,17 +4216,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4265,8 +4279,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionHealthChecksReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4335,17 +4350,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4400,8 +4417,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionHealthCheckReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4651,17 +4669,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4714,8 +4734,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4856,18 +4877,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4924,8 +4947,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionHealthCheckReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5175,17 +5199,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionHealthChecksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthChecksRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthChecksRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5424,11 +5450,14 @@ def test_region_health_checks_base_transport(): def test_region_health_checks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthChecksTransport( @@ -5448,9 +5477,12 @@ def test_region_health_checks_base_transport_with_credentials_file(): def test_region_health_checks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_health_checks.transports.RegionHealthChecksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthChecksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_sources.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_sources.py index 0d961d9b6369..c7adcc74f068 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_sources.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_health_sources.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionHealthSourcesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionHealthSourcesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionHealthSourcesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3507,8 +3512,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3579,18 +3585,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3647,8 +3655,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionHealthSourceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3757,17 +3766,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3822,8 +3833,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionHealthSourceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3912,17 +3924,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3973,8 +3987,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionHealthSourceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4164,17 +4179,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4225,8 +4242,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionHealthSourcesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4295,17 +4313,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4360,8 +4380,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionHealthSourceRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4555,17 +4576,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4618,8 +4641,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4760,18 +4784,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionHealthSourcesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionHealthSourcesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionHealthSourcesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5012,11 +5038,14 @@ def test_region_health_sources_base_transport(): def test_region_health_sources_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthSourcesTransport( @@ -5036,9 +5065,12 @@ def test_region_health_sources_base_transport_with_credentials_file(): def test_region_health_sources_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_health_sources.transports.RegionHealthSourcesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionHealthSourcesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py index 315d2eb63ca2..b068c6e5eb80 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstanceGroupManagersClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionInstanceGroupManagersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstanceGroupManagersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -10626,8 +10631,9 @@ def test_abandon_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10821,18 +10827,22 @@ def test_abandon_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_abandon_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_abandon_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_abandon_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_abandon_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_abandon_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_abandon_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10889,8 +10899,9 @@ def test_apply_updates_to_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11089,20 +11100,22 @@ def test_apply_updates_to_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_apply_updates_to_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_apply_updates_to_instances", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_apply_updates_to_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_apply_updates_to_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11161,8 +11174,9 @@ def test_create_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11368,18 +11382,22 @@ def test_create_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_create_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_create_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_create_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_create_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_create_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_create_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11436,8 +11454,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11546,18 +11565,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11614,8 +11635,9 @@ def test_delete_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11810,18 +11832,22 @@ def test_delete_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_delete_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_delete_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_delete_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11878,8 +11904,9 @@ def test_delete_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12075,20 +12102,22 @@ def test_delete_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_delete_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_delete_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_delete_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_delete_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12147,8 +12176,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12254,17 +12284,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12319,8 +12352,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12637,18 +12671,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12701,8 +12737,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12771,17 +12808,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12843,8 +12883,9 @@ def test_list_errors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12913,18 +12954,20 @@ def test_list_errors_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_list_errors" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_errors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_list_errors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_list_errors" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_errors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_list_errors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12986,8 +13029,9 @@ def test_list_managed_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13056,20 +13100,22 @@ def test_list_managed_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_managed_instances", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_managed_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_list_managed_instances", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_managed_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_managed_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_list_managed_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13131,8 +13177,9 @@ def test_list_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13201,20 +13248,22 @@ def test_list_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_list_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_list_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_list_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_list_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13280,8 +13329,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13602,18 +13652,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13670,8 +13722,9 @@ def test_patch_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13879,20 +13932,22 @@ def test_patch_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_patch_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_patch_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_patch_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_patch_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13951,8 +14006,9 @@ def test_recreate_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14146,18 +14202,22 @@ def test_recreate_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_recreate_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_recreate_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_recreate_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_recreate_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_recreate_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_recreate_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14214,8 +14274,9 @@ def test_resize_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14324,18 +14385,20 @@ def test_resize_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_resize_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_resize" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resize_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_resize" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14392,8 +14455,9 @@ def test_resume_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14587,18 +14651,22 @@ def test_resume_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_resume_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_resume_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_resume_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resume_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_resume_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_resume_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14655,8 +14723,9 @@ def test_set_instance_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14852,20 +14921,22 @@ def test_set_instance_template_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_instance_template", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_instance_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_set_instance_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_instance_template", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_instance_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_set_instance_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14922,8 +14993,9 @@ def test_set_target_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15118,18 +15190,22 @@ def test_set_target_pools_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_set_target_pools" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_set_target_pools_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_set_target_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_target_pools", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_set_target_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_set_target_pools", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15186,8 +15262,9 @@ def test_start_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15381,18 +15458,21 @@ def test_start_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_start_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_start_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_start_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_start_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_start_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_start_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15449,8 +15529,9 @@ def test_stop_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15645,18 +15726,20 @@ def test_stop_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_stop_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_stop_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_stop_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "post_stop_instances" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_stop_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, "pre_stop_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15713,8 +15796,9 @@ def test_suspend_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15908,18 +15992,22 @@ def test_suspend_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "post_suspend_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_suspend_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, "pre_suspend_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_suspend_instances", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_suspend_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_suspend_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15976,8 +16064,9 @@ def test_update_per_instance_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16187,20 +16276,22 @@ def test_update_per_instance_configs_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupManagersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs", - ) as post, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "post_update_per_instance_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupManagersRestInterceptor, - "pre_update_per_instance_configs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs", + ) as post, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "post_update_per_instance_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupManagersRestInterceptor, + "pre_update_per_instance_configs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16799,11 +16890,14 @@ def test_region_instance_group_managers_base_transport(): def test_region_instance_group_managers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupManagersTransport( @@ -16823,9 +16917,12 @@ def test_region_instance_group_managers_base_transport_with_credentials_file(): def test_region_instance_group_managers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_instance_group_managers.transports.RegionInstanceGroupManagersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupManagersTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_groups.py index b5c84f262a0d..e93db85e736c 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstanceGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionInstanceGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstanceGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2704,8 +2709,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionInstanceGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2794,17 +2800,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2855,8 +2863,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionInstanceGroupsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2925,17 +2934,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2994,8 +3005,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3154,18 +3166,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, - "post_list_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3227,8 +3241,9 @@ def test_set_named_ports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3423,18 +3438,20 @@ def test_set_named_ports_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_set_named_ports" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, - "post_set_named_ports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_set_named_ports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_set_named_ports" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, + "post_set_named_ports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_set_named_ports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3487,8 +3504,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3629,18 +3647,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionInstanceGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceGroupsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceGroupsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3839,11 +3859,14 @@ def test_region_instance_groups_base_transport(): def test_region_instance_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupsTransport( @@ -3863,9 +3886,12 @@ def test_region_instance_groups_base_transport_with_credentials_file(): def test_region_instance_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_instance_groups.transports.RegionInstanceGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_templates.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_templates.py index f7854332d1eb..9cb1311ea0b8 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_templates.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instance_templates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstanceTemplatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionInstanceTemplatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstanceTemplatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2594,8 +2599,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2704,17 +2710,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2769,8 +2778,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionInstanceTemplateRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2851,17 +2861,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2914,8 +2926,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3300,17 +3313,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3361,8 +3377,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionInstanceTemplatesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3431,17 +3448,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstanceTemplatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstanceTemplatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstanceTemplatesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3617,11 +3636,14 @@ def test_region_instance_templates_base_transport(): def test_region_instance_templates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceTemplatesTransport( @@ -3641,9 +3663,12 @@ def test_region_instance_templates_base_transport_with_credentials_file(): def test_region_instance_templates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_instance_templates.transports.RegionInstanceTemplatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstanceTemplatesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instances.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instances.py index 5111e4ec07dd..6bddefba6972 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instances.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instances.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstancesClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionInstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstancesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1663,8 +1668,9 @@ def test_bulk_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2047,17 +2053,19 @@ def test_bulk_insert_rest_interceptors(null_interceptor): ) client = RegionInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstancesRestInterceptor, "post_bulk_insert" - ) as post, mock.patch.object( - transports.RegionInstancesRestInterceptor, "post_bulk_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstancesRestInterceptor, "pre_bulk_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstancesRestInterceptor, "post_bulk_insert" + ) as post, + mock.patch.object( + transports.RegionInstancesRestInterceptor, "post_bulk_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstancesRestInterceptor, "pre_bulk_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2166,11 +2174,14 @@ def test_region_instances_base_transport(): def test_region_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstancesTransport( @@ -2190,9 +2201,12 @@ def test_region_instances_base_transport_with_credentials_file(): def test_region_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_instances.transports.RegionInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstancesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instant_snapshots.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instant_snapshots.py index e5dd53924758..5e8f32905fd2 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instant_snapshots.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_instant_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionInstantSnapshotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionInstantSnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionInstantSnapshotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3657,8 +3662,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3767,17 +3773,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3832,8 +3841,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionInstantSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3932,17 +3942,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3995,8 +4007,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4063,18 +4076,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4127,8 +4142,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4328,17 +4344,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4389,8 +4408,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionInstantSnapshotsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4459,17 +4479,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4524,8 +4546,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4708,18 +4731,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4772,8 +4797,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4957,18 +4983,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_set_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5021,8 +5049,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5163,18 +5192,21 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionInstantSnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionInstantSnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionInstantSnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5436,11 +5468,14 @@ def test_region_instant_snapshots_base_transport(): def test_region_instant_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstantSnapshotsTransport( @@ -5460,9 +5495,12 @@ def test_region_instant_snapshots_base_transport_with_credentials_file(): def test_region_instant_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_instant_snapshots.transports.RegionInstantSnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionInstantSnapshotsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py index b1a6f2963313..3befb5a346be 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNetworkEndpointGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionNetworkEndpointGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNetworkEndpointGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3833,8 +3838,9 @@ def test_attach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4040,20 +4046,22 @@ def test_attach_network_endpoints_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints", - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_attach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "pre_attach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints", + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_attach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "pre_attach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4110,8 +4118,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4220,18 +4229,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4288,8 +4299,9 @@ def test_detach_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4495,20 +4507,22 @@ def test_detach_network_endpoints_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints", - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_detach_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "pre_detach_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints", + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_detach_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "pre_detach_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4565,8 +4579,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4659,17 +4674,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4724,8 +4742,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4939,18 +4958,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5003,8 +5024,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5073,17 +5095,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5142,8 +5167,9 @@ def test_list_network_endpoints_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5216,20 +5242,22 @@ def test_list_network_endpoints_rest_interceptors(null_interceptor): ) client = RegionNetworkEndpointGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints", - ) as post, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "post_list_network_endpoints_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkEndpointGroupsRestInterceptor, - "pre_list_network_endpoints", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints", + ) as post, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "post_list_network_endpoints_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkEndpointGroupsRestInterceptor, + "pre_list_network_endpoints", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5477,11 +5505,14 @@ def test_region_network_endpoint_groups_base_transport(): def test_region_network_endpoint_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkEndpointGroupsTransport( @@ -5501,9 +5532,12 @@ def test_region_network_endpoint_groups_base_transport_with_credentials_file(): def test_region_network_endpoint_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_network_endpoint_groups.transports.RegionNetworkEndpointGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkEndpointGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_firewall_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_firewall_policies.py index 73523fb272ad..5c6c25d670db 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_firewall_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_network_firewall_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNetworkFirewallPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): RegionNetworkFirewallPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNetworkFirewallPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -7063,8 +7068,9 @@ def test_add_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7257,18 +7263,22 @@ def test_add_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_add_association" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_add_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_add_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_add_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_add_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_add_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7325,8 +7335,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7568,18 +7579,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_add_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7636,8 +7649,9 @@ def test_clone_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7746,18 +7760,20 @@ def test_clone_rules_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_clone_rules" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_clone_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_clone_rules" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_clone_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_clone_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7814,8 +7830,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7924,18 +7941,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7992,8 +8011,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8086,18 +8106,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8154,8 +8176,9 @@ def test_get_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8230,18 +8253,22 @@ def test_get_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_association" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_association" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_get_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8296,8 +8323,9 @@ def test_get_effective_firewalls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8365,20 +8393,22 @@ def test_get_effective_firewalls_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_effective_firewalls", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_effective_firewalls_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "pre_get_effective_firewalls", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_effective_firewalls", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_effective_firewalls_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_get_effective_firewalls", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8440,8 +8470,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8508,18 +8539,22 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_iam_policy", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_get_iam_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8576,8 +8611,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8668,18 +8704,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_get_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8732,8 +8770,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9004,18 +9043,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9068,8 +9109,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9136,18 +9178,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9204,8 +9248,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9480,18 +9525,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_patch_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9548,8 +9595,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9791,18 +9839,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9859,8 +9909,9 @@ def test_remove_association_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9969,20 +10020,22 @@ def test_remove_association_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_remove_association", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_remove_association_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "pre_remove_association", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_remove_association", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_remove_association_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_remove_association", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10039,8 +10092,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10149,18 +10203,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10213,8 +10269,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10397,18 +10454,22 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_set_iam_policy", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_set_iam_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10461,8 +10522,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10605,20 +10667,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionNetworkFirewallPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNetworkFirewallPoliciesRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNetworkFirewallPoliciesRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11073,11 +11137,14 @@ def test_region_network_firewall_policies_base_transport(): def test_region_network_firewall_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkFirewallPoliciesTransport( @@ -11097,9 +11164,12 @@ def test_region_network_firewall_policies_base_transport_with_credentials_file() def test_region_network_firewall_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_network_firewall_policies.transports.RegionNetworkFirewallPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNetworkFirewallPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py index 5443d6d72f27..f7b6674dd256 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionNotificationEndpointsClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): RegionNotificationEndpointsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionNotificationEndpointsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3118,8 +3123,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3190,18 +3196,21 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_aggregated_list", + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3263,8 +3272,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3373,18 +3383,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_delete_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3441,8 +3453,9 @@ def test_get_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3521,17 +3534,20 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_get_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3586,8 +3602,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3783,18 +3800,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_insert_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3847,8 +3866,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3917,17 +3937,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3982,8 +4005,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4126,20 +4150,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RegionNotificationEndpointsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionNotificationEndpointsRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionNotificationEndpointsRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4359,11 +4385,14 @@ def test_region_notification_endpoints_base_transport(): def test_region_notification_endpoints_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNotificationEndpointsTransport( @@ -4383,9 +4412,12 @@ def test_region_notification_endpoints_base_transport_with_credentials_file(): def test_region_notification_endpoints_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_notification_endpoints.transports.RegionNotificationEndpointsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionNotificationEndpointsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_operations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_operations.py index 5cbed439e4d6..b6f4e3b34602 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_operations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): RegionOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2126,8 +2131,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionOperationReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2187,17 +2193,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2253,8 +2261,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2359,17 +2368,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionOperationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2420,8 +2429,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionOperationsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2490,17 +2500,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2551,8 +2563,9 @@ def test_wait_rest_bad_request(request_type=compute.WaitRegionOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2657,17 +2670,19 @@ def test_wait_rest_interceptors(null_interceptor): ) client = RegionOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_wait" - ) as post, mock.patch.object( - transports.RegionOperationsRestInterceptor, "post_wait_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionOperationsRestInterceptor, "pre_wait" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_wait" + ) as post, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "post_wait_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionOperationsRestInterceptor, "pre_wait" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2841,11 +2856,14 @@ def test_region_operations_base_transport(): def test_region_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionOperationsTransport( @@ -2865,9 +2883,12 @@ def test_region_operations_base_transport_with_credentials_file(): def test_region_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_operations.transports.RegionOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionOperationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_security_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_security_policies.py index 0d8fc26e905e..e6c7cdeb4dd2 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_security_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_security_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSecurityPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionSecurityPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSecurityPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5047,8 +5052,9 @@ def test_add_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5320,17 +5326,20 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_add_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5387,8 +5396,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5497,17 +5507,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5562,8 +5575,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSecurityPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5652,17 +5666,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5719,8 +5735,9 @@ def test_get_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5795,17 +5812,20 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_get_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5858,8 +5878,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6217,17 +6238,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6278,8 +6302,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSecurityPoliciesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6346,17 +6371,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6411,8 +6438,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionSecurityPolicyRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6774,17 +6802,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6841,8 +6871,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7114,18 +7145,20 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, - "post_patch_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_patch_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7182,8 +7215,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7292,18 +7326,20 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, - "post_remove_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_remove_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7356,8 +7392,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7541,18 +7578,20 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = RegionSecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, - "post_set_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSecurityPoliciesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, + "post_set_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSecurityPoliciesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7852,11 +7891,14 @@ def test_region_security_policies_base_transport(): def test_region_security_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSecurityPoliciesTransport( @@ -7876,9 +7918,12 @@ def test_region_security_policies_base_transport_with_credentials_file(): def test_region_security_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_security_policies.transports.RegionSecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSecurityPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py index b3cadd35855b..fdd99da65554 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSslCertificatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionSslCertificatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSslCertificatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2588,8 +2593,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2698,17 +2704,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2763,8 +2771,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSslCertificateReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2853,17 +2862,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2916,8 +2927,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3119,17 +3131,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3180,8 +3194,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSslCertificatesReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3250,17 +3265,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslCertificatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslCertificatesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3434,11 +3451,14 @@ def test_region_ssl_certificates_base_transport(): def test_region_ssl_certificates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslCertificatesTransport( @@ -3458,9 +3478,12 @@ def test_region_ssl_certificates_base_transport_with_credentials_file(): def test_region_ssl_certificates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_ssl_certificates.transports.RegionSslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslCertificatesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_policies.py index 313321f9a9c1..2ffb578b5a29 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_ssl_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionSslPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionSslPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionSslPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3209,8 +3214,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionSslPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3315,17 +3321,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3376,8 +3384,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3462,17 +3471,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3523,8 +3534,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionSslPolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3717,17 +3729,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3778,8 +3792,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionSslPoliciesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3848,17 +3863,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3911,8 +3928,9 @@ def test_list_available_features_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3975,18 +3993,20 @@ def test_list_available_features_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_list_available_features" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, - "post_list_available_features_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_list_available_features" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_list_available_features" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, + "post_list_available_features_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_list_available_features" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4042,8 +4062,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionSslPolicyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4236,17 +4257,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionSslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionSslPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionSslPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4464,11 +4487,14 @@ def test_region_ssl_policies_base_transport(): def test_region_ssl_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslPoliciesTransport( @@ -4488,9 +4514,12 @@ def test_region_ssl_policies_base_transport_with_credentials_file(): def test_region_ssl_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_ssl_policies.transports.RegionSslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionSslPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py index 406a495eafde..68de2a4ebf1e 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionTargetHttpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionTargetHttpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionTargetHttpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3018,8 +3023,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3128,17 +3134,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3193,8 +3202,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionTargetHttpProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3281,17 +3291,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3344,8 +3356,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3536,17 +3549,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3597,8 +3613,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionTargetHttpProxiesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3667,17 +3684,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3736,8 +3755,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3920,18 +3940,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = RegionTargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, - "post_set_url_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4126,11 +4148,14 @@ def test_region_target_http_proxies_base_transport(): def test_region_target_http_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpProxiesTransport( @@ -4150,9 +4175,12 @@ def test_region_target_http_proxies_base_transport_with_credentials_file(): def test_region_target_http_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_target_http_proxies.transports.RegionTargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py index 57c1aa7d5b86..245ae4bea7fe 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionTargetHttpsProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionTargetHttpsProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionTargetHttpsProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3900,8 +3905,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4010,17 +4016,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4075,8 +4084,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionTargetHttpsProxyRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4177,17 +4187,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4240,8 +4252,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4439,17 +4452,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4502,8 +4518,9 @@ def test_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4572,17 +4589,20 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4641,8 +4661,9 @@ def test_patch_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4844,17 +4865,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4911,8 +4935,9 @@ def test_set_ssl_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5106,18 +5131,22 @@ def test_set_ssl_certificates_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_set_ssl_certificates" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, - "post_set_ssl_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_set_ssl_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_set_ssl_certificates", + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_set_ssl_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "pre_set_ssl_certificates", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5174,8 +5203,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5358,18 +5388,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = RegionTargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, - "post_set_url_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetHttpsProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetHttpsProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5608,11 +5640,14 @@ def test_region_target_https_proxies_base_transport(): def test_region_target_https_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpsProxiesTransport( @@ -5632,9 +5667,12 @@ def test_region_target_https_proxies_base_transport_with_credentials_file(): def test_region_target_https_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_target_https_proxies.transports.RegionTargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetHttpsProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_tcp_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_tcp_proxies.py index bec67f79bd67..05ce98feaada 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_tcp_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_target_tcp_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionTargetTcpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): RegionTargetTcpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionTargetTcpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2592,8 +2597,9 @@ def test_delete_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2702,17 +2708,20 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, + "post_delete_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2767,8 +2776,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionTargetTcpProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2853,17 +2863,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2916,8 +2928,9 @@ def test_insert_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3107,17 +3120,20 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, + "post_insert_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3168,8 +3184,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionTargetTcpProxiesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3238,17 +3255,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionTargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionTargetTcpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionTargetTcpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3422,11 +3441,14 @@ def test_region_target_tcp_proxies_base_transport(): def test_region_target_tcp_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetTcpProxiesTransport( @@ -3446,9 +3468,12 @@ def test_region_target_tcp_proxies_base_transport_with_credentials_file(): def test_region_target_tcp_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_target_tcp_proxies.transports.RegionTargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionTargetTcpProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_url_maps.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_url_maps.py index a1e684b088ea..a0f53b154702 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_url_maps.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_url_maps.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionUrlMapsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( RegionUrlMapsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RegionUrlMapsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3603,8 +3608,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRegionUrlMapRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3709,17 +3715,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3770,8 +3776,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3850,17 +3857,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3909,8 +3914,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRegionUrlMapRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4272,17 +4278,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4333,8 +4339,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionUrlMapsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4403,17 +4410,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4464,8 +4469,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRegionUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4827,17 +4833,17 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4888,8 +4894,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRegionUrlMapRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5251,17 +5258,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionUrlMapsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5312,8 +5319,9 @@ def test_validate_rest_bad_request(request_type=compute.ValidateRegionUrlMapRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5648,17 +5656,19 @@ def test_validate_rest_interceptors(null_interceptor): ) client = RegionUrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_validate" - ) as post, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "post_validate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionUrlMapsRestInterceptor, "pre_validate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_validate" + ) as post, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "post_validate_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RegionUrlMapsRestInterceptor, "pre_validate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5897,11 +5907,14 @@ def test_region_url_maps_base_transport(): def test_region_url_maps_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionUrlMapsTransport( @@ -5921,9 +5934,12 @@ def test_region_url_maps_base_transport_with_credentials_file(): def test_region_url_maps_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_url_maps.transports.RegionUrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionUrlMapsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_zones.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_zones.py index ee50f6a2461b..c917e7e14f7c 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_zones.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_region_zones.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionZonesClient._get_default_mtls_endpoint(None) is None assert ( @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegionZonesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RegionZonesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1482,8 +1486,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1552,17 +1557,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionZonesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionZonesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionZonesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionZonesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionZonesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionZonesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionZonesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1669,11 +1672,14 @@ def test_region_zones_base_transport(): def test_region_zones_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionZonesTransport( @@ -1694,9 +1700,12 @@ def test_region_zones_base_transport_with_credentials_file(): def test_region_zones_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.region_zones.transports.RegionZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionZonesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_regions.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_regions.py index ee42e1a6b6e4..eb5f700ccaea 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_regions.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_regions.py @@ -114,6 +114,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RegionsClient._get_default_mtls_endpoint(None) is None assert RegionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RegionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RegionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1635,8 +1637,9 @@ def test_get_rest_bad_request(request_type=compute.GetRegionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1713,17 +1716,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RegionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RegionsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RegionsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1772,8 +1773,9 @@ def test_list_rest_bad_request(request_type=compute.ListRegionsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1840,17 +1842,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RegionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RegionsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RegionsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RegionsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RegionsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RegionsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RegionsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1980,11 +1980,14 @@ def test_regions_base_transport(): def test_regions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.regions.transports.RegionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.regions.transports.RegionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionsTransport( @@ -2005,9 +2008,12 @@ def test_regions_base_transport_with_credentials_file(): def test_regions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.regions.transports.RegionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.regions.transports.RegionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RegionsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_blocks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_blocks.py index b659daa25170..c4998cda4db7 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_blocks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_blocks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationBlocksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ReservationBlocksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationBlocksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2879,8 +2884,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationBlockRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2945,17 +2951,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3018,8 +3026,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3091,17 +3100,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3152,8 +3164,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationBlocksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3222,17 +3235,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3295,8 +3310,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3491,18 +3507,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, - "post_perform_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3560,8 +3578,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3752,17 +3771,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3820,8 +3842,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3967,18 +3990,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationBlocksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationBlocksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationBlocksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4200,11 +4225,14 @@ def test_reservation_blocks_base_transport(): def test_reservation_blocks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationBlocksTransport( @@ -4224,9 +4252,12 @@ def test_reservation_blocks_base_transport_with_credentials_file(): def test_reservation_blocks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.reservation_blocks.transports.ReservationBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationBlocksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_slots.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_slots.py index 18aabf67167e..98c93b73d20b 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_slots.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_slots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationSlotsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ReservationSlotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationSlotsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2654,8 +2659,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationSlotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2720,17 +2726,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationSlotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2793,8 +2799,9 @@ def test_get_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2989,17 +2996,19 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3054,8 +3063,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationSlotsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3128,17 +3138,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3199,8 +3211,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateReservationSlotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3411,17 +3424,19 @@ def test_update_rest_interceptors(null_interceptor): ) client = ReservationSlotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSlotsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSlotsRestInterceptor, "pre_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3595,11 +3610,14 @@ def test_reservation_slots_base_transport(): def test_reservation_slots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSlotsTransport( @@ -3619,9 +3637,12 @@ def test_reservation_slots_base_transport_with_credentials_file(): def test_reservation_slots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.reservation_slots.transports.ReservationSlotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSlotsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_sub_blocks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_sub_blocks.py index cdb04a47b793..daf7cfe60beb 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_sub_blocks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservation_sub_blocks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationSubBlocksClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ReservationSubBlocksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReservationSubBlocksClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3779,8 +3784,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationSubBlockRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3845,17 +3851,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3918,8 +3926,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3991,18 +4000,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4060,8 +4071,9 @@ def test_get_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4256,17 +4268,20 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_get_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4321,8 +4336,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationSubBlocksRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4395,17 +4411,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4468,8 +4486,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4579,18 +4598,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_perform_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4648,8 +4669,9 @@ def test_report_faulty_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4848,18 +4870,20 @@ def test_report_faulty_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_report_faulty" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_report_faulty_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_report_faulty" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_report_faulty" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_report_faulty_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_report_faulty" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4917,8 +4941,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5109,18 +5134,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5178,8 +5205,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5325,18 +5353,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationSubBlocksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationSubBlocksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationSubBlocksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5600,11 +5630,14 @@ def test_reservation_sub_blocks_base_transport(): def test_reservation_sub_blocks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSubBlocksTransport( @@ -5624,9 +5657,12 @@ def test_reservation_sub_blocks_base_transport_with_credentials_file(): def test_reservation_sub_blocks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.reservation_sub_blocks.transports.ReservationSubBlocksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationSubBlocksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservations.py index 22ade1f96a69..75cf3999215b 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_reservations.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReservationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ReservationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ReservationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4770,8 +4775,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4842,17 +4848,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4905,8 +4913,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5011,17 +5020,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5072,8 +5081,9 @@ def test_get_rest_bad_request(request_type=compute.GetReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5170,17 +5180,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ReservationsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5231,8 +5239,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5299,17 +5308,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5360,8 +5371,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5633,17 +5645,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5694,8 +5706,9 @@ def test_list_rest_bad_request(request_type=compute.ListReservationsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5764,17 +5777,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ReservationsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5827,8 +5838,9 @@ def test_perform_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6018,17 +6030,20 @@ def test_perform_maintenance_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_perform_maintenance" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_perform_maintenance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_perform_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_perform_maintenance" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, + "post_perform_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_perform_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6079,8 +6094,9 @@ def test_resize_rest_bad_request(request_type=compute.ResizeReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6263,17 +6279,17 @@ def test_resize_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_resize" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_resize_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_resize" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_resize" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_resize_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_resize") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6326,8 +6342,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6510,17 +6527,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6573,8 +6592,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6715,18 +6735,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReservationsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6779,8 +6801,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateReservationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7052,17 +7075,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = ReservationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReservationsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.ReservationsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ReservationsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.ReservationsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ReservationsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7387,11 +7410,14 @@ def test_reservations_base_transport(): def test_reservations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationsTransport( @@ -7411,9 +7437,12 @@ def test_reservations_base_transport_with_credentials_file(): def test_reservations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.reservations.transports.ReservationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReservationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_resource_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_resource_policies.py index 0bffe4983cd1..a493fd7e2768 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_resource_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_resource_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ResourcePoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ResourcePoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ResourcePoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3915,8 +3920,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3989,17 +3995,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4059,8 +4068,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteResourcePolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4169,17 +4179,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4234,8 +4246,9 @@ def test_get_rest_bad_request(request_type=compute.GetResourcePolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4316,17 +4329,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ResourcePoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4379,8 +4392,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4447,17 +4461,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4508,8 +4525,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertResourcePolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4758,17 +4776,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4819,8 +4839,9 @@ def test_list_rest_bad_request(request_type=compute.ListResourcePoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4891,17 +4912,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4956,8 +4979,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchResourcePolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5210,17 +5234,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5273,8 +5299,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5457,17 +5484,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5520,8 +5550,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5662,18 +5693,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ResourcePoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ResourcePoliciesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ResourcePoliciesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5956,11 +5989,14 @@ def test_resource_policies_base_transport(): def test_resource_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ResourcePoliciesTransport( @@ -5980,9 +6016,12 @@ def test_resource_policies_base_transport_with_credentials_file(): def test_resource_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.resource_policies.transports.ResourcePoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ResourcePoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routers.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routers.py index 759eabba6d2f..7d79ec5e1922 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routers.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routers.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RoutersClient._get_default_mtls_endpoint(None) is None assert RoutersClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RoutersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RoutersClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -6636,8 +6638,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6706,17 +6709,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6769,8 +6774,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6873,17 +6879,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6934,8 +6938,9 @@ def test_delete_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7038,17 +7043,19 @@ def test_delete_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_delete_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_delete_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_delete_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_delete_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7099,8 +7106,9 @@ def test_get_rest_bad_request(request_type=compute.GetRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7177,17 +7185,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7238,8 +7244,9 @@ def test_get_nat_ip_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7297,17 +7304,19 @@ def test_get_nat_ip_info_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_ip_info" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_ip_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_nat_ip_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_ip_info" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_ip_info_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_nat_ip_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7360,8 +7369,9 @@ def test_get_nat_mapping_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7428,17 +7438,19 @@ def test_get_nat_mapping_info_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_mapping_info" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_nat_mapping_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_nat_mapping_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_mapping_info" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_nat_mapping_info_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_nat_mapping_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7493,8 +7505,9 @@ def test_get_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7552,17 +7565,19 @@ def test_get_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7620,8 +7635,9 @@ def test_get_router_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7682,17 +7698,19 @@ def test_get_router_status_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_router_status" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_get_router_status_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_get_router_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_router_status" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_get_router_status_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_get_router_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7745,8 +7763,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8053,17 +8072,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8112,8 +8129,9 @@ def test_list_rest_bad_request(request_type=compute.ListRoutersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8180,17 +8198,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8241,8 +8257,9 @@ def test_list_bgp_routes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8313,17 +8330,19 @@ def test_list_bgp_routes_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_bgp_routes" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_bgp_routes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list_bgp_routes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_bgp_routes" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_bgp_routes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_list_bgp_routes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8378,8 +8397,9 @@ def test_list_route_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8450,17 +8470,19 @@ def test_list_route_policies_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_route_policies" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_list_route_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_list_route_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_route_policies" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_list_route_policies_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_list_route_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8513,8 +8535,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8821,17 +8844,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8882,8 +8903,9 @@ def test_patch_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9077,17 +9099,19 @@ def test_patch_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_patch_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_patch_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_patch_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_patch_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9138,8 +9162,9 @@ def test_preview_rest_bad_request(request_type=compute.PreviewRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9401,17 +9426,15 @@ def test_preview_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_preview" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_preview_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_preview" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_preview") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_preview_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_preview") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9462,8 +9485,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9770,17 +9794,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutersRestInterceptor, "post_update") as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutersRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9831,8 +9853,9 @@ def test_update_route_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10026,17 +10049,19 @@ def test_update_route_policy_rest_interceptors(null_interceptor): ) client = RoutersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_route_policy" - ) as post, mock.patch.object( - transports.RoutersRestInterceptor, "post_update_route_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutersRestInterceptor, "pre_update_route_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_route_policy" + ) as post, + mock.patch.object( + transports.RoutersRestInterceptor, "post_update_route_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutersRestInterceptor, "pre_update_route_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10495,11 +10520,14 @@ def test_routers_base_transport(): def test_routers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.routers.transports.RoutersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.routers.transports.RoutersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutersTransport( @@ -10519,9 +10547,12 @@ def test_routers_base_transport_with_credentials_file(): def test_routers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.routers.transports.RoutersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.routers.transports.RoutersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutersTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routes.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routes.py index 26ac4a4d72fb..4bc50393ec3f 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routes.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_routes.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RoutesClient._get_default_mtls_endpoint(None) is None assert RoutesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RoutesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert RoutesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -2625,8 +2627,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2729,17 +2732,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2788,8 +2789,9 @@ def test_get_rest_bad_request(request_type=compute.GetRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2899,17 +2901,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2958,8 +2958,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3166,17 +3167,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3225,8 +3224,9 @@ def test_list_rest_bad_request(request_type=compute.ListRoutesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3293,17 +3293,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RoutesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RoutesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3354,8 +3352,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3494,17 +3493,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = RoutesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RoutesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.RoutesRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RoutesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RoutesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.RoutesRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RoutesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3703,11 +3704,14 @@ def test_routes_base_transport(): def test_routes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.routes.transports.RoutesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.routes.transports.RoutesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutesTransport( @@ -3727,9 +3731,12 @@ def test_routes_base_transport_with_credentials_file(): def test_routes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.routes.transports.RoutesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.routes.transports.RoutesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RoutesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_security_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_security_policies.py index 3fcf0e58a374..187139065449 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_security_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_security_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SecurityPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): SecurityPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SecurityPoliciesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5316,8 +5321,9 @@ def test_add_rule_rest_bad_request(request_type=compute.AddRuleSecurityPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5585,17 +5591,19 @@ def test_add_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_add_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_add_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_add_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_add_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_add_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_add_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5648,8 +5656,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5722,17 +5731,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5788,8 +5800,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSecurityPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5894,17 +5907,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5955,8 +5970,9 @@ def test_get_rest_bad_request(request_type=compute.GetSecurityPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6041,17 +6057,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SecurityPoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6102,8 +6118,9 @@ def test_get_rule_rest_bad_request(request_type=compute.GetRuleSecurityPolicyReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6174,17 +6191,19 @@ def test_get_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_get_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_get_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_get_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_get_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6235,8 +6254,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSecurityPolicyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6594,17 +6614,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6655,8 +6677,9 @@ def test_list_rest_bad_request(request_type=compute.ListSecurityPoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6723,17 +6746,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6786,8 +6811,9 @@ def test_list_preconfigured_expression_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6853,20 +6879,22 @@ def test_list_preconfigured_expression_sets_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets", - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "post_list_preconfigured_expression_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, - "pre_list_preconfigured_expression_sets", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets", + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "post_list_preconfigured_expression_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, + "pre_list_preconfigured_expression_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6926,8 +6954,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSecurityPolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7285,17 +7314,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7348,8 +7379,9 @@ def test_patch_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7617,17 +7649,19 @@ def test_patch_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_patch_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_patch_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_patch_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_patch_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7680,8 +7714,9 @@ def test_remove_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7786,17 +7821,19 @@ def test_remove_rule_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_remove_rule" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_remove_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_remove_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_remove_rule" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_remove_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_remove_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7849,8 +7886,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8034,17 +8072,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = SecurityPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SecurityPoliciesRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SecurityPoliciesRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8388,11 +8428,14 @@ def test_security_policies_base_transport(): def test_security_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecurityPoliciesTransport( @@ -8412,9 +8455,12 @@ def test_security_policies_base_transport_with_credentials_file(): def test_security_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.security_policies.transports.SecurityPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecurityPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_service_attachments.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_service_attachments.py index e103745af769..364b202e41c2 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_service_attachments.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_service_attachments.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServiceAttachmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): ServiceAttachmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ServiceAttachmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3945,8 +3950,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4017,18 +4023,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4088,8 +4096,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteServiceAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4198,17 +4207,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4263,8 +4274,9 @@ def test_get_rest_bad_request(request_type=compute.GetServiceAttachmentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4363,17 +4375,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4426,8 +4440,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4494,18 +4509,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4556,8 +4573,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertServiceAttachmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4778,17 +4796,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4839,8 +4859,9 @@ def test_list_rest_bad_request(request_type=compute.ListServiceAttachmentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4909,17 +4930,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4976,8 +4999,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchServiceAttachmentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5202,17 +5226,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5265,8 +5291,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5449,18 +5476,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5513,8 +5542,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5655,18 +5685,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ServiceAttachmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServiceAttachmentsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServiceAttachmentsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5949,11 +5981,14 @@ def test_service_attachments_base_transport(): def test_service_attachments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceAttachmentsTransport( @@ -5973,9 +6008,12 @@ def test_service_attachments_base_transport_with_credentials_file(): def test_service_attachments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.service_attachments.transports.ServiceAttachmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceAttachmentsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshot_settings_service.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshot_settings_service.py index 1b8ce0216682..d9227617b885 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshot_settings_service.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshot_settings_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnapshotSettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): SnapshotSettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SnapshotSettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1899,8 +1904,9 @@ def test_get_rest_bad_request(request_type=compute.GetSnapshotSettingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1960,17 +1966,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = SnapshotSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2021,8 +2029,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSnapshotSettingRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2203,17 +2212,20 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SnapshotSettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotSettingsServiceRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, + "post_patch_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotSettingsServiceRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2345,11 +2357,14 @@ def test_snapshot_settings_service_base_transport(): def test_snapshot_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotSettingsServiceTransport( @@ -2369,9 +2384,12 @@ def test_snapshot_settings_service_base_transport_with_credentials_file(): def test_snapshot_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.snapshot_settings_service.transports.SnapshotSettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotSettingsServiceTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshots.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshots.py index 106299268893..8840e80987a3 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshots.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_snapshots.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnapshotsClient._get_default_mtls_endpoint(None) is None assert SnapshotsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SnapshotsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SnapshotsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3437,8 +3441,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3541,17 +3546,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3600,8 +3603,9 @@ def test_get_rest_bad_request(request_type=compute.GetSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3733,17 +3737,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3794,8 +3796,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3860,17 +3863,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3921,8 +3926,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSnapshotRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4138,17 +4144,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4197,8 +4201,9 @@ def test_list_rest_bad_request(request_type=compute.ListSnapshotsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4265,17 +4270,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SnapshotsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4326,8 +4329,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4508,17 +4512,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4569,8 +4575,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsSnapshotReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4752,17 +4759,17 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SnapshotsRestInterceptor, "pre_set_labels") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4815,8 +4822,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4955,17 +4963,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SnapshotsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SnapshotsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SnapshotsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5227,11 +5238,14 @@ def test_snapshots_base_transport(): def test_snapshots_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotsTransport( @@ -5251,9 +5265,12 @@ def test_snapshots_base_transport_with_credentials_file(): def test_snapshots_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.snapshots.transports.SnapshotsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_certificates.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_certificates.py index 487b993b2e1e..c46683416d9d 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_certificates.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_certificates.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SslCertificatesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( SslCertificatesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SslCertificatesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2768,8 +2773,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2840,17 +2846,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2906,8 +2915,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSslCertificateReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3012,17 +3022,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3073,8 +3085,9 @@ def test_get_rest_bad_request(request_type=compute.GetSslCertificateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3159,17 +3172,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslCertificatesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3220,8 +3233,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSslCertificateReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3423,17 +3437,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3484,8 +3500,9 @@ def test_list_rest_bad_request(request_type=compute.ListSslCertificatesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3554,17 +3571,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = SslCertificatesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SslCertificatesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslCertificatesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.SslCertificatesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslCertificatesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3759,11 +3776,14 @@ def test_ssl_certificates_base_transport(): def test_ssl_certificates_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslCertificatesTransport( @@ -3783,9 +3803,12 @@ def test_ssl_certificates_base_transport_with_credentials_file(): def test_ssl_certificates_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.ssl_certificates.transports.SslCertificatesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslCertificatesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_policies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_policies.py index a47b28d346b0..0d6684829cb9 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_policies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_ssl_policies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SslPoliciesClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SslPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SslPoliciesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3341,8 +3345,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3415,17 +3420,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3478,8 +3485,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3584,17 +3592,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3643,8 +3649,9 @@ def test_get_rest_bad_request(request_type=compute.GetSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3729,17 +3736,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3788,8 +3793,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3982,17 +3988,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4041,8 +4045,9 @@ def test_list_rest_bad_request(request_type=compute.ListSslPoliciesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4111,17 +4116,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4172,8 +4175,9 @@ def test_list_available_features_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4236,18 +4240,20 @@ def test_list_available_features_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_list_available_features" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, - "post_list_available_features_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_list_available_features" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_list_available_features" + ) as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, + "post_list_available_features_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "pre_list_available_features" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4303,8 +4309,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSslPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4497,17 +4504,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SslPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SslPoliciesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SslPoliciesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SslPoliciesRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.SslPoliciesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SslPoliciesRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4744,11 +4749,14 @@ def test_ssl_policies_base_transport(): def test_ssl_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslPoliciesTransport( @@ -4768,9 +4776,12 @@ def test_ssl_policies_base_transport_with_credentials_file(): def test_ssl_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.ssl_policies.transports.SslPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SslPoliciesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pool_types.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pool_types.py index a51776f9366d..cd241486f156 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pool_types.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pool_types.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert StoragePoolTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): StoragePoolTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + StoragePoolTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2004,8 +2009,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2074,17 +2080,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = StoragePoolTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2144,8 +2153,9 @@ def test_get_rest_bad_request(request_type=compute.GetStoragePoolTypeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2242,17 +2252,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = StoragePoolTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolTypesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2303,8 +2313,9 @@ def test_list_rest_bad_request(request_type=compute.ListStoragePoolTypesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2373,17 +2384,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = StoragePoolTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolTypesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolTypesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2538,11 +2551,14 @@ def test_storage_pool_types_base_transport(): def test_storage_pool_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolTypesTransport( @@ -2563,9 +2579,12 @@ def test_storage_pool_types_base_transport_with_credentials_file(): def test_storage_pool_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.storage_pool_types.transports.StoragePoolTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolTypesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pools.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pools.py index e783ceeaae6f..9709e0cfd239 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pools.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_storage_pools.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert StoragePoolsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert StoragePoolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + StoragePoolsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4162,8 +4167,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4236,17 +4242,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4299,8 +4307,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4405,17 +4414,17 @@ def test_delete_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4466,8 +4475,9 @@ def test_get_rest_bad_request(request_type=compute.GetStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4562,17 +4572,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.StoragePoolsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4623,8 +4631,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4691,17 +4700,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4752,8 +4763,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4969,17 +4981,17 @@ def test_insert_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5030,8 +5042,9 @@ def test_list_rest_bad_request(request_type=compute.ListStoragePoolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5104,17 +5117,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.StoragePoolsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5165,8 +5176,9 @@ def test_list_disks_rest_bad_request(request_type=compute.ListDisksStoragePoolsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5239,17 +5251,19 @@ def test_list_disks_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list_disks" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_list_disks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_list_disks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_list_disks" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_list_disks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_list_disks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5304,8 +5318,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5488,17 +5503,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5551,8 +5568,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5693,18 +5711,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5757,8 +5777,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateStoragePoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5974,17 +5995,17 @@ def test_update_rest_interceptors(null_interceptor): ) client = StoragePoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.StoragePoolsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.StoragePoolsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_update" + ) as post, + mock.patch.object( + transports.StoragePoolsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.StoragePoolsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6286,11 +6307,14 @@ def test_storage_pools_base_transport(): def test_storage_pools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolsTransport( @@ -6310,9 +6334,12 @@ def test_storage_pools_base_transport_with_credentials_file(): def test_storage_pools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.storage_pools.transports.StoragePoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.StoragePoolsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_subnetworks.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_subnetworks.py index 6a2fdaa727c6..2b9e9e0b8e11 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_subnetworks.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_subnetworks.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SubnetworksClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SubnetworksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SubnetworksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -5028,8 +5032,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5100,17 +5105,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5163,8 +5170,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5269,17 +5277,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5332,8 +5338,9 @@ def test_expand_ip_cidr_range_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5523,17 +5530,20 @@ def test_expand_ip_cidr_range_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_expand_ip_cidr_range" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_expand_ip_cidr_range_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_expand_ip_cidr_range" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_expand_ip_cidr_range" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, + "post_expand_ip_cidr_range_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_expand_ip_cidr_range" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5584,8 +5594,9 @@ def test_get_rest_bad_request(request_type=compute.GetSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5712,17 +5723,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_get") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5773,8 +5782,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5841,17 +5851,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5902,8 +5914,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6143,17 +6156,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6204,8 +6215,9 @@ def test_list_rest_bad_request(request_type=compute.ListSubnetworksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6274,17 +6286,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_list") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6335,8 +6345,9 @@ def test_list_usable_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6407,17 +6418,19 @@ def test_list_usable_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list_usable" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_list_usable_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_list_usable" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_list_usable" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_list_usable_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_list_usable" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6473,8 +6486,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchSubnetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6714,17 +6728,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.SubnetworksRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SubnetworksRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6775,8 +6787,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6959,17 +6972,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7022,8 +7037,9 @@ def test_set_private_ip_google_access_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7213,18 +7229,20 @@ def test_set_private_ip_google_access_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_set_private_ip_google_access" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, - "post_set_private_ip_google_access_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_set_private_ip_google_access" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_set_private_ip_google_access" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, + "post_set_private_ip_google_access_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_set_private_ip_google_access" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7277,8 +7295,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7419,17 +7438,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = SubnetworksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.SubnetworksRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SubnetworksRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SubnetworksRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.SubnetworksRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SubnetworksRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7779,11 +7801,14 @@ def test_subnetworks_base_transport(): def test_subnetworks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubnetworksTransport( @@ -7803,9 +7828,12 @@ def test_subnetworks_base_transport_with_credentials_file(): def test_subnetworks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.subnetworks.transports.SubnetworksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SubnetworksTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py index 118d9c0b2ca5..60081cccbe96 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetGrpcProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetGrpcProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetGrpcProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2912,8 +2917,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetGrpcProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3018,17 +3024,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3079,8 +3087,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetGrpcProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3161,17 +3170,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3222,8 +3233,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetGrpcProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3413,17 +3425,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3474,8 +3488,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetGrpcProxiesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3544,17 +3559,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3607,8 +3624,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchTargetGrpcProxyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3798,17 +3816,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = TargetGrpcProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetGrpcProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetGrpcProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4003,11 +4023,14 @@ def test_target_grpc_proxies_base_transport(): def test_target_grpc_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetGrpcProxiesTransport( @@ -4027,9 +4050,12 @@ def test_target_grpc_proxies_base_transport_with_credentials_file(): def test_target_grpc_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_grpc_proxies.transports.TargetGrpcProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetGrpcProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_http_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_http_proxies.py index af8752893ccc..51fde53402cc 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_http_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_http_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetHttpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetHttpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetHttpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3596,8 +3601,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3668,18 +3674,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3735,8 +3743,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetHttpProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3841,17 +3850,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3902,8 +3913,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetHttpProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3986,17 +3998,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4047,8 +4061,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetHttpProxyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4239,17 +4254,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4300,8 +4317,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetHttpProxiesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4370,17 +4388,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4433,8 +4453,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchTargetHttpProxyRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4625,17 +4646,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4688,8 +4711,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4868,17 +4892,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = TargetHttpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "post_set_url_map_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5115,11 +5142,14 @@ def test_target_http_proxies_base_transport(): def test_target_http_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpProxiesTransport( @@ -5139,9 +5169,12 @@ def test_target_http_proxies_base_transport_with_credentials_file(): def test_target_http_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_http_proxies.transports.TargetHttpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_https_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_https_proxies.py index 4e7fe771bf29..32409be60fe5 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_https_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_https_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetHttpsProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetHttpsProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetHttpsProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -5272,8 +5277,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5344,18 +5350,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5411,8 +5419,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetHttpsProxyRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5517,17 +5526,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5578,8 +5589,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetHttpsProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5676,17 +5688,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5737,8 +5751,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetHttpsProxyRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5936,17 +5951,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5997,8 +6014,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetHttpsProxiesReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6067,17 +6085,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6130,8 +6150,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchTargetHttpsProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6329,17 +6350,19 @@ def test_patch_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_patch" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_patch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6392,8 +6415,9 @@ def test_set_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6583,18 +6607,20 @@ def test_set_certificate_map_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_certificate_map" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_certificate_map" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6647,8 +6673,9 @@ def test_set_quic_override_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6838,18 +6865,20 @@ def test_set_quic_override_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_quic_override" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_quic_override_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_quic_override" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_quic_override" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_quic_override_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_quic_override" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6902,8 +6931,9 @@ def test_set_ssl_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7093,18 +7123,20 @@ def test_set_ssl_certificates_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_certificates" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_ssl_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_certificates" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_ssl_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_certificates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7157,8 +7189,9 @@ def test_set_ssl_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7339,18 +7372,20 @@ def test_set_ssl_policy_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_policy" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, - "post_set_ssl_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_ssl_policy" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_ssl_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_ssl_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7403,8 +7438,9 @@ def test_set_url_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7583,17 +7619,20 @@ def test_set_url_map_rest_interceptors(null_interceptor): ) client = TargetHttpsProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_url_map" - ) as post, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "post_set_url_map_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetHttpsProxiesRestInterceptor, "pre_set_url_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "post_set_url_map" + ) as post, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, + "post_set_url_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetHttpsProxiesRestInterceptor, "pre_set_url_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7920,11 +7959,14 @@ def test_target_https_proxies_base_transport(): def test_target_https_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpsProxiesTransport( @@ -7944,9 +7986,12 @@ def test_target_https_proxies_base_transport_with_credentials_file(): def test_target_https_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_https_proxies.transports.TargetHttpsProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetHttpsProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_instances.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_instances.py index 27dd78f886aa..bcba6cea7696 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_instances.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_instances.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetInstancesClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( TargetInstancesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetInstancesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3483,8 +3488,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3555,17 +3561,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3625,8 +3634,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetInstanceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3735,17 +3745,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3800,8 +3812,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetInstanceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3888,17 +3901,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetInstancesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3949,8 +3962,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetInstanceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4139,17 +4153,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4200,8 +4216,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetInstancesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4270,17 +4287,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetInstancesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4337,8 +4354,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4525,18 +4543,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, - "post_set_security_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4589,8 +4609,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4731,18 +4752,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetInstancesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetInstancesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetInstancesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetInstancesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetInstancesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetInstancesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4985,11 +5008,14 @@ def test_target_instances_base_transport(): def test_target_instances_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetInstancesTransport( @@ -5009,9 +5035,12 @@ def test_target_instances_base_transport_with_credentials_file(): def test_target_instances_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_instances.transports.TargetInstancesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetInstancesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_pools.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_pools.py index 572b2d531b3f..66904508e2b1 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_pools.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_pools.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetPoolsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TargetPoolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TargetPoolsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -5859,8 +5863,9 @@ def test_add_health_check_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6050,17 +6055,19 @@ def test_add_health_check_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_health_check" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_health_check_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_add_health_check" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_health_check" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_health_check_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_add_health_check" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6113,8 +6120,9 @@ def test_add_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6304,17 +6312,19 @@ def test_add_instance_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_instance" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_add_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_add_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_instance" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_add_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_add_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6367,8 +6377,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6439,17 +6450,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6502,8 +6515,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetPoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6608,17 +6622,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6669,8 +6681,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetPoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6757,17 +6770,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6816,8 +6827,9 @@ def test_get_health_rest_bad_request(request_type=compute.GetHealthTargetPoolReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6954,17 +6966,19 @@ def test_get_health_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get_health" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_get_health_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_get_health" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_get_health" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_get_health_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_get_health" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7017,8 +7031,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetPoolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7207,17 +7222,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7268,8 +7281,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetPoolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7338,17 +7352,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.TargetPoolsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetPoolsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7399,8 +7411,9 @@ def test_remove_health_check_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7590,17 +7603,20 @@ def test_remove_health_check_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_health_check" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_health_check_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_remove_health_check" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_remove_health_check" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, + "post_remove_health_check_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_remove_health_check" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7653,8 +7669,9 @@ def test_remove_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7844,17 +7861,19 @@ def test_remove_instance_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_instance" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_remove_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_remove_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_remove_instance" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_remove_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_remove_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7905,8 +7924,9 @@ def test_set_backup_rest_bad_request(request_type=compute.SetBackupTargetPoolReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8085,17 +8105,19 @@ def test_set_backup_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_backup" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_set_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_set_backup" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_set_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_set_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8148,8 +8170,9 @@ def test_set_security_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8332,17 +8355,20 @@ def test_set_security_policy_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_security_policy" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_set_security_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_set_security_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_set_security_policy" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, + "post_set_security_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_set_security_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8395,8 +8421,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8537,17 +8564,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetPoolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetPoolsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetPoolsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetPoolsRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetPoolsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8918,11 +8948,14 @@ def test_target_pools_base_transport(): def test_target_pools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetPoolsTransport( @@ -8942,9 +8975,12 @@ def test_target_pools_base_transport_with_credentials_file(): def test_target_pools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_pools.transports.TargetPoolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetPoolsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py index e600835d4eef..7f764f89105e 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetSslProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetSslProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetSslProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -4786,8 +4791,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetSslProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4892,17 +4898,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4953,8 +4961,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetSslProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5037,17 +5046,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetSslProxiesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5098,8 +5107,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetSslProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5290,17 +5300,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5351,8 +5363,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetSslProxiesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5421,17 +5434,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5484,8 +5499,9 @@ def test_set_backend_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5675,18 +5691,20 @@ def test_set_backend_service_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_backend_service" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_backend_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_backend_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_backend_service" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_backend_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_backend_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5739,8 +5757,9 @@ def test_set_certificate_map_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5930,18 +5949,20 @@ def test_set_certificate_map_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_certificate_map" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_certificate_map_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_certificate_map" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_certificate_map" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_certificate_map_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_certificate_map" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5994,8 +6015,9 @@ def test_set_proxy_header_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6185,18 +6207,20 @@ def test_set_proxy_header_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_proxy_header" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_proxy_header_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_proxy_header" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_proxy_header" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_proxy_header_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_proxy_header" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6249,8 +6273,9 @@ def test_set_ssl_certificates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6440,18 +6465,20 @@ def test_set_ssl_certificates_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_ssl_certificates" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_set_ssl_certificates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_certificates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_ssl_certificates" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_ssl_certificates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_certificates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6504,8 +6531,9 @@ def test_set_ssl_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6686,17 +6714,20 @@ def test_set_ssl_policy_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_ssl_policy" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_set_ssl_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_set_ssl_policy" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_set_ssl_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_set_ssl_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6749,8 +6780,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6891,18 +6923,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetSslProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetSslProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetSslProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7212,11 +7246,14 @@ def test_target_ssl_proxies_base_transport(): def test_target_ssl_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetSslProxiesTransport( @@ -7236,9 +7273,12 @@ def test_target_ssl_proxies_base_transport_with_credentials_file(): def test_target_ssl_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_ssl_proxies.transports.TargetSslProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetSslProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py index 630e4514e4c7..d6a8115c1655 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetTcpProxiesClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetTcpProxiesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetTcpProxiesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3814,8 +3819,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3886,17 +3892,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3952,8 +3961,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetTcpProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4058,17 +4068,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4119,8 +4131,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetTcpProxyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4201,17 +4214,17 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.TargetTcpProxiesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4262,8 +4275,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetTcpProxyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4453,17 +4467,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4514,8 +4530,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetTcpProxiesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4584,17 +4601,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4647,8 +4666,9 @@ def test_set_backend_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4838,18 +4858,20 @@ def test_set_backend_service_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_set_backend_service" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, - "post_set_backend_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_set_backend_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_set_backend_service" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_set_backend_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_set_backend_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4902,8 +4924,9 @@ def test_set_proxy_header_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5093,18 +5116,20 @@ def test_set_proxy_header_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_set_proxy_header" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, - "post_set_proxy_header_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_set_proxy_header" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_set_proxy_header" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_set_proxy_header_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_set_proxy_header" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5157,8 +5182,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5299,18 +5325,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = TargetTcpProxiesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetTcpProxiesRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetTcpProxiesRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5574,11 +5602,14 @@ def test_target_tcp_proxies_base_transport(): def test_target_tcp_proxies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetTcpProxiesTransport( @@ -5598,9 +5629,12 @@ def test_target_tcp_proxies_base_transport_with_credentials_file(): def test_target_tcp_proxies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_tcp_proxies.transports.TargetTcpProxiesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetTcpProxiesTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py index 1a3897ddc445..19af493fc77b 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TargetVpnGatewaysClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TargetVpnGatewaysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TargetVpnGatewaysClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -3278,8 +3283,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3350,18 +3356,20 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, - "post_aggregated_list_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, + "post_aggregated_list_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3421,8 +3429,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteTargetVpnGatewayRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3531,17 +3540,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3596,8 +3607,9 @@ def test_get_rest_bad_request(request_type=compute.GetTargetVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3686,17 +3698,19 @@ def test_get_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_get" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_get" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3747,8 +3761,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertTargetVpnGatewayRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3942,17 +3957,19 @@ def test_insert_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_insert" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_insert" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4003,8 +4020,9 @@ def test_list_rest_bad_request(request_type=compute.ListTargetVpnGatewaysRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4073,17 +4091,19 @@ def test_list_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4138,8 +4158,9 @@ def test_set_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4323,17 +4344,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = TargetVpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TargetVpnGatewaysRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TargetVpnGatewaysRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4549,11 +4572,14 @@ def test_target_vpn_gateways_base_transport(): def test_target_vpn_gateways_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetVpnGatewaysTransport( @@ -4573,9 +4599,12 @@ def test_target_vpn_gateways_base_transport_with_credentials_file(): def test_target_vpn_gateways_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.target_vpn_gateways.transports.TargetVpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TargetVpnGatewaysTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_url_maps.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_url_maps.py index cb8416aeff30..d812da4263e2 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_url_maps.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_url_maps.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UrlMapsClient._get_default_mtls_endpoint(None) is None assert UrlMapsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert UrlMapsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert UrlMapsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -4333,8 +4335,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4403,17 +4406,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UrlMapsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4466,8 +4471,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4570,17 +4576,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4629,8 +4633,9 @@ def test_get_rest_bad_request(request_type=compute.GetUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4707,17 +4712,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4766,8 +4769,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5127,17 +5131,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5188,8 +5190,9 @@ def test_invalidate_cache_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5372,17 +5375,19 @@ def test_invalidate_cache_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_invalidate_cache" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_invalidate_cache_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_invalidate_cache" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_invalidate_cache" + ) as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_invalidate_cache_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UrlMapsRestInterceptor, "pre_invalidate_cache" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5433,8 +5438,9 @@ def test_list_rest_bad_request(request_type=compute.ListUrlMapsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5501,17 +5507,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5560,8 +5564,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5921,17 +5926,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5982,8 +5985,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6122,17 +6126,19 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_test_iam_permissions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.UrlMapsRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6185,8 +6191,9 @@ def test_update_rest_bad_request(request_type=compute.UpdateUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6546,17 +6553,15 @@ def test_update_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_update" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_update_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_update") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_update_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_update") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6605,8 +6610,9 @@ def test_validate_rest_bad_request(request_type=compute.ValidateUrlMapRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6938,17 +6944,15 @@ def test_validate_rest_interceptors(null_interceptor): ) client = UrlMapsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_validate" - ) as post, mock.patch.object( - transports.UrlMapsRestInterceptor, "post_validate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.UrlMapsRestInterceptor, "pre_validate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.UrlMapsRestInterceptor, "post_validate") as post, + mock.patch.object( + transports.UrlMapsRestInterceptor, "post_validate_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.UrlMapsRestInterceptor, "pre_validate") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7250,11 +7254,14 @@ def test_url_maps_base_transport(): def test_url_maps_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UrlMapsTransport( @@ -7274,9 +7281,12 @@ def test_url_maps_base_transport_with_credentials_file(): def test_url_maps_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.url_maps.transports.UrlMapsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UrlMapsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_gateways.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_gateways.py index 1eb2d58c6ac2..c34b9ce000d5 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_gateways.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_gateways.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VpnGatewaysClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VpnGatewaysClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + VpnGatewaysClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3641,8 +3645,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3713,17 +3718,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3776,8 +3783,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3882,17 +3890,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3943,8 +3949,9 @@ def test_get_rest_bad_request(request_type=compute.GetVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4027,17 +4034,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_get") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4086,8 +4091,9 @@ def test_get_status_rest_bad_request(request_type=compute.GetStatusVpnGatewayReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4147,17 +4153,19 @@ def test_get_status_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get_status" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_get_status_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_get_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_get_status" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_get_status_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_get_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4213,8 +4221,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertVpnGatewayRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4411,17 +4420,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4472,8 +4479,9 @@ def test_list_rest_bad_request(request_type=compute.ListVpnGatewaysRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4542,17 +4550,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "post_list") as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnGatewaysRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4601,8 +4607,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsVpnGatewayReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4786,17 +4793,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4849,8 +4858,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4991,17 +5001,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = VpnGatewaysClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnGatewaysRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.VpnGatewaysRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5263,11 +5276,14 @@ def test_vpn_gateways_base_transport(): def test_vpn_gateways_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnGatewaysTransport( @@ -5287,9 +5303,12 @@ def test_vpn_gateways_base_transport_with_credentials_file(): def test_vpn_gateways_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.vpn_gateways.transports.VpnGatewaysTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnGatewaysTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_tunnels.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_tunnels.py index 5c6e37b419ca..a9afc1d23662 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_tunnels.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_vpn_tunnels.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VpnTunnelsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VpnTunnelsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + VpnTunnelsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3220,8 +3224,9 @@ def test_aggregated_list_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3292,17 +3297,19 @@ def test_aggregated_list_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_aggregated_list" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_aggregated_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_aggregated_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_aggregated_list" + ) as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_aggregated_list_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "pre_aggregated_list" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3355,8 +3362,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteVpnTunnelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3461,17 +3469,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3520,8 +3526,9 @@ def test_get_rest_bad_request(request_type=compute.GetVpnTunnelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3628,17 +3635,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3687,8 +3692,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertVpnTunnelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3906,17 +3912,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3965,8 +3969,9 @@ def test_list_rest_bad_request(request_type=compute.ListVpnTunnelsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4035,17 +4040,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VpnTunnelsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4094,8 +4097,9 @@ def test_set_labels_rest_bad_request(request_type=compute.SetLabelsVpnTunnelRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4279,17 +4283,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = VpnTunnelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VpnTunnelsRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VpnTunnelsRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4505,11 +4511,14 @@ def test_vpn_tunnels_base_transport(): def test_vpn_tunnels_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnTunnelsTransport( @@ -4529,9 +4538,12 @@ def test_vpn_tunnels_base_transport_with_credentials_file(): def test_vpn_tunnels_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.vpn_tunnels.transports.VpnTunnelsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VpnTunnelsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_wire_groups.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_wire_groups.py index f62ab05dc1f5..5a80f6a120f7 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_wire_groups.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_wire_groups.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WireGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert WireGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + WireGroupsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -2965,8 +2969,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3075,17 +3080,15 @@ def test_delete_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_delete") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_delete") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3138,8 +3141,9 @@ def test_get_rest_bad_request(request_type=compute.GetWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3220,17 +3224,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3279,8 +3281,9 @@ def test_insert_rest_bad_request(request_type=compute.InsertWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3477,17 +3480,15 @@ def test_insert_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_insert" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_insert_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_insert" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_insert") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_insert_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_insert") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3536,8 +3537,9 @@ def test_list_rest_bad_request(request_type=compute.ListWireGroupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3610,17 +3612,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_list") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3673,8 +3673,9 @@ def test_patch_rest_bad_request(request_type=compute.PatchWireGroupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3875,17 +3876,15 @@ def test_patch_rest_interceptors(null_interceptor): ) client = WireGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_patch" - ) as post, mock.patch.object( - transports.WireGroupsRestInterceptor, "post_patch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WireGroupsRestInterceptor, "pre_patch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.WireGroupsRestInterceptor, "post_patch") as post, + mock.patch.object( + transports.WireGroupsRestInterceptor, "post_patch_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WireGroupsRestInterceptor, "pre_patch") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4078,11 +4077,14 @@ def test_wire_groups_base_transport(): def test_wire_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WireGroupsTransport( @@ -4102,9 +4104,12 @@ def test_wire_groups_base_transport_with_credentials_file(): def test_wire_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.wire_groups.transports.WireGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WireGroupsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zone_operations.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zone_operations.py index 6a68f5d34a5d..4400661526cb 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zone_operations.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zone_operations.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ZoneOperationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( ZoneOperationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ZoneOperationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -2106,8 +2111,9 @@ def test_delete_rest_bad_request(request_type=compute.DeleteZoneOperationRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2167,17 +2173,19 @@ def test_delete_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_delete" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_delete_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_delete" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_delete" + ) as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_delete_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "pre_delete" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2233,8 +2241,9 @@ def test_get_rest_bad_request(request_type=compute.GetZoneOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2339,17 +2348,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2400,8 +2407,9 @@ def test_list_rest_bad_request(request_type=compute.ListZoneOperationsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2470,17 +2478,17 @@ def test_list_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_list" + ) as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2531,8 +2539,9 @@ def test_wait_rest_bad_request(request_type=compute.WaitZoneOperationRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2637,17 +2646,17 @@ def test_wait_rest_interceptors(null_interceptor): ) client = ZoneOperationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_wait" - ) as post, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "post_wait_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZoneOperationsRestInterceptor, "pre_wait" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_wait" + ) as post, + mock.patch.object( + transports.ZoneOperationsRestInterceptor, "post_wait_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZoneOperationsRestInterceptor, "pre_wait") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2821,11 +2830,14 @@ def test_zone_operations_base_transport(): def test_zone_operations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZoneOperationsTransport( @@ -2845,9 +2857,12 @@ def test_zone_operations_base_transport_with_credentials_file(): def test_zone_operations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.zone_operations.transports.ZoneOperationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZoneOperationsTransport() diff --git a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zones.py b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zones.py index a2d37804b65a..8c54a316560e 100644 --- a/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zones.py +++ b/packages/google-cloud-compute/tests/unit/gapic/compute_v1/test_zones.py @@ -114,6 +114,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ZonesClient._get_default_mtls_endpoint(None) is None assert ZonesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ZonesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ZonesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1629,8 +1631,9 @@ def test_get_rest_bad_request(request_type=compute.GetZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1709,17 +1712,15 @@ def test_get_rest_interceptors(null_interceptor): ) client = ZonesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZonesRestInterceptor, "post_get" - ) as post, mock.patch.object( - transports.ZonesRestInterceptor, "post_get_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZonesRestInterceptor, "pre_get" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ZonesRestInterceptor, "post_get") as post, + mock.patch.object( + transports.ZonesRestInterceptor, "post_get_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZonesRestInterceptor, "pre_get") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1768,8 +1769,9 @@ def test_list_rest_bad_request(request_type=compute.ListZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1836,17 +1838,15 @@ def test_list_rest_interceptors(null_interceptor): ) client = ZonesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ZonesRestInterceptor, "post_list" - ) as post, mock.patch.object( - transports.ZonesRestInterceptor, "post_list_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ZonesRestInterceptor, "pre_list" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ZonesRestInterceptor, "post_list") as post, + mock.patch.object( + transports.ZonesRestInterceptor, "post_list_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ZonesRestInterceptor, "pre_list") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1976,11 +1976,14 @@ def test_zones_base_transport(): def test_zones_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.compute_v1.services.zones.transports.ZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.compute_v1.services.zones.transports.ZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZonesTransport( @@ -2001,9 +2004,12 @@ def test_zones_base_transport_with_credentials_file(): def test_zones_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.compute_v1.services.zones.transports.ZonesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.compute_v1.services.zones.transports.ZonesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ZonesTransport() diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/async_client.py b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/async_client.py index d59d263b51ac..db8ef853006c 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/async_client.py +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> ConfidentialComputingTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -712,7 +712,7 @@ async def sample_verify_confidential_gke(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -738,8 +738,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -748,7 +752,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -756,7 +760,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -767,7 +771,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -793,8 +797,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -803,7 +811,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -811,7 +819,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/client.py b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/client.py index 588035880f6a..0248d1b34ca7 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/client.py +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/client.py @@ -112,7 +112,7 @@ class ConfidentialComputingClient(metaclass=ConfidentialComputingClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -536,7 +540,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = ConfidentialComputingClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1145,7 +1149,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1171,8 +1175,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1181,7 +1189,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1190,7 +1198,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1204,7 +1212,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1230,8 +1238,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1240,7 +1252,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1249,7 +1261,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/README.rst b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/README.rst index 2bf126ac1dec..c5fe314f5f2d 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/README.rst +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfidentialComputingTransport` is the ABC for all transports. -- public child `ConfidentialComputingGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfidentialComputingGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfidentialComputingRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfidentialComputingRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfidentialComputingTransport`` is the ABC for all transports. + +- public child ``ConfidentialComputingGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfidentialComputingGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfidentialComputingRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfidentialComputingRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/base.py b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/base.py index 801b5016064c..e8ae49973225 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/base.py +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc.py b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc.py index 52ca1891686c..44501e0c86fb 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc.py +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc_asyncio.py b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc_asyncio.py index bf6972d07cfc..4aa3837528f0 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc_asyncio.py +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/rest.py b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/rest.py index 672d037c7ca7..37c00d763a3d 100644 --- a/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/rest.py +++ b/packages/google-cloud-confidentialcomputing/google/cloud/confidentialcomputing_v1/services/confidential_computing/transports/rest.py @@ -422,6 +422,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConfidentialComputingRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-confidentialcomputing/noxfile.py b/packages/google-cloud-confidentialcomputing/noxfile.py index a6d71233b4d0..f47e4e202ff1 100644 --- a/packages/google-cloud-confidentialcomputing/noxfile.py +++ b/packages/google-cloud-confidentialcomputing/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-confidentialcomputing/setup.py b/packages/google-cloud-confidentialcomputing/setup.py index 70c8b4b43006..3d55e5ec9a9a 100644 --- a/packages/google-cloud-confidentialcomputing/setup.py +++ b/packages/google-cloud-confidentialcomputing/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-confidentialcomputing" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-confidentialcomputing/testing/constraints-3.7.txt b/packages/google-cloud-confidentialcomputing/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-confidentialcomputing/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-confidentialcomputing/testing/constraints-3.8.txt b/packages/google-cloud-confidentialcomputing/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-confidentialcomputing/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-confidentialcomputing/testing/constraints-3.9.txt b/packages/google-cloud-confidentialcomputing/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-confidentialcomputing/testing/constraints-3.9.txt +++ b/packages/google-cloud-confidentialcomputing/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-confidentialcomputing/tests/unit/gapic/confidentialcomputing_v1/test_confidential_computing.py b/packages/google-cloud-confidentialcomputing/tests/unit/gapic/confidentialcomputing_v1/test_confidential_computing.py index dc963ff697f9..261d352446b3 100644 --- a/packages/google-cloud-confidentialcomputing/tests/unit/gapic/confidentialcomputing_v1/test_confidential_computing.py +++ b/packages/google-cloud-confidentialcomputing/tests/unit/gapic/confidentialcomputing_v1/test_confidential_computing.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfidentialComputingClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): ConfidentialComputingClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConfidentialComputingClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1344,11 +1349,13 @@ def test_confidential_computing_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3395,8 +3402,9 @@ def test_create_challenge_rest_bad_request(request_type=service.CreateChallengeR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3537,18 +3545,20 @@ def test_create_challenge_rest_interceptors(null_interceptor): ) client = ConfidentialComputingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "post_create_challenge" - ) as post, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, - "post_create_challenge_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "pre_create_challenge" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, "post_create_challenge" + ) as post, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "post_create_challenge_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, "pre_create_challenge" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3601,8 +3611,9 @@ def test_verify_attestation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3667,18 +3678,20 @@ def test_verify_attestation_rest_interceptors(null_interceptor): ) client = ConfidentialComputingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "post_verify_attestation" - ) as post, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, - "post_verify_attestation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "pre_verify_attestation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, "post_verify_attestation" + ) as post, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "post_verify_attestation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, "pre_verify_attestation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3735,8 +3748,9 @@ def test_verify_confidential_space_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3801,19 +3815,22 @@ def test_verify_confidential_space_rest_interceptors(null_interceptor): ) client = ConfidentialComputingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, - "post_verify_confidential_space", - ) as post, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, - "post_verify_confidential_space_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "pre_verify_confidential_space" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "post_verify_confidential_space", + ) as post, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "post_verify_confidential_space_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "pre_verify_confidential_space", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3873,8 +3890,9 @@ def test_verify_confidential_gke_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3939,18 +3957,22 @@ def test_verify_confidential_gke_rest_interceptors(null_interceptor): ) client = ConfidentialComputingClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "post_verify_confidential_gke" - ) as post, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, - "post_verify_confidential_gke_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfidentialComputingRestInterceptor, "pre_verify_confidential_gke" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "post_verify_confidential_gke", + ) as post, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "post_verify_confidential_gke_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfidentialComputingRestInterceptor, + "pre_verify_confidential_gke", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4008,8 +4030,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4068,8 +4091,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4268,11 +4292,14 @@ def test_confidential_computing_base_transport(): def test_confidential_computing_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.confidentialcomputing_v1.services.confidential_computing.transports.ConfidentialComputingTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.confidentialcomputing_v1.services.confidential_computing.transports.ConfidentialComputingTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfidentialComputingTransport( @@ -4289,9 +4316,12 @@ def test_confidential_computing_base_transport_with_credentials_file(): def test_confidential_computing_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.confidentialcomputing_v1.services.confidential_computing.transports.ConfidentialComputingTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.confidentialcomputing_v1.services.confidential_computing.transports.ConfidentialComputingTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfidentialComputingTransport() @@ -4363,11 +4393,12 @@ def test_confidential_computing_transport_auth_gdch_credentials(transport_class) def test_confidential_computing_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4947,6 +4978,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConfidentialComputingClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConfidentialComputingAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConfidentialComputingClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5090,6 +5155,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConfidentialComputingClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConfidentialComputingAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConfidentialComputingClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/async_client.py b/packages/google-cloud-config/google/cloud/config_v1/services/config/async_client.py index 197c0c21e6f5..4e11dbd7aad0 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/async_client.py +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/async_client.py @@ -213,7 +213,7 @@ def transport(self) -> ConfigTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3807,7 +3807,7 @@ async def sample_update_auto_migration_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3833,8 +3833,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3843,7 +3847,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3851,7 +3855,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3862,7 +3866,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3888,8 +3892,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3898,7 +3906,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3906,7 +3914,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3917,7 +3925,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3947,8 +3955,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3957,7 +3969,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3965,7 +3977,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3973,7 +3985,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4002,8 +4014,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4012,7 +4028,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4020,7 +4036,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4028,7 +4044,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4120,8 +4136,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4130,7 +4150,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4138,7 +4160,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4149,7 +4171,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4242,8 +4264,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4252,7 +4278,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4260,7 +4288,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4271,7 +4299,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4302,8 +4330,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4314,7 +4346,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4322,7 +4356,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4333,7 +4367,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4359,8 +4393,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4369,7 +4407,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4377,7 +4415,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4388,7 +4426,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4414,8 +4452,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4424,7 +4466,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4432,7 +4474,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/client.py b/packages/google-cloud-config/google/cloud/config_v1/services/config/client.py index b123f02fdb4c..57559a5bbf07 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/client.py +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/client.py @@ -125,7 +125,7 @@ class ConfigClient(metaclass=ConfigClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -658,7 +662,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -755,7 +759,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -851,7 +855,7 @@ def __init__( self._universe_domain = ConfigClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4367,7 +4371,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4393,8 +4397,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4403,7 +4411,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4412,7 +4420,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4426,7 +4434,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4452,8 +4460,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4462,7 +4474,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4471,7 +4483,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4485,7 +4497,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4515,8 +4527,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4525,7 +4541,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4533,7 +4549,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4541,7 +4557,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4570,8 +4586,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4580,7 +4600,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4588,7 +4608,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4596,7 +4616,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4688,8 +4708,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4698,7 +4722,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4707,7 +4733,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4721,7 +4747,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4814,8 +4840,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4824,7 +4854,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4833,7 +4865,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4847,7 +4879,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4878,8 +4910,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4888,7 +4924,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4897,7 +4935,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4911,7 +4949,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4937,8 +4975,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4947,7 +4989,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4956,7 +4998,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4970,7 +5012,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4996,8 +5038,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5006,7 +5052,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5015,7 +5061,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/README.rst b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/README.rst index 78e592f08a90..87549ba61f67 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/README.rst +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfigTransport` is the ABC for all transports. -- public child `ConfigGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfigGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfigRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfigRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfigTransport`` is the ABC for all transports. + +- public child ``ConfigGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfigGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfigRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfigRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/base.py b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/base.py index d22f48979335..4059497f0267 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/base.py +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc.py b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc.py index e7295ca94886..2cf2d8aff6a3 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc.py +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc_asyncio.py b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc_asyncio.py index 7943d5927c24..5d4daf465a81 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc_asyncio.py +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/rest.py b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/rest.py index 4f4353d88c48..c07961a3d7f5 100644 --- a/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/rest.py +++ b/packages/google-cloud-config/google/cloud/config_v1/services/config/transports/rest.py @@ -1916,6 +1916,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConfigRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-config/noxfile.py b/packages/google-cloud-config/noxfile.py index e895336118b0..836fd4e11171 100644 --- a/packages/google-cloud-config/noxfile.py +++ b/packages/google-cloud-config/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-config/setup.py b/packages/google-cloud-config/setup.py index 3a81a074bc7d..af778f09645e 100644 --- a/packages/google-cloud-config/setup.py +++ b/packages/google-cloud-config/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-config/testing/constraints-3.7.txt b/packages/google-cloud-config/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-config/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-config/testing/constraints-3.8.txt b/packages/google-cloud-config/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-config/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-config/testing/constraints-3.9.txt b/packages/google-cloud-config/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-config/testing/constraints-3.9.txt +++ b/packages/google-cloud-config/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-config/tests/unit/gapic/config_v1/test_config.py b/packages/google-cloud-config/tests/unit/gapic/config_v1/test_config.py index 52e1238251c8..0130d81d8f67 100644 --- a/packages/google-cloud-config/tests/unit/gapic/config_v1/test_config.py +++ b/packages/google-cloud-config/tests/unit/gapic/config_v1/test_config.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigClient._get_default_mtls_endpoint(None) is None assert ConfigClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -151,6 +152,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ConfigClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ConfigClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_config_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -19843,8 +19847,9 @@ def test_list_deployments_rest_bad_request(request_type=config.ListDeploymentsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19907,17 +19912,19 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_deployments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19968,8 +19975,9 @@ def test_get_deployment_rest_bad_request(request_type=config.GetDeploymentReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20060,17 +20068,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20121,8 +20131,9 @@ def test_create_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20298,19 +20309,20 @@ def test_create_deployment_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_create_deployment" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_create_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_create_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_deployment" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_create_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20363,8 +20375,9 @@ def test_update_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20542,19 +20555,20 @@ def test_update_deployment_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_update_deployment" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_update_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_update_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_deployment" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_update_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20605,8 +20619,9 @@ def test_delete_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20661,19 +20676,20 @@ def test_delete_deployment_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_delete_deployment" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_delete_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_delete_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_delete_deployment" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_delete_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_delete_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20722,8 +20738,9 @@ def test_list_revisions_rest_bad_request(request_type=config.ListRevisionsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20786,17 +20803,19 @@ def test_list_revisions_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_revisions" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_revisions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_revisions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_revisions" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_revisions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_revisions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20849,8 +20868,9 @@ def test_get_revision_rest_bad_request(request_type=config.GetRevisionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20943,17 +20963,17 @@ def test_get_revision_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_revision" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_revision_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_revision" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_revision_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ConfigRestInterceptor, "pre_get_revision") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21004,8 +21024,9 @@ def test_get_resource_rest_bad_request(request_type=config.GetResourceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21072,17 +21093,17 @@ def test_get_resource_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_resource" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_resource_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_resource" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_resource_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ConfigRestInterceptor, "pre_get_resource") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21133,8 +21154,9 @@ def test_list_resources_rest_bad_request(request_type=config.ListResourcesReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21199,17 +21221,19 @@ def test_list_resources_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_resources" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_resources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_resources" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_resources_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21262,8 +21286,9 @@ def test_export_deployment_statefile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21324,18 +21349,20 @@ def test_export_deployment_statefile_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_deployment_statefile" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, - "post_export_deployment_statefile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_export_deployment_statefile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_export_deployment_statefile" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, + "post_export_deployment_statefile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_export_deployment_statefile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21390,8 +21417,9 @@ def test_export_revision_statefile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21454,17 +21482,20 @@ def test_export_revision_statefile_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_revision_statefile" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_revision_statefile_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_export_revision_statefile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_export_revision_statefile" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, + "post_export_revision_statefile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_export_revision_statefile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21515,8 +21546,9 @@ def test_import_statefile_rest_bad_request(request_type=config.ImportStatefileRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21577,17 +21609,19 @@ def test_import_statefile_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_import_statefile" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_import_statefile_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_import_statefile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_import_statefile" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_import_statefile_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_import_statefile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21636,8 +21670,9 @@ def test_delete_statefile_rest_bad_request(request_type=config.DeleteStatefileRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21692,13 +21727,13 @@ def test_delete_statefile_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "pre_delete_statefile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_delete_statefile" + ) as pre, + ): pre.assert_not_called() pb_message = config.DeleteStatefileRequest.pb(config.DeleteStatefileRequest()) transcode.return_value = { @@ -21739,8 +21774,9 @@ def test_lock_deployment_rest_bad_request(request_type=config.LockDeploymentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21795,19 +21831,20 @@ def test_lock_deployment_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_lock_deployment" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_lock_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_lock_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_lock_deployment" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_lock_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_lock_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21858,8 +21895,9 @@ def test_unlock_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21914,19 +21952,20 @@ def test_unlock_deployment_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_unlock_deployment" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_unlock_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_unlock_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_unlock_deployment" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_unlock_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_unlock_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21975,8 +22014,9 @@ def test_export_lock_info_rest_bad_request(request_type=config.ExportLockInfoReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22045,17 +22085,19 @@ def test_export_lock_info_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_lock_info" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_lock_info_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_export_lock_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_export_lock_info" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_export_lock_info_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_export_lock_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22104,8 +22146,9 @@ def test_create_preview_rest_bad_request(request_type=config.CreatePreviewReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22277,19 +22320,20 @@ def test_create_preview_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_create_preview" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_create_preview_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_create_preview" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_preview" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_create_preview_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_create_preview" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22338,8 +22382,9 @@ def test_get_preview_rest_bad_request(request_type=config.GetPreviewRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22424,17 +22469,15 @@ def test_get_preview_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_preview" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_preview_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_preview" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ConfigRestInterceptor, "post_get_preview") as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_preview_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ConfigRestInterceptor, "pre_get_preview") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22483,8 +22526,9 @@ def test_list_previews_rest_bad_request(request_type=config.ListPreviewsRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22547,17 +22591,17 @@ def test_list_previews_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_previews" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_previews_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_previews" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_previews" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_previews_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ConfigRestInterceptor, "pre_list_previews") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22608,8 +22652,9 @@ def test_delete_preview_rest_bad_request(request_type=config.DeletePreviewReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22664,19 +22709,20 @@ def test_delete_preview_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_delete_preview" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_delete_preview_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_delete_preview" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_delete_preview" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_delete_preview_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_delete_preview" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22727,8 +22773,9 @@ def test_export_preview_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22786,17 +22833,19 @@ def test_export_preview_result_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_preview_result" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_export_preview_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_export_preview_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_export_preview_result" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_export_preview_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_export_preview_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22851,8 +22900,9 @@ def test_list_terraform_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22915,17 +22965,20 @@ def test_list_terraform_versions_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_terraform_versions" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_terraform_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_terraform_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_terraform_versions" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, + "post_list_terraform_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_terraform_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22985,8 +23038,9 @@ def test_get_terraform_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23051,17 +23105,19 @@ def test_get_terraform_version_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_terraform_version" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_terraform_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_terraform_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_terraform_version" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_terraform_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_get_terraform_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23114,8 +23170,9 @@ def test_list_resource_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23178,17 +23235,19 @@ def test_list_resource_changes_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_resource_changes" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_resource_changes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_resource_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_resource_changes" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_resource_changes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_resource_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23245,8 +23304,9 @@ def test_get_resource_change_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23311,17 +23371,19 @@ def test_get_resource_change_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_resource_change" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_resource_change_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_resource_change" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_resource_change" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_resource_change_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_get_resource_change" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23374,8 +23436,9 @@ def test_list_resource_drifts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23438,17 +23501,19 @@ def test_list_resource_drifts_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_resource_drifts" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_list_resource_drifts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_list_resource_drifts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_resource_drifts" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_list_resource_drifts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_list_resource_drifts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23505,8 +23570,9 @@ def test_get_resource_drift_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23569,17 +23635,19 @@ def test_get_resource_drift_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_resource_drift" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_resource_drift_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_resource_drift" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_resource_drift" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_resource_drift_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_get_resource_drift" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23630,8 +23698,9 @@ def test_get_auto_migration_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23694,17 +23763,20 @@ def test_get_auto_migration_config_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_auto_migration_config" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, "post_get_auto_migration_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_get_auto_migration_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigRestInterceptor, "post_get_auto_migration_config" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, + "post_get_auto_migration_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_get_auto_migration_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23761,8 +23833,9 @@ def test_update_auto_migration_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23897,20 +23970,21 @@ def test_update_auto_migration_config_rest_interceptors(null_interceptor): ) client = ConfigClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigRestInterceptor, "post_update_auto_migration_config" - ) as post, mock.patch.object( - transports.ConfigRestInterceptor, - "post_update_auto_migration_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigRestInterceptor, "pre_update_auto_migration_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigRestInterceptor, "post_update_auto_migration_config" + ) as post, + mock.patch.object( + transports.ConfigRestInterceptor, + "post_update_auto_migration_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigRestInterceptor, "pre_update_auto_migration_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23963,8 +24037,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24023,8 +24098,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24085,8 +24161,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24149,8 +24226,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24213,8 +24291,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24277,8 +24356,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24339,8 +24419,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24401,8 +24482,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24463,8 +24545,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25241,11 +25324,14 @@ def test_config_base_transport(): def test_config_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.config_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.config_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigTransport( @@ -25262,9 +25348,12 @@ def test_config_base_transport_with_credentials_file(): def test_config_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.config_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.config_v1.services.config.transports.ConfigTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigTransport() @@ -25336,11 +25425,12 @@ def test_config_transport_auth_gdch_credentials(transport_class): def test_config_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -26263,6 +26353,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26402,6 +26524,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26547,6 +26701,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26692,6 +26880,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26837,6 +27059,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26978,6 +27234,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConfigClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27142,6 +27432,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = ConfigClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27309,6 +27634,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = ConfigClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27486,6 +27846,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = ConfigClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = ConfigAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = ConfigClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/async_client.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/async_client.py index dd0e925e28fe..9fb00220856f 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/async_client.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> ConfigDeliveryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3581,7 +3581,7 @@ async def sample_abort_rollout(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3607,8 +3607,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3617,7 +3621,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3625,7 +3629,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3636,7 +3640,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3662,8 +3666,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3672,7 +3680,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3680,7 +3688,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3691,7 +3699,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3721,8 +3729,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3731,7 +3743,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3739,7 +3751,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3747,7 +3759,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3776,8 +3788,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3786,7 +3802,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3794,7 +3810,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3802,7 +3818,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3828,8 +3844,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3838,7 +3858,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3846,7 +3866,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3857,7 +3877,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3883,8 +3903,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3893,7 +3917,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3901,7 +3925,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/client.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/client.py index fa30280f649c..47190c40f737 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/client.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/client.py @@ -119,7 +119,7 @@ class ConfigDeliveryClient(metaclass=ConfigDeliveryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -588,7 +592,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -685,7 +689,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -781,7 +785,7 @@ def __init__( self._universe_domain = ConfigDeliveryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4077,7 +4081,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4103,8 +4107,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4113,7 +4121,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4122,7 +4130,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4136,7 +4144,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4162,8 +4170,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4172,7 +4184,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4181,7 +4193,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4195,7 +4207,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4225,8 +4237,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4235,7 +4251,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4243,7 +4259,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4251,7 +4267,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4280,8 +4296,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4290,7 +4310,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4298,7 +4318,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4306,7 +4326,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4332,8 +4352,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4342,7 +4366,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4351,7 +4375,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4365,7 +4389,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4391,8 +4415,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4401,7 +4429,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4410,7 +4438,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/README.rst b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/README.rst index 844bd8856291..b7a11729ed22 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/README.rst +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfigDeliveryTransport` is the ABC for all transports. -- public child `ConfigDeliveryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfigDeliveryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfigDeliveryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfigDeliveryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfigDeliveryTransport`` is the ABC for all transports. + +- public child ``ConfigDeliveryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfigDeliveryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfigDeliveryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfigDeliveryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/base.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/base.py index 054233059180..2dd592ffb10e 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/base.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc.py index 8bf58ca4619e..5db7f3287eb3 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc_asyncio.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc_asyncio.py index cc448e0708c7..a345f1eb48c7 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc_asyncio.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/rest.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/rest.py index 7bbaa970a983..0757c909c3b3 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/rest.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1/services/config_delivery/transports/rest.py @@ -1715,6 +1715,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConfigDeliveryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/async_client.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/async_client.py index 71a66e856c45..68c26815ca76 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/async_client.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> ConfigDeliveryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3581,7 +3581,7 @@ async def sample_abort_rollout(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3607,8 +3607,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3617,7 +3621,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3625,7 +3629,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3636,7 +3640,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3662,8 +3666,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3672,7 +3680,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3680,7 +3688,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3691,7 +3699,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3721,8 +3729,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3731,7 +3743,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3739,7 +3751,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3747,7 +3759,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3776,8 +3788,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3786,7 +3802,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3794,7 +3810,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3802,7 +3818,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3828,8 +3844,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3838,7 +3858,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3846,7 +3866,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3857,7 +3877,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3883,8 +3903,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3893,7 +3917,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3901,7 +3925,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/client.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/client.py index d70edaefc585..644017275092 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/client.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/client.py @@ -119,7 +119,7 @@ class ConfigDeliveryClient(metaclass=ConfigDeliveryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -588,7 +592,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -685,7 +689,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -781,7 +785,7 @@ def __init__( self._universe_domain = ConfigDeliveryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4077,7 +4081,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4103,8 +4107,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4113,7 +4121,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4122,7 +4130,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4136,7 +4144,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4162,8 +4170,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4172,7 +4184,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4181,7 +4193,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4195,7 +4207,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4225,8 +4237,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4235,7 +4251,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4243,7 +4259,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4251,7 +4267,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4280,8 +4296,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4290,7 +4310,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4298,7 +4318,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4306,7 +4326,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4332,8 +4352,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4342,7 +4366,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4351,7 +4375,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4365,7 +4389,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4391,8 +4415,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4401,7 +4429,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4410,7 +4438,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/README.rst b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/README.rst index 844bd8856291..b7a11729ed22 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/README.rst +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfigDeliveryTransport` is the ABC for all transports. -- public child `ConfigDeliveryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfigDeliveryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfigDeliveryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfigDeliveryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfigDeliveryTransport`` is the ABC for all transports. + +- public child ``ConfigDeliveryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfigDeliveryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfigDeliveryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfigDeliveryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/base.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/base.py index 45b9c0e82f11..198d0c1d1333 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/base.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc.py index e9498262b2f9..2b4ee6debdd4 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc_asyncio.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc_asyncio.py index 8135a228cdf7..2ed71fcc60a8 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc_asyncio.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/rest.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/rest.py index ac538514b040..b6634c84e38f 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/rest.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1alpha/services/config_delivery/transports/rest.py @@ -1715,6 +1715,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConfigDeliveryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/async_client.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/async_client.py index 1a3468cdd10f..3dc2c0cb9ed7 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/async_client.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> ConfigDeliveryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3581,7 +3581,7 @@ async def sample_abort_rollout(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3607,8 +3607,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3617,7 +3621,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3625,7 +3629,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3636,7 +3640,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3662,8 +3666,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3672,7 +3680,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3680,7 +3688,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3691,7 +3699,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3721,8 +3729,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3731,7 +3743,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3739,7 +3751,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3747,7 +3759,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3776,8 +3788,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3786,7 +3802,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3794,7 +3810,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3802,7 +3818,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3828,8 +3844,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3838,7 +3858,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3846,7 +3866,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3857,7 +3877,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3883,8 +3903,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3893,7 +3917,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3901,7 +3925,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/client.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/client.py index 47383c193e6f..ef2e27696ca4 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/client.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/client.py @@ -119,7 +119,7 @@ class ConfigDeliveryClient(metaclass=ConfigDeliveryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -588,7 +592,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -685,7 +689,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -781,7 +785,7 @@ def __init__( self._universe_domain = ConfigDeliveryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4077,7 +4081,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4103,8 +4107,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4113,7 +4121,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4122,7 +4130,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4136,7 +4144,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4162,8 +4170,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4172,7 +4184,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4181,7 +4193,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4195,7 +4207,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4225,8 +4237,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4235,7 +4251,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4243,7 +4259,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4251,7 +4267,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4280,8 +4296,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4290,7 +4310,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4298,7 +4318,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4306,7 +4326,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4332,8 +4352,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4342,7 +4366,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4351,7 +4375,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4365,7 +4389,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4391,8 +4415,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4401,7 +4429,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4410,7 +4438,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/README.rst b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/README.rst index 844bd8856291..b7a11729ed22 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/README.rst +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfigDeliveryTransport` is the ABC for all transports. -- public child `ConfigDeliveryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfigDeliveryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfigDeliveryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfigDeliveryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfigDeliveryTransport`` is the ABC for all transports. + +- public child ``ConfigDeliveryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfigDeliveryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfigDeliveryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfigDeliveryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/base.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/base.py index 3e5c33990a0f..ed73b2bc566d 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/base.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc.py index e3838c903a10..f8073a333329 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc_asyncio.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc_asyncio.py index d326931bf8e0..bc95a64050f7 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc_asyncio.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/rest.py b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/rest.py index 393a0e5dcb6b..00aea48e1b6c 100644 --- a/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/rest.py +++ b/packages/google-cloud-configdelivery/google/cloud/configdelivery_v1beta/services/config_delivery/transports/rest.py @@ -1715,6 +1715,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConfigDeliveryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-configdelivery/noxfile.py b/packages/google-cloud-configdelivery/noxfile.py index 291417271f4e..bd7d788f7f61 100644 --- a/packages/google-cloud-configdelivery/noxfile.py +++ b/packages/google-cloud-configdelivery/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-configdelivery/setup.py b/packages/google-cloud-configdelivery/setup.py index 1eb48db87b32..8e41bcf95023 100644 --- a/packages/google-cloud-configdelivery/setup.py +++ b/packages/google-cloud-configdelivery/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-configdelivery" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-configdelivery/testing/constraints-3.7.txt b/packages/google-cloud-configdelivery/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-configdelivery/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-configdelivery/testing/constraints-3.8.txt b/packages/google-cloud-configdelivery/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-configdelivery/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-configdelivery/testing/constraints-3.9.txt b/packages/google-cloud-configdelivery/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-configdelivery/testing/constraints-3.9.txt +++ b/packages/google-cloud-configdelivery/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1/test_config_delivery.py b/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1/test_config_delivery.py index f63e8b8f9113..e4311149e409 100644 --- a/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1/test_config_delivery.py +++ b/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1/test_config_delivery.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigDeliveryClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( ConfigDeliveryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConfigDeliveryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_config_delivery_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -17418,8 +17425,9 @@ def test_list_resource_bundles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17484,18 +17492,20 @@ def test_list_resource_bundles_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_resource_bundles" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_list_resource_bundles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_resource_bundles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_resource_bundles" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_list_resource_bundles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_resource_bundles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17555,8 +17565,9 @@ def test_get_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17623,18 +17634,20 @@ def test_get_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_get_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_get_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17689,8 +17702,9 @@ def test_create_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17823,20 +17837,21 @@ def test_create_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_create_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17893,8 +17908,9 @@ def test_update_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18031,20 +18047,21 @@ def test_update_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_update_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18099,8 +18116,9 @@ def test_delete_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18159,20 +18177,21 @@ def test_delete_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_delete_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18225,8 +18244,9 @@ def test_list_fleet_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18291,18 +18311,20 @@ def test_list_fleet_packages_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_fleet_packages" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_list_fleet_packages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_fleet_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_fleet_packages" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_list_fleet_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_fleet_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18360,8 +18382,9 @@ def test_get_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18431,17 +18454,20 @@ def test_get_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_get_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18496,8 +18522,9 @@ def test_create_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18650,20 +18677,21 @@ def test_create_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_create_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18720,8 +18748,9 @@ def test_update_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18878,20 +18907,21 @@ def test_update_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_update_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18944,8 +18974,9 @@ def test_delete_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19002,20 +19033,21 @@ def test_delete_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_delete_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19070,8 +19102,9 @@ def test_list_releases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19138,17 +19171,19 @@ def test_list_releases_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_releases" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_releases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_releases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_releases" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_releases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_releases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19206,8 +19241,9 @@ def test_get_release_rest_bad_request(request_type=config_delivery.GetReleaseReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19276,17 +19312,19 @@ def test_get_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_release_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19341,8 +19379,9 @@ def test_create_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19481,19 +19520,21 @@ def test_create_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19550,8 +19591,9 @@ def test_update_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19692,19 +19734,21 @@ def test_update_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19759,8 +19803,9 @@ def test_delete_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19819,19 +19864,21 @@ def test_delete_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19886,8 +19933,9 @@ def test_list_variants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19954,17 +20002,19 @@ def test_list_variants_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_variants" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_variants_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_variants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_variants" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_variants_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_variants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20022,8 +20072,9 @@ def test_get_variant_rest_bad_request(request_type=config_delivery.GetVariantReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20090,17 +20141,19 @@ def test_get_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_variant_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20155,8 +20208,9 @@ def test_create_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20289,19 +20343,21 @@ def test_create_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20358,8 +20414,9 @@ def test_update_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20494,19 +20551,21 @@ def test_update_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20561,8 +20620,9 @@ def test_delete_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20621,19 +20681,21 @@ def test_delete_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20688,8 +20750,9 @@ def test_list_rollouts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20756,17 +20819,19 @@ def test_list_rollouts_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_rollouts" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_rollouts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_rollouts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_rollouts" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_rollouts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_rollouts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20824,8 +20889,9 @@ def test_get_rollout_rest_bad_request(request_type=config_delivery.GetRolloutReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20897,17 +20963,19 @@ def test_get_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20962,8 +21030,9 @@ def test_suspend_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21022,19 +21091,21 @@ def test_suspend_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_suspend_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_suspend_rollout_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_suspend_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21089,8 +21160,9 @@ def test_resume_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21149,19 +21221,21 @@ def test_resume_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_resume_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_resume_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_resume_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_resume_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_resume_rollout_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_resume_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21216,8 +21290,9 @@ def test_abort_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21276,19 +21351,20 @@ def test_abort_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_abort_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_abort_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_abort_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_abort_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_abort_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_abort_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21341,8 +21417,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21401,8 +21478,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21463,8 +21541,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21525,8 +21604,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21587,8 +21667,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21649,8 +21730,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22330,11 +22412,14 @@ def test_config_delivery_base_transport(): def test_config_delivery_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.configdelivery_v1.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.configdelivery_v1.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigDeliveryTransport( @@ -22351,9 +22436,12 @@ def test_config_delivery_base_transport_with_credentials_file(): def test_config_delivery_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.configdelivery_v1.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.configdelivery_v1.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigDeliveryTransport() @@ -22425,11 +22513,12 @@ def test_config_delivery_transport_auth_gdch_credentials(transport_class): def test_config_delivery_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -23283,6 +23372,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23422,6 +23543,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23567,6 +23720,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23712,6 +23899,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23857,6 +24078,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23998,6 +24253,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1alpha/test_config_delivery.py b/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1alpha/test_config_delivery.py index 4689577b70e3..fb0cf859c406 100644 --- a/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1alpha/test_config_delivery.py +++ b/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1alpha/test_config_delivery.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigDeliveryClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( ConfigDeliveryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConfigDeliveryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_config_delivery_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -17418,8 +17425,9 @@ def test_list_resource_bundles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17484,18 +17492,20 @@ def test_list_resource_bundles_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_resource_bundles" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_list_resource_bundles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_resource_bundles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_resource_bundles" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_list_resource_bundles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_resource_bundles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17555,8 +17565,9 @@ def test_get_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17623,18 +17634,20 @@ def test_get_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_get_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_get_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17689,8 +17702,9 @@ def test_create_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17823,20 +17837,21 @@ def test_create_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_create_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17893,8 +17908,9 @@ def test_update_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18031,20 +18047,21 @@ def test_update_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_update_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18099,8 +18116,9 @@ def test_delete_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18159,20 +18177,21 @@ def test_delete_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_delete_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18225,8 +18244,9 @@ def test_list_fleet_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18291,18 +18311,20 @@ def test_list_fleet_packages_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_fleet_packages" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_list_fleet_packages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_fleet_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_fleet_packages" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_list_fleet_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_fleet_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18360,8 +18382,9 @@ def test_get_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18431,17 +18454,20 @@ def test_get_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_get_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18496,8 +18522,9 @@ def test_create_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18650,20 +18677,21 @@ def test_create_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_create_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18720,8 +18748,9 @@ def test_update_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18878,20 +18907,21 @@ def test_update_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_update_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18944,8 +18974,9 @@ def test_delete_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19002,20 +19033,21 @@ def test_delete_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_delete_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19070,8 +19102,9 @@ def test_list_releases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19138,17 +19171,19 @@ def test_list_releases_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_releases" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_releases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_releases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_releases" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_releases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_releases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19206,8 +19241,9 @@ def test_get_release_rest_bad_request(request_type=config_delivery.GetReleaseReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19276,17 +19312,19 @@ def test_get_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_release_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19341,8 +19379,9 @@ def test_create_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19481,19 +19520,21 @@ def test_create_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19550,8 +19591,9 @@ def test_update_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19692,19 +19734,21 @@ def test_update_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19759,8 +19803,9 @@ def test_delete_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19819,19 +19864,21 @@ def test_delete_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19886,8 +19933,9 @@ def test_list_variants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19954,17 +20002,19 @@ def test_list_variants_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_variants" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_variants_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_variants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_variants" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_variants_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_variants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20022,8 +20072,9 @@ def test_get_variant_rest_bad_request(request_type=config_delivery.GetVariantReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20090,17 +20141,19 @@ def test_get_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_variant_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20155,8 +20208,9 @@ def test_create_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20289,19 +20343,21 @@ def test_create_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20358,8 +20414,9 @@ def test_update_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20494,19 +20551,21 @@ def test_update_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20561,8 +20620,9 @@ def test_delete_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20621,19 +20681,21 @@ def test_delete_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20688,8 +20750,9 @@ def test_list_rollouts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20756,17 +20819,19 @@ def test_list_rollouts_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_rollouts" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_rollouts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_rollouts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_rollouts" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_rollouts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_rollouts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20824,8 +20889,9 @@ def test_get_rollout_rest_bad_request(request_type=config_delivery.GetRolloutReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20897,17 +20963,19 @@ def test_get_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20962,8 +21030,9 @@ def test_suspend_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21022,19 +21091,21 @@ def test_suspend_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_suspend_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_suspend_rollout_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_suspend_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21089,8 +21160,9 @@ def test_resume_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21149,19 +21221,21 @@ def test_resume_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_resume_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_resume_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_resume_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_resume_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_resume_rollout_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_resume_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21216,8 +21290,9 @@ def test_abort_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21276,19 +21351,20 @@ def test_abort_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_abort_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_abort_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_abort_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_abort_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_abort_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_abort_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21341,8 +21417,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21401,8 +21478,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21463,8 +21541,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21525,8 +21604,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21587,8 +21667,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21649,8 +21730,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22330,11 +22412,14 @@ def test_config_delivery_base_transport(): def test_config_delivery_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.configdelivery_v1alpha.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.configdelivery_v1alpha.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigDeliveryTransport( @@ -22351,9 +22436,12 @@ def test_config_delivery_base_transport_with_credentials_file(): def test_config_delivery_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.configdelivery_v1alpha.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.configdelivery_v1alpha.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigDeliveryTransport() @@ -22425,11 +22513,12 @@ def test_config_delivery_transport_auth_gdch_credentials(transport_class): def test_config_delivery_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -23283,6 +23372,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23422,6 +23543,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23567,6 +23720,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23712,6 +23899,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23857,6 +24078,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23998,6 +24253,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1beta/test_config_delivery.py b/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1beta/test_config_delivery.py index c8b0099bd3bf..381a3eb3ef39 100644 --- a/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1beta/test_config_delivery.py +++ b/packages/google-cloud-configdelivery/tests/unit/gapic/configdelivery_v1beta/test_config_delivery.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigDeliveryClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( ConfigDeliveryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConfigDeliveryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_config_delivery_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -17418,8 +17425,9 @@ def test_list_resource_bundles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17484,18 +17492,20 @@ def test_list_resource_bundles_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_resource_bundles" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_list_resource_bundles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_resource_bundles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_resource_bundles" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_list_resource_bundles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_resource_bundles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17555,8 +17565,9 @@ def test_get_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17623,18 +17634,20 @@ def test_get_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_get_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_get_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17689,8 +17702,9 @@ def test_create_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17823,20 +17837,21 @@ def test_create_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_create_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17893,8 +17908,9 @@ def test_update_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18031,20 +18047,21 @@ def test_update_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_update_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18099,8 +18116,9 @@ def test_delete_resource_bundle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18159,20 +18177,21 @@ def test_delete_resource_bundle_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_resource_bundle" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_delete_resource_bundle_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_resource_bundle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_resource_bundle" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_resource_bundle_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_resource_bundle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18225,8 +18244,9 @@ def test_list_fleet_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18291,18 +18311,20 @@ def test_list_fleet_packages_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_fleet_packages" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_list_fleet_packages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_fleet_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_fleet_packages" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_list_fleet_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_fleet_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18360,8 +18382,9 @@ def test_get_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18431,17 +18454,20 @@ def test_get_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_get_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18496,8 +18522,9 @@ def test_create_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18650,20 +18677,21 @@ def test_create_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_create_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18720,8 +18748,9 @@ def test_update_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18878,20 +18907,21 @@ def test_update_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_update_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18944,8 +18974,9 @@ def test_delete_fleet_package_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19002,20 +19033,21 @@ def test_delete_fleet_package_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_fleet_package" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, - "post_delete_fleet_package_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_fleet_package" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_fleet_package" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_fleet_package_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_fleet_package" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19070,8 +19102,9 @@ def test_list_releases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19138,17 +19171,19 @@ def test_list_releases_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_releases" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_releases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_releases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_releases" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_releases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_releases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19206,8 +19241,9 @@ def test_get_release_rest_bad_request(request_type=config_delivery.GetReleaseReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19276,17 +19312,19 @@ def test_get_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_release_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19341,8 +19379,9 @@ def test_create_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19481,19 +19520,21 @@ def test_create_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19550,8 +19591,9 @@ def test_update_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19692,19 +19734,21 @@ def test_update_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19759,8 +19803,9 @@ def test_delete_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19819,19 +19864,21 @@ def test_delete_release_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_release" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_release" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_release_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19886,8 +19933,9 @@ def test_list_variants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19954,17 +20002,19 @@ def test_list_variants_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_variants" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_variants_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_variants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_variants" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_variants_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_variants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20022,8 +20072,9 @@ def test_get_variant_rest_bad_request(request_type=config_delivery.GetVariantReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20090,17 +20141,19 @@ def test_get_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_variant_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20155,8 +20208,9 @@ def test_create_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20289,19 +20343,21 @@ def test_create_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_create_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_create_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_create_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_create_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_create_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20358,8 +20414,9 @@ def test_update_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20494,19 +20551,21 @@ def test_update_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_update_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_update_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_update_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_update_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_update_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20561,8 +20620,9 @@ def test_delete_variant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20621,19 +20681,21 @@ def test_delete_variant_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_variant" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_delete_variant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_delete_variant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_delete_variant" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_delete_variant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_delete_variant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20688,8 +20750,9 @@ def test_list_rollouts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20756,17 +20819,19 @@ def test_list_rollouts_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_rollouts" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_list_rollouts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_list_rollouts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_rollouts" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_list_rollouts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_list_rollouts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20824,8 +20889,9 @@ def test_get_rollout_rest_bad_request(request_type=config_delivery.GetRolloutReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20897,17 +20963,19 @@ def test_get_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_get_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_get_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_get_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_get_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20962,8 +21030,9 @@ def test_suspend_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21022,19 +21091,21 @@ def test_suspend_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_suspend_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_suspend_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_suspend_rollout_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_suspend_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21089,8 +21160,9 @@ def test_resume_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21149,19 +21221,21 @@ def test_resume_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_resume_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_resume_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_resume_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_resume_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, + "post_resume_rollout_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_resume_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21216,8 +21290,9 @@ def test_abort_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21276,19 +21351,20 @@ def test_abort_rollout_rest_interceptors(null_interceptor): ) client = ConfigDeliveryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_abort_rollout" - ) as post, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "post_abort_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConfigDeliveryRestInterceptor, "pre_abort_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_abort_rollout" + ) as post, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "post_abort_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConfigDeliveryRestInterceptor, "pre_abort_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21341,8 +21417,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21401,8 +21478,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21463,8 +21541,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21525,8 +21604,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21587,8 +21667,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21649,8 +21730,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22330,11 +22412,14 @@ def test_config_delivery_base_transport(): def test_config_delivery_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.configdelivery_v1beta.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.configdelivery_v1beta.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigDeliveryTransport( @@ -22351,9 +22436,12 @@ def test_config_delivery_base_transport_with_credentials_file(): def test_config_delivery_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.configdelivery_v1beta.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.configdelivery_v1beta.services.config_delivery.transports.ConfigDeliveryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigDeliveryTransport() @@ -22425,11 +22513,12 @@ def test_config_delivery_transport_auth_gdch_credentials(transport_class): def test_config_delivery_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -23283,6 +23372,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23422,6 +23543,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23567,6 +23720,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23712,6 +23899,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23857,6 +24078,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23998,6 +24253,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConfigDeliveryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConfigDeliveryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConfigDeliveryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/async_client.py b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/async_client.py index 23c0a6f224cb..b2833f3a3be3 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/async_client.py +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/async_client.py @@ -274,7 +274,7 @@ def transport(self) -> ContactCenterInsightsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -9393,7 +9393,7 @@ async def sample_bulk_download_feedback_labels(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9419,8 +9419,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9429,7 +9433,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9437,7 +9441,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9448,7 +9452,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9474,8 +9478,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9484,7 +9492,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9492,7 +9500,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9503,7 +9511,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9532,8 +9540,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9542,7 +9554,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9550,7 +9562,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/client.py b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/client.py index 6c77219b006a..9f8f41880a6b 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/client.py +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/client.py @@ -128,7 +128,7 @@ class ContactCenterInsightsClient(metaclass=ContactCenterInsightsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -816,7 +820,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -915,7 +919,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1015,7 +1019,7 @@ def __init__( self._universe_domain = ContactCenterInsightsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -9942,7 +9946,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9968,8 +9972,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9978,7 +9986,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9987,7 +9995,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -10001,7 +10009,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -10027,8 +10035,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -10037,7 +10049,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -10046,7 +10058,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -10060,7 +10072,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -10089,8 +10101,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -10099,7 +10115,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -10107,7 +10123,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/README.rst b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/README.rst index fad811392785..aa81223ab9fa 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/README.rst +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContactCenterInsightsTransport` is the ABC for all transports. -- public child `ContactCenterInsightsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContactCenterInsightsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContactCenterInsightsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContactCenterInsightsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContactCenterInsightsTransport`` is the ABC for all transports. + +- public child ``ContactCenterInsightsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContactCenterInsightsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContactCenterInsightsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContactCenterInsightsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/base.py b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/base.py index 708f1611d68a..62abce102fd1 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/base.py +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc.py b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc.py index 71aff517b1fa..dc0b2cf7e937 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc.py +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc_asyncio.py b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc_asyncio.py index ef6eb284d6e1..b914bbb127c5 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc_asyncio.py +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/rest.py b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/rest.py index 6ddce1539427..226df716343f 100644 --- a/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/rest.py +++ b/packages/google-cloud-contact-center-insights/google/cloud/contact_center_insights_v1/services/contact_center_insights/transports/rest.py @@ -4090,6 +4090,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContactCenterInsightsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contact-center-insights/noxfile.py b/packages/google-cloud-contact-center-insights/noxfile.py index 1efad5565af0..16432b313ae8 100644 --- a/packages/google-cloud-contact-center-insights/noxfile.py +++ b/packages/google-cloud-contact-center-insights/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-contact-center-insights/setup.py b/packages/google-cloud-contact-center-insights/setup.py index c6f0fcd36244..64db7468f9cb 100644 --- a/packages/google-cloud-contact-center-insights/setup.py +++ b/packages/google-cloud-contact-center-insights/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-contact-center-insights/testing/constraints-3.7.txt b/packages/google-cloud-contact-center-insights/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-contact-center-insights/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-contact-center-insights/testing/constraints-3.8.txt b/packages/google-cloud-contact-center-insights/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-contact-center-insights/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-contact-center-insights/testing/constraints-3.9.txt b/packages/google-cloud-contact-center-insights/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-contact-center-insights/testing/constraints-3.9.txt +++ b/packages/google-cloud-contact-center-insights/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-contact-center-insights/tests/unit/gapic/contact_center_insights_v1/test_contact_center_insights.py b/packages/google-cloud-contact-center-insights/tests/unit/gapic/contact_center_insights_v1/test_contact_center_insights.py index b8823822581b..3887d2ece9f6 100644 --- a/packages/google-cloud-contact-center-insights/tests/unit/gapic/contact_center_insights_v1/test_contact_center_insights.py +++ b/packages/google-cloud-contact-center-insights/tests/unit/gapic/contact_center_insights_v1/test_contact_center_insights.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContactCenterInsightsClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): ContactCenterInsightsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContactCenterInsightsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1359,11 +1364,13 @@ def test_contact_center_insights_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -46905,8 +46912,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47308,18 +47316,20 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_conversation" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_conversation" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47372,8 +47382,9 @@ def test_upload_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47430,20 +47441,21 @@ def test_upload_conversation_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_upload_conversation" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_upload_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_upload_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_upload_conversation" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_upload_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_upload_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47500,8 +47512,9 @@ def test_update_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47907,18 +47920,20 @@ def test_update_conversation_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_conversation" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_conversation" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47971,8 +47986,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48047,18 +48063,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48111,8 +48129,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48177,18 +48196,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48246,8 +48267,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48304,13 +48326,13 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_conversation" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteConversationRequest.pb( contact_center_insights.DeleteConversationRequest() @@ -48357,8 +48379,9 @@ def test_create_analysis_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48617,20 +48640,21 @@ def test_create_analysis_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_analysis" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_analysis_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_analysis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_analysis" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_analysis_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_analysis" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48685,8 +48709,9 @@ def test_get_analysis_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48751,18 +48776,20 @@ def test_get_analysis_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_analysis" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_analysis_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_analysis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_analysis" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_analysis_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_analysis" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48817,8 +48844,9 @@ def test_list_analyses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48883,18 +48911,20 @@ def test_list_analyses_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_analyses" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_analyses_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_analyses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_analyses" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_analyses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_analyses" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48954,8 +48984,9 @@ def test_delete_analysis_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49014,13 +49045,13 @@ def test_delete_analysis_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_analysis" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_analysis" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteAnalysisRequest.pb( contact_center_insights.DeleteAnalysisRequest() @@ -49065,8 +49096,9 @@ def test_bulk_analyze_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49123,22 +49155,23 @@ def test_bulk_analyze_conversations_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_analyze_conversations", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_analyze_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_bulk_analyze_conversations", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_analyze_conversations", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_analyze_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_bulk_analyze_conversations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49191,8 +49224,9 @@ def test_bulk_delete_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49249,21 +49283,23 @@ def test_bulk_delete_conversations_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_delete_conversations", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_delete_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_bulk_delete_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_delete_conversations", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_delete_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_bulk_delete_conversations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49316,8 +49352,9 @@ def test_ingest_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49374,20 +49411,21 @@ def test_ingest_conversations_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_ingest_conversations" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_ingest_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_ingest_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_ingest_conversations" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_ingest_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_ingest_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49440,8 +49478,9 @@ def test_export_insights_data_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49498,20 +49537,21 @@ def test_export_insights_data_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_export_insights_data" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_export_insights_data_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_export_insights_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_export_insights_data" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_export_insights_data_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_export_insights_data" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49564,8 +49604,9 @@ def test_create_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49711,20 +49752,21 @@ def test_create_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49781,8 +49823,9 @@ def test_update_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49948,18 +49991,20 @@ def test_update_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50012,8 +50057,9 @@ def test_get_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50086,18 +50132,20 @@ def test_get_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50150,8 +50198,9 @@ def test_list_issue_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50211,18 +50260,20 @@ def test_list_issue_models_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_issue_models" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_issue_models_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_issue_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_issue_models" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_issue_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_issue_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50280,8 +50331,9 @@ def test_delete_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50338,20 +50390,21 @@ def test_delete_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_delete_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_delete_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_delete_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_delete_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50404,8 +50457,9 @@ def test_deploy_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50462,20 +50516,21 @@ def test_deploy_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_deploy_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_deploy_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_deploy_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_deploy_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_deploy_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_deploy_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50528,8 +50583,9 @@ def test_undeploy_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50586,20 +50642,21 @@ def test_undeploy_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_undeploy_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_undeploy_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_undeploy_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_undeploy_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_undeploy_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_undeploy_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50652,8 +50709,9 @@ def test_export_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50710,20 +50768,21 @@ def test_export_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_export_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_export_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_export_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_export_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_export_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_export_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50776,8 +50835,9 @@ def test_import_issue_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50834,20 +50894,21 @@ def test_import_issue_model_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_import_issue_model" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_import_issue_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_import_issue_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_import_issue_model" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_import_issue_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_import_issue_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50902,8 +50963,9 @@ def test_get_issue_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50974,17 +51036,20 @@ def test_get_issue_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_issue" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_issue_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_issue" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_issue" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_issue_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_issue" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51037,8 +51102,9 @@ def test_list_issues_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51098,18 +51164,20 @@ def test_list_issues_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_issues" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_issues_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_issues" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_issues" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_issues_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_issues" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51171,8 +51239,9 @@ def test_update_issue_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51320,18 +51389,20 @@ def test_update_issue_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_issue" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_issue_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_issue" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_issue" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_issue_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_issue" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51386,8 +51457,9 @@ def test_delete_issue_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51446,13 +51518,13 @@ def test_delete_issue_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_issue" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_issue" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteIssueRequest.pb( contact_center_insights.DeleteIssueRequest() @@ -51499,8 +51571,9 @@ def test_calculate_issue_model_stats_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51566,20 +51639,22 @@ def test_calculate_issue_model_stats_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_calculate_issue_model_stats", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_calculate_issue_model_stats_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_calculate_issue_model_stats", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_calculate_issue_model_stats", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_calculate_issue_model_stats_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_calculate_issue_model_stats", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51637,8 +51712,9 @@ def test_create_phrase_matcher_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51806,18 +51882,21 @@ def test_create_phrase_matcher_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_phrase_matcher" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_phrase_matcher_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_phrase_matcher" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_phrase_matcher", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_phrase_matcher_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_phrase_matcher" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51870,8 +51949,9 @@ def test_get_phrase_matcher_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51946,18 +52026,20 @@ def test_get_phrase_matcher_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_phrase_matcher" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_phrase_matcher_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_phrase_matcher" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_phrase_matcher" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_phrase_matcher_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_phrase_matcher" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52010,8 +52092,9 @@ def test_list_phrase_matchers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52076,18 +52159,20 @@ def test_list_phrase_matchers_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_phrase_matchers" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_phrase_matchers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_phrase_matchers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_phrase_matchers" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_phrase_matchers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_phrase_matchers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52145,8 +52230,9 @@ def test_delete_phrase_matcher_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52203,13 +52289,13 @@ def test_delete_phrase_matcher_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_phrase_matcher" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_phrase_matcher" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeletePhraseMatcherRequest.pb( contact_center_insights.DeletePhraseMatcherRequest() @@ -52258,8 +52344,9 @@ def test_update_phrase_matcher_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52431,18 +52518,21 @@ def test_update_phrase_matcher_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_phrase_matcher" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_phrase_matcher_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_phrase_matcher" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_phrase_matcher", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_phrase_matcher_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_phrase_matcher" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52495,8 +52585,9 @@ def test_calculate_stats_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52561,18 +52652,20 @@ def test_calculate_stats_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_calculate_stats" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_calculate_stats_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_calculate_stats" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_calculate_stats" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_calculate_stats_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_calculate_stats" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52630,8 +52723,9 @@ def test_get_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52696,18 +52790,20 @@ def test_get_settings_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_settings" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_settings" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52760,8 +52856,9 @@ def test_update_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52935,18 +53032,20 @@ def test_update_settings_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_settings" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_settings" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52999,8 +53098,9 @@ def test_create_analysis_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53174,18 +53274,20 @@ def test_create_analysis_rule_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_analysis_rule" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_analysis_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_analysis_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_analysis_rule" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_analysis_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_analysis_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53238,8 +53340,9 @@ def test_get_analysis_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53310,18 +53413,20 @@ def test_get_analysis_rule_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_analysis_rule" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_analysis_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_analysis_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_analysis_rule" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_analysis_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_analysis_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53374,8 +53479,9 @@ def test_list_analysis_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53440,18 +53546,20 @@ def test_list_analysis_rules_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_analysis_rules" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_analysis_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_analysis_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_analysis_rules" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_analysis_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_analysis_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53513,8 +53621,9 @@ def test_update_analysis_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53692,18 +53801,20 @@ def test_update_analysis_rule_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_analysis_rule" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_analysis_rule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_analysis_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_analysis_rule" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_analysis_rule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_analysis_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53756,8 +53867,9 @@ def test_delete_analysis_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53814,13 +53926,13 @@ def test_delete_analysis_rule_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_analysis_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_analysis_rule" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteAnalysisRuleRequest.pb( contact_center_insights.DeleteAnalysisRuleRequest() @@ -53865,8 +53977,9 @@ def test_get_encryption_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53931,18 +54044,20 @@ def test_get_encryption_spec_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_encryption_spec" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_encryption_spec_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_encryption_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_encryption_spec" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_encryption_spec_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_encryption_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53997,8 +54112,9 @@ def test_initialize_encryption_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54057,22 +54173,23 @@ def test_initialize_encryption_spec_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_initialize_encryption_spec", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_initialize_encryption_spec_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_initialize_encryption_spec", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_initialize_encryption_spec", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_initialize_encryption_spec_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_initialize_encryption_spec", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -54125,8 +54242,9 @@ def test_create_view_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54267,18 +54385,20 @@ def test_create_view_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_view" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_view_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_view" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_view" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_view_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_view" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -54329,8 +54449,9 @@ def test_get_view_rest_bad_request(request_type=contact_center_insights.GetViewR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54397,17 +54518,20 @@ def test_get_view_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_view" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_view_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_view" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_view" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_view_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_view" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -54460,8 +54584,9 @@ def test_list_views_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54524,17 +54649,20 @@ def test_list_views_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_views" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_views_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_views" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_views" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_views_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_views" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -54594,8 +54722,9 @@ def test_update_view_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54738,18 +54867,20 @@ def test_update_view_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_view" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_view_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_view" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_view" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_view_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_view" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -54802,8 +54933,9 @@ def test_delete_view_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54860,13 +54992,13 @@ def test_delete_view_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_view" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_view" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteViewRequest.pb( contact_center_insights.DeleteViewRequest() @@ -54911,8 +55043,9 @@ def test_query_metrics_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -54969,20 +55102,21 @@ def test_query_metrics_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_query_metrics" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_query_metrics_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_query_metrics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_query_metrics" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_query_metrics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_query_metrics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -55037,8 +55171,9 @@ def test_create_qa_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -55208,18 +55343,20 @@ def test_create_qa_question_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_qa_question" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_qa_question_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_qa_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_qa_question" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_qa_question_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_qa_question" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -55274,8 +55411,9 @@ def test_get_qa_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -55350,18 +55488,20 @@ def test_get_qa_question_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_qa_question" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_qa_question_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_qa_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_qa_question" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_qa_question_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_qa_question" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -55418,8 +55558,9 @@ def test_update_qa_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -55591,18 +55732,20 @@ def test_update_qa_question_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_qa_question" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_qa_question_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_qa_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_qa_question" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_qa_question_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_qa_question" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -55657,8 +55800,9 @@ def test_delete_qa_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -55717,13 +55861,13 @@ def test_delete_qa_question_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_qa_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_qa_question" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteQaQuestionRequest.pb( contact_center_insights.DeleteQaQuestionRequest() @@ -55770,8 +55914,9 @@ def test_list_qa_questions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -55836,18 +55981,20 @@ def test_list_qa_questions_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_qa_questions" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_qa_questions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_qa_questions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_qa_questions" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_qa_questions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_qa_questions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -55905,8 +56052,9 @@ def test_create_qa_scorecard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56049,18 +56197,20 @@ def test_create_qa_scorecard_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_qa_scorecard" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_qa_scorecard_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_qa_scorecard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_create_qa_scorecard" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_qa_scorecard_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_qa_scorecard" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -56113,8 +56263,9 @@ def test_get_qa_scorecard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56181,18 +56332,20 @@ def test_get_qa_scorecard_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_qa_scorecard" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_qa_scorecard_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_qa_scorecard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_qa_scorecard" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_qa_scorecard_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_qa_scorecard" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -56249,8 +56402,9 @@ def test_update_qa_scorecard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56397,18 +56551,20 @@ def test_update_qa_scorecard_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_qa_scorecard" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_qa_scorecard_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_qa_scorecard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_update_qa_scorecard" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_qa_scorecard_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_qa_scorecard" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -56461,8 +56617,9 @@ def test_delete_qa_scorecard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56519,13 +56676,13 @@ def test_delete_qa_scorecard_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_qa_scorecard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_qa_scorecard" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteQaScorecardRequest.pb( contact_center_insights.DeleteQaScorecardRequest() @@ -56570,8 +56727,9 @@ def test_list_qa_scorecards_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56634,18 +56792,20 @@ def test_list_qa_scorecards_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_qa_scorecards" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_qa_scorecards_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_qa_scorecards" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_qa_scorecards" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_qa_scorecards_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_qa_scorecards" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -56703,8 +56863,9 @@ def test_create_qa_scorecard_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56855,20 +57016,22 @@ def test_create_qa_scorecard_revision_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_qa_scorecard_revision", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_qa_scorecard_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_create_qa_scorecard_revision", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_qa_scorecard_revision", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_qa_scorecard_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_create_qa_scorecard_revision", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -56925,8 +57088,9 @@ def test_get_qa_scorecard_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -56995,19 +57159,22 @@ def test_get_qa_scorecard_revision_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_qa_scorecard_revision", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_qa_scorecard_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_qa_scorecard_revision" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_qa_scorecard_revision", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_qa_scorecard_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_get_qa_scorecard_revision", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -57064,8 +57231,9 @@ def test_tune_qa_scorecard_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -57124,22 +57292,23 @@ def test_tune_qa_scorecard_revision_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_tune_qa_scorecard_revision", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_tune_qa_scorecard_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_tune_qa_scorecard_revision", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_tune_qa_scorecard_revision", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_tune_qa_scorecard_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_tune_qa_scorecard_revision", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -57194,8 +57363,9 @@ def test_deploy_qa_scorecard_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -57264,20 +57434,22 @@ def test_deploy_qa_scorecard_revision_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_deploy_qa_scorecard_revision", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_deploy_qa_scorecard_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_deploy_qa_scorecard_revision", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_deploy_qa_scorecard_revision", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_deploy_qa_scorecard_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_deploy_qa_scorecard_revision", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -57334,8 +57506,9 @@ def test_undeploy_qa_scorecard_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -57404,20 +57577,22 @@ def test_undeploy_qa_scorecard_revision_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_undeploy_qa_scorecard_revision", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_undeploy_qa_scorecard_revision_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_undeploy_qa_scorecard_revision", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_undeploy_qa_scorecard_revision", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_undeploy_qa_scorecard_revision_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_undeploy_qa_scorecard_revision", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -57474,8 +57649,9 @@ def test_delete_qa_scorecard_revision_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -57534,14 +57710,14 @@ def test_delete_qa_scorecard_revision_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_delete_qa_scorecard_revision", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_delete_qa_scorecard_revision", + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteQaScorecardRevisionRequest.pb( contact_center_insights.DeleteQaScorecardRevisionRequest() @@ -57586,8 +57762,9 @@ def test_list_qa_scorecard_revisions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -57652,20 +57829,22 @@ def test_list_qa_scorecard_revisions_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_qa_scorecard_revisions", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_qa_scorecard_revisions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_list_qa_scorecard_revisions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_qa_scorecard_revisions", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_qa_scorecard_revisions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_list_qa_scorecard_revisions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -57725,8 +57904,9 @@ def test_create_feedback_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -57880,18 +58060,21 @@ def test_create_feedback_label_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_create_feedback_label" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_create_feedback_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_create_feedback_label" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_feedback_label", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_create_feedback_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_create_feedback_label" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -57946,8 +58129,9 @@ def test_list_feedback_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58014,18 +58198,20 @@ def test_list_feedback_labels_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_feedback_labels" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_feedback_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_feedback_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_list_feedback_labels" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_feedback_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_list_feedback_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -58085,8 +58271,9 @@ def test_get_feedback_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58154,18 +58341,20 @@ def test_get_feedback_label_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_get_feedback_label" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_get_feedback_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_get_feedback_label" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "post_get_feedback_label" + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_get_feedback_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_get_feedback_label" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -58222,8 +58411,9 @@ def test_update_feedback_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58379,18 +58569,21 @@ def test_update_feedback_label_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_update_feedback_label" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_update_feedback_label_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_update_feedback_label" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_feedback_label", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_update_feedback_label_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_update_feedback_label" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -58445,8 +58638,9 @@ def test_delete_feedback_label_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58505,13 +58699,13 @@ def test_delete_feedback_label_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_delete_feedback_label" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, "pre_delete_feedback_label" + ) as pre, + ): pre.assert_not_called() pb_message = contact_center_insights.DeleteFeedbackLabelRequest.pb( contact_center_insights.DeleteFeedbackLabelRequest() @@ -58556,8 +58750,9 @@ def test_list_all_feedback_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58622,18 +58817,22 @@ def test_list_all_feedback_labels_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "post_list_all_feedback_labels" - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_list_all_feedback_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, "pre_list_all_feedback_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_all_feedback_labels", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_list_all_feedback_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_list_all_feedback_labels", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -58691,8 +58890,9 @@ def test_bulk_upload_feedback_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58749,22 +58949,23 @@ def test_bulk_upload_feedback_labels_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_upload_feedback_labels", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_upload_feedback_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_bulk_upload_feedback_labels", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_upload_feedback_labels", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_upload_feedback_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_bulk_upload_feedback_labels", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -58817,8 +59018,9 @@ def test_bulk_download_feedback_labels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -58875,22 +59077,23 @@ def test_bulk_download_feedback_labels_rest_interceptors(null_interceptor): ) client = ContactCenterInsightsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_download_feedback_labels", - ) as post, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "post_bulk_download_feedback_labels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContactCenterInsightsRestInterceptor, - "pre_bulk_download_feedback_labels", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_download_feedback_labels", + ) as post, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "post_bulk_download_feedback_labels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContactCenterInsightsRestInterceptor, + "pre_bulk_download_feedback_labels", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -58945,8 +59148,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -59007,8 +59211,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -59069,8 +59274,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -60862,11 +61068,14 @@ def test_contact_center_insights_base_transport(): def test_contact_center_insights_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contact_center_insights_v1.services.contact_center_insights.transports.ContactCenterInsightsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contact_center_insights_v1.services.contact_center_insights.transports.ContactCenterInsightsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContactCenterInsightsTransport( @@ -60883,9 +61092,12 @@ def test_contact_center_insights_base_transport_with_credentials_file(): def test_contact_center_insights_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contact_center_insights_v1.services.contact_center_insights.transports.ContactCenterInsightsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contact_center_insights_v1.services.contact_center_insights.transports.ContactCenterInsightsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContactCenterInsightsTransport() @@ -60959,11 +61171,12 @@ def test_contact_center_insights_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -62245,6 +62458,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ContactCenterInsightsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ContactCenterInsightsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ContactCenterInsightsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -62390,6 +62635,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ContactCenterInsightsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ContactCenterInsightsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ContactCenterInsightsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -62535,6 +62814,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ContactCenterInsightsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ContactCenterInsightsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ContactCenterInsightsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/async_client.py b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/async_client.py index 8efb679832ed..0c78dce22b6a 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/async_client.py +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ClusterManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/client.py b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/client.py index 73e6493415ea..7ac6a0b894d6 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/client.py +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/client.py @@ -111,7 +111,7 @@ class ClusterManagerClient(metaclass=ClusterManagerClientMeta): """Google Kubernetes Engine Cluster Manager v1""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -501,7 +505,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -598,7 +602,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -694,7 +698,7 @@ def __init__( self._universe_domain = ClusterManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/README.rst b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/README.rst index 4b8234a968af..f0173c7f5edf 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/README.rst +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ClusterManagerTransport` is the ABC for all transports. -- public child `ClusterManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ClusterManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseClusterManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ClusterManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ClusterManagerTransport`` is the ABC for all transports. + +- public child ``ClusterManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ClusterManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseClusterManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ClusterManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/base.py b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/base.py index 16201009e18f..c8be4e111c56 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/base.py +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc.py b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc.py index f25e3046a2b0..7a59031d1d80 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc.py +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc_asyncio.py b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc_asyncio.py index 60d3d78e1644..ebc96ac3eb1e 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/rest.py b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/rest.py index d026a2c5cb4e..4afbc5bd0b49 100644 --- a/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/rest.py +++ b/packages/google-cloud-container/google/cloud/container_v1/services/cluster_manager/transports/rest.py @@ -2116,6 +2116,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ClusterManagerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/async_client.py b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/async_client.py index eb0095a767bd..66d02042698b 100644 --- a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/async_client.py +++ b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ClusterManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/client.py b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/client.py index 366430f47bfe..9d5b512e750c 100644 --- a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/client.py +++ b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/client.py @@ -109,7 +109,7 @@ class ClusterManagerClient(metaclass=ClusterManagerClientMeta): """Google Kubernetes Engine Cluster Manager v1beta1""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -117,7 +117,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -127,6 +127,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -499,7 +503,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -596,7 +600,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -692,7 +696,7 @@ def __init__( self._universe_domain = ClusterManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/README.rst b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/README.rst index 4b8234a968af..f0173c7f5edf 100644 --- a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/README.rst +++ b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ClusterManagerTransport` is the ABC for all transports. -- public child `ClusterManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ClusterManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseClusterManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ClusterManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ClusterManagerTransport`` is the ABC for all transports. + +- public child ``ClusterManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ClusterManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseClusterManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ClusterManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/base.py b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/base.py index 2ed6c696ecd1..39ea174d211f 100644 --- a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/base.py +++ b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc.py b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc.py index a238762b9918..15f2c5dcbd7e 100644 --- a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc.py +++ b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc_asyncio.py b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc_asyncio.py index 5b95c1723c06..160b4bc16469 100644 --- a/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-container/google/cloud/container_v1beta1/services/cluster_manager/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-container/noxfile.py b/packages/google-cloud-container/noxfile.py index 1b0993589f0f..34d68a6a8949 100644 --- a/packages/google-cloud-container/noxfile.py +++ b/packages/google-cloud-container/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-container/setup.py b/packages/google-cloud-container/setup.py index 64ba083c2bbb..0ef6b855c8a7 100644 --- a/packages/google-cloud-container/setup.py +++ b/packages/google-cloud-container/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-container" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-container/testing/constraints-3.7.txt b/packages/google-cloud-container/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-container/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-container/testing/constraints-3.8.txt b/packages/google-cloud-container/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-container/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-container/testing/constraints-3.9.txt b/packages/google-cloud-container/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-container/testing/constraints-3.9.txt +++ b/packages/google-cloud-container/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-container/tests/unit/gapic/container_v1/test_cluster_manager.py b/packages/google-cloud-container/tests/unit/gapic/container_v1/test_cluster_manager.py index edd061045b5b..6cdd523036f5 100644 --- a/packages/google-cloud-container/tests/unit/gapic/container_v1/test_cluster_manager.py +++ b/packages/google-cloud-container/tests/unit/gapic/container_v1/test_cluster_manager.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ClusterManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ClusterManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ClusterManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_cluster_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -21887,8 +21894,9 @@ def test_list_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21951,17 +21959,19 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_list_clusters_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22017,8 +22027,9 @@ def test_get_cluster_rest_bad_request(request_type=cluster_service.GetClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22145,17 +22156,19 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22208,8 +22221,9 @@ def test_create_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22292,17 +22306,20 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_create_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22355,8 +22372,9 @@ def test_update_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22439,17 +22457,20 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_update_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22504,8 +22525,9 @@ def test_update_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22590,17 +22612,20 @@ def test_update_node_pool_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_update_node_pool" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_update_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_update_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_update_node_pool" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_update_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_update_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22655,8 +22680,9 @@ def test_set_node_pool_autoscaling_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22741,18 +22767,20 @@ def test_set_node_pool_autoscaling_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_node_pool_autoscaling" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_node_pool_autoscaling_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_node_pool_autoscaling" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_node_pool_autoscaling" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_node_pool_autoscaling_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_node_pool_autoscaling" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22805,8 +22833,9 @@ def test_set_logging_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22889,18 +22918,20 @@ def test_set_logging_service_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_logging_service" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_logging_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_logging_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_logging_service" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_logging_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_logging_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22953,8 +22984,9 @@ def test_set_monitoring_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23037,18 +23069,20 @@ def test_set_monitoring_service_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_monitoring_service" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_monitoring_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_monitoring_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_monitoring_service" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_monitoring_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_monitoring_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23101,8 +23135,9 @@ def test_set_addons_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23185,17 +23220,20 @@ def test_set_addons_config_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_addons_config" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_addons_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_addons_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_addons_config" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_addons_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_addons_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23248,8 +23286,9 @@ def test_set_locations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23332,17 +23371,19 @@ def test_set_locations_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_locations" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_locations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_locations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_locations" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_locations_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_locations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23395,8 +23436,9 @@ def test_update_master_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23479,17 +23521,19 @@ def test_update_master_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_update_master" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_update_master_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_update_master" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_update_master" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_update_master_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_update_master" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23542,8 +23586,9 @@ def test_set_master_auth_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23626,17 +23671,20 @@ def test_set_master_auth_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_master_auth" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_master_auth_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_master_auth" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_master_auth" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_master_auth_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_master_auth" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23689,8 +23737,9 @@ def test_delete_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23773,17 +23822,20 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_delete_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23836,8 +23888,9 @@ def test_list_operations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23900,17 +23953,20 @@ def test_list_operations_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_operations" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_operations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_list_operations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_list_operations" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_list_operations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_list_operations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23968,8 +24024,9 @@ def test_get_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24052,17 +24109,19 @@ def test_get_operation_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_operation" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_operation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_get_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_operation" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_operation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_get_operation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24115,8 +24174,9 @@ def test_cancel_operation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24173,13 +24233,13 @@ def test_cancel_operation_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_cancel_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_cancel_operation" + ) as pre, + ): pre.assert_not_called() pb_message = cluster_service.CancelOperationRequest.pb( cluster_service.CancelOperationRequest() @@ -24224,8 +24284,9 @@ def test_get_server_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24296,17 +24357,20 @@ def test_get_server_config_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_server_config" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_server_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_get_server_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_server_config" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_get_server_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_get_server_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24361,8 +24425,9 @@ def test_get_json_web_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24422,17 +24487,20 @@ def test_get_json_web_keys_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_json_web_keys" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_json_web_keys_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_get_json_web_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_json_web_keys" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_get_json_web_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_get_json_web_keys" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24490,8 +24558,9 @@ def test_list_node_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24551,17 +24620,20 @@ def test_list_node_pools_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_node_pools" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_node_pools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_list_node_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_list_node_pools" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_list_node_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_list_node_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24621,8 +24693,9 @@ def test_get_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24705,17 +24778,19 @@ def test_get_node_pool_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_node_pool" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_get_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_get_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_node_pool" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_get_node_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_get_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24768,8 +24843,9 @@ def test_create_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24852,17 +24928,20 @@ def test_create_node_pool_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_create_node_pool" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_create_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_create_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_create_node_pool" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_create_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_create_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24917,8 +24996,9 @@ def test_delete_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25003,17 +25083,20 @@ def test_delete_node_pool_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_delete_node_pool" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_delete_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_delete_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_delete_node_pool" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_delete_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_delete_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25068,8 +25151,9 @@ def test_complete_node_pool_upgrade_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25128,13 +25212,13 @@ def test_complete_node_pool_upgrade_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_complete_node_pool_upgrade" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_complete_node_pool_upgrade" + ) as pre, + ): pre.assert_not_called() pb_message = cluster_service.CompleteNodePoolUpgradeRequest.pb( cluster_service.CompleteNodePoolUpgradeRequest() @@ -25181,8 +25265,9 @@ def test_rollback_node_pool_upgrade_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25267,18 +25352,20 @@ def test_rollback_node_pool_upgrade_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_rollback_node_pool_upgrade" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_rollback_node_pool_upgrade_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_rollback_node_pool_upgrade" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_rollback_node_pool_upgrade" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_rollback_node_pool_upgrade_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_rollback_node_pool_upgrade" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25333,8 +25420,9 @@ def test_set_node_pool_management_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25419,18 +25507,20 @@ def test_set_node_pool_management_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_node_pool_management" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_node_pool_management_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_node_pool_management" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_node_pool_management" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_node_pool_management_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_node_pool_management" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25481,8 +25571,9 @@ def test_set_labels_rest_bad_request(request_type=cluster_service.SetLabelsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25565,17 +25656,19 @@ def test_set_labels_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_labels" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_labels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_labels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_labels" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_labels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_labels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25628,8 +25721,9 @@ def test_set_legacy_abac_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25712,17 +25806,20 @@ def test_set_legacy_abac_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_legacy_abac" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_legacy_abac_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_legacy_abac" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_legacy_abac" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_legacy_abac_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_legacy_abac" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25775,8 +25872,9 @@ def test_start_ip_rotation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25859,17 +25957,20 @@ def test_start_ip_rotation_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_start_ip_rotation" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_start_ip_rotation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_start_ip_rotation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_start_ip_rotation" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_start_ip_rotation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_start_ip_rotation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25922,8 +26023,9 @@ def test_complete_ip_rotation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26006,18 +26108,20 @@ def test_complete_ip_rotation_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_complete_ip_rotation" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_complete_ip_rotation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_complete_ip_rotation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_complete_ip_rotation" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_complete_ip_rotation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_complete_ip_rotation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26072,8 +26176,9 @@ def test_set_node_pool_size_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26158,18 +26263,20 @@ def test_set_node_pool_size_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_node_pool_size" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_node_pool_size_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_node_pool_size" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_node_pool_size" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_node_pool_size_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_node_pool_size" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26222,8 +26329,9 @@ def test_set_network_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26306,18 +26414,20 @@ def test_set_network_policy_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_network_policy" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_network_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_network_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_network_policy" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_network_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_network_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26370,8 +26480,9 @@ def test_set_maintenance_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26454,18 +26565,20 @@ def test_set_maintenance_policy_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_set_maintenance_policy" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_set_maintenance_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_set_maintenance_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_set_maintenance_policy" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_set_maintenance_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_set_maintenance_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26518,8 +26631,9 @@ def test_list_usable_subnetworks_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26582,18 +26696,20 @@ def test_list_usable_subnetworks_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_list_usable_subnetworks" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_list_usable_subnetworks_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_list_usable_subnetworks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_list_usable_subnetworks" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_list_usable_subnetworks_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_list_usable_subnetworks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26651,8 +26767,9 @@ def test_check_autopilot_compatibility_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26717,18 +26834,22 @@ def test_check_autopilot_compatibility_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_check_autopilot_compatibility" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_check_autopilot_compatibility_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_check_autopilot_compatibility" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_check_autopilot_compatibility", + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_check_autopilot_compatibility_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "pre_check_autopilot_compatibility", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26786,8 +26907,9 @@ def test_fetch_cluster_upgrade_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26874,18 +26996,20 @@ def test_fetch_cluster_upgrade_info_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_fetch_cluster_upgrade_info" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_fetch_cluster_upgrade_info_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_fetch_cluster_upgrade_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "post_fetch_cluster_upgrade_info" + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_fetch_cluster_upgrade_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_fetch_cluster_upgrade_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26942,8 +27066,9 @@ def test_fetch_node_pool_upgrade_info_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27032,18 +27157,21 @@ def test_fetch_node_pool_upgrade_info_rest_interceptors(null_interceptor): ) client = ClusterManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterManagerRestInterceptor, "post_fetch_node_pool_upgrade_info" - ) as post, mock.patch.object( - transports.ClusterManagerRestInterceptor, - "post_fetch_node_pool_upgrade_info_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterManagerRestInterceptor, "pre_fetch_node_pool_upgrade_info" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_fetch_node_pool_upgrade_info", + ) as post, + mock.patch.object( + transports.ClusterManagerRestInterceptor, + "post_fetch_node_pool_upgrade_info_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterManagerRestInterceptor, "pre_fetch_node_pool_upgrade_info" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27941,11 +28069,14 @@ def test_cluster_manager_base_transport(): def test_cluster_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.container_v1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.container_v1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClusterManagerTransport( @@ -27962,9 +28093,12 @@ def test_cluster_manager_base_transport_with_credentials_file(): def test_cluster_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.container_v1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.container_v1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClusterManagerTransport() @@ -28036,11 +28170,12 @@ def test_cluster_manager_transport_auth_gdch_credentials(transport_class): def test_cluster_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-container/tests/unit/gapic/container_v1beta1/test_cluster_manager.py b/packages/google-cloud-container/tests/unit/gapic/container_v1beta1/test_cluster_manager.py index f503bd7256b4..155473904ee9 100644 --- a/packages/google-cloud-container/tests/unit/gapic/container_v1beta1/test_cluster_manager.py +++ b/packages/google-cloud-container/tests/unit/gapic/container_v1beta1/test_cluster_manager.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ClusterManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): assert ( ClusterManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ClusterManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1265,11 +1270,13 @@ def test_cluster_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -18016,11 +18023,14 @@ def test_cluster_manager_base_transport(): def test_cluster_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.container_v1beta1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.container_v1beta1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClusterManagerTransport( @@ -18037,9 +18047,12 @@ def test_cluster_manager_base_transport_with_credentials_file(): def test_cluster_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.container_v1beta1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.container_v1beta1.services.cluster_manager.transports.ClusterManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClusterManagerTransport() @@ -18110,11 +18123,12 @@ def test_cluster_manager_transport_auth_gdch_credentials(transport_class): def test_cluster_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py index 82470402c8aa..adb1e78eaefb 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> ContainerAnalysisTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py index 302e5c8c9361..9ad4e7cc7aea 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py @@ -128,7 +128,7 @@ class ContainerAnalysisClient(metaclass=ContainerAnalysisClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -431,7 +435,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = ContainerAnalysisClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/README.rst b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/README.rst index bb31ff2a3d4f..249aaadd3e18 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/README.rst +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContainerAnalysisTransport` is the ABC for all transports. -- public child `ContainerAnalysisGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContainerAnalysisGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContainerAnalysisRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContainerAnalysisRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContainerAnalysisTransport`` is the ABC for all transports. + +- public child ``ContainerAnalysisGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContainerAnalysisGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContainerAnalysisRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContainerAnalysisRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/base.py b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/base.py index 5519704e8561..ba76ec369b33 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/base.py +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py index 54416e8ad6b2..123aa21d0e0b 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -200,6 +200,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py index a63ab06bf1b0..22604d84fcde 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -251,6 +251,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/rest.py b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/rest.py index 5d52cf3b8637..96433743ea74 100644 --- a/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/rest.py +++ b/packages/google-cloud-containeranalysis/google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/rest.py @@ -447,6 +447,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContainerAnalysisRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-containeranalysis/noxfile.py b/packages/google-cloud-containeranalysis/noxfile.py index b8b1323ca676..58617355fb2a 100644 --- a/packages/google-cloud-containeranalysis/noxfile.py +++ b/packages/google-cloud-containeranalysis/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-containeranalysis/setup.py b/packages/google-cloud-containeranalysis/setup.py index 2062fd3203b8..da0d14d9f9a4 100644 --- a/packages/google-cloud-containeranalysis/setup.py +++ b/packages/google-cloud-containeranalysis/setup.py @@ -43,16 +43,16 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "grafeas >=1.4.1, <2.0", + "grafeas >=1.7.0, <2.0", "grpcio >= 1.33.2, < 2.0.0", "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -85,8 +85,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -98,7 +96,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-containeranalysis/testing/constraints-3.7.txt b/packages/google-cloud-containeranalysis/testing/constraints-3.7.txt deleted file mode 100644 index e2c541a156d5..000000000000 --- a/packages/google-cloud-containeranalysis/testing/constraints-3.7.txt +++ /dev/null @@ -1,16 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -grafeas==1.4.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-containeranalysis/testing/constraints-3.8.txt b/packages/google-cloud-containeranalysis/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-containeranalysis/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-containeranalysis/testing/constraints-3.9.txt b/packages/google-cloud-containeranalysis/testing/constraints-3.9.txt index 1cd0c5a2c3d4..b881d222bed8 100644 --- a/packages/google-cloud-containeranalysis/testing/constraints-3.9.txt +++ b/packages/google-cloud-containeranalysis/testing/constraints-3.9.txt @@ -1,11 +1,15 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +grafeas==1.7.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-containeranalysis/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py b/packages/google-cloud-containeranalysis/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py index 08e8c4d9f2f5..cfe2bce239a6 100644 --- a/packages/google-cloud-containeranalysis/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py +++ b/packages/google-cloud-containeranalysis/tests/unit/gapic/containeranalysis_v1/test_container_analysis.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContainerAnalysisClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): ContainerAnalysisClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContainerAnalysisClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1322,11 +1327,13 @@ def test_container_analysis_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4248,8 +4255,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4311,17 +4319,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ContainerAnalysisClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4372,8 +4383,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4435,17 +4447,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ContainerAnalysisClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4496,8 +4511,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4557,18 +4573,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ContainerAnalysisClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4624,8 +4642,9 @@ def test_get_vulnerability_occurrences_summary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4687,20 +4706,22 @@ def test_get_vulnerability_occurrences_summary_rest_interceptors(null_intercepto ) client = ContainerAnalysisClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, - "post_get_vulnerability_occurrences_summary", - ) as post, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, - "post_get_vulnerability_occurrences_summary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, - "pre_get_vulnerability_occurrences_summary", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "post_get_vulnerability_occurrences_summary", + ) as post, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "post_get_vulnerability_occurrences_summary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "pre_get_vulnerability_occurrences_summary", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4756,8 +4777,9 @@ def test_export_sbom_rest_bad_request(request_type=containeranalysis.ExportSBOMR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4820,17 +4842,20 @@ def test_export_sbom_rest_interceptors(null_interceptor): ) client = ContainerAnalysisClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_export_sbom" - ) as post, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "post_export_sbom_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContainerAnalysisRestInterceptor, "pre_export_sbom" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "post_export_sbom" + ) as post, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, + "post_export_sbom_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContainerAnalysisRestInterceptor, "pre_export_sbom" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5045,11 +5070,14 @@ def test_container_analysis_base_transport(): def test_container_analysis_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.devtools.containeranalysis_v1.services.container_analysis.transports.ContainerAnalysisTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.devtools.containeranalysis_v1.services.container_analysis.transports.ContainerAnalysisTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContainerAnalysisTransport( @@ -5066,9 +5094,12 @@ def test_container_analysis_base_transport_with_credentials_file(): def test_container_analysis_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.devtools.containeranalysis_v1.services.container_analysis.transports.ContainerAnalysisTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.devtools.containeranalysis_v1.services.container_analysis.transports.ContainerAnalysisTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContainerAnalysisTransport() @@ -5140,11 +5171,12 @@ def test_container_analysis_transport_auth_gdch_credentials(transport_class): def test_container_analysis_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/async_client.py index 6d694a3e1f37..b62e17ae8b96 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> DocumentLinkServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -782,7 +782,7 @@ async def sample_delete_document_link(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -808,8 +808,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -818,7 +822,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -826,7 +830,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/client.py index 425755509bc6..3ec61f58f9e6 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/client.py @@ -115,7 +115,7 @@ class DocumentLinkServiceClient(metaclass=DocumentLinkServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -561,7 +565,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = DocumentLinkServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1232,7 +1236,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1258,8 +1262,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1268,7 +1276,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1277,7 +1285,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/README.rst b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/README.rst index 4e3d9ba6d450..865f0f844363 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/README.rst +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentLinkServiceTransport` is the ABC for all transports. -- public child `DocumentLinkServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentLinkServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentLinkServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentLinkServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentLinkServiceTransport`` is the ABC for all transports. + +- public child ``DocumentLinkServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentLinkServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentLinkServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentLinkServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/base.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/base.py index 85020638704d..0b4adc7e79fe 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/base.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc.py index 062d8c50c93c..e2b04de62d44 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc_asyncio.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc_asyncio.py index 3d3d0156853b..1c800a751e9d 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/rest.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/rest.py index 91499a2b98e1..a804d763db5a 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/rest.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_link_service/transports/rest.py @@ -372,6 +372,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentLinkServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/async_client.py index e60bd140dcf1..8c0e16a5eedc 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> DocumentSchemaServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -923,7 +923,7 @@ async def sample_list_document_schemas(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -949,8 +949,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -959,7 +963,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -967,7 +971,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/client.py index 706149da6cc6..287d5463b10d 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/client.py @@ -118,7 +118,7 @@ class DocumentSchemaServiceClient(metaclass=DocumentSchemaServiceClientMeta): """This service lets you manage document schema.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -460,7 +464,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -559,7 +563,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -659,7 +663,7 @@ def __init__( self._universe_domain = DocumentSchemaServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1361,7 +1365,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1387,8 +1391,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1397,7 +1405,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1406,7 +1414,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/README.rst b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/README.rst index fd0bc7e8c28b..042ed64b5449 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/README.rst +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentSchemaServiceTransport` is the ABC for all transports. -- public child `DocumentSchemaServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentSchemaServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentSchemaServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentSchemaServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentSchemaServiceTransport`` is the ABC for all transports. + +- public child ``DocumentSchemaServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentSchemaServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentSchemaServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentSchemaServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/base.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/base.py index 1409b5deed56..bdb4037834b1 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/base.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc.py index c4b285be66b6..6b3fb4d7e9d8 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc_asyncio.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc_asyncio.py index 8f555bbf3928..91790d21c5c3 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/rest.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/rest.py index f74c8433b2b3..acf0ee8294f3 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/rest.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_schema_service/transports/rest.py @@ -432,6 +432,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentSchemaServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/async_client.py index 797b2c7a0176..30addc63a86c 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> DocumentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1299,7 +1299,7 @@ async def sample_set_acl(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1325,8 +1325,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1335,7 +1339,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1343,7 +1347,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/client.py index 65ab77fb8633..ae1bb6db4116 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/client.py @@ -121,7 +121,7 @@ class DocumentServiceClient(metaclass=DocumentServiceClientMeta): """This service lets you manage document.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -485,7 +489,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -582,7 +586,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -680,7 +684,7 @@ def __init__( self._universe_domain = DocumentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1753,7 +1757,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1779,8 +1783,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1789,7 +1797,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1798,7 +1806,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/README.rst b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/README.rst index 4aabee4652ef..765422bd31c7 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/README.rst +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentServiceTransport` is the ABC for all transports. -- public child `DocumentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentServiceTransport`` is the ABC for all transports. + +- public child ``DocumentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/base.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/base.py index 735a27928b7d..de69c8a799b1 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/base.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc.py index fcd89b2a25f1..f37df5ae34eb 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc_asyncio.py index 4859ac9a2562..7c4c743311a7 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/rest.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/rest.py index f592a3b3f934..01a5854c2006 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/rest.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/document_service/transports/rest.py @@ -604,6 +604,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py index 6b5195c82c94..0fe3a70614a5 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> PipelineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -431,7 +431,7 @@ async def sample_run_pipeline(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -457,8 +457,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -467,7 +471,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -475,7 +479,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py index b766c59cb78c..999f8eb52298 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/client.py @@ -112,7 +112,7 @@ class PipelineServiceClient(metaclass=PipelineServiceClientMeta): """This service lets you manage pipelines.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -454,7 +458,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -551,7 +555,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -649,7 +653,7 @@ def __init__( self._universe_domain = PipelineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -884,7 +888,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -910,8 +914,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -920,7 +928,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -929,7 +937,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/README.rst b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/README.rst index b5f17d1cea76..82250888a7e9 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/README.rst +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PipelineServiceTransport` is the ABC for all transports. -- public child `PipelineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PipelineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePipelineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PipelineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PipelineServiceTransport`` is the ABC for all transports. + +- public child ``PipelineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PipelineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePipelineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PipelineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/base.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/base.py index 1fab48ac4a0c..0c93f321f412 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/base.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc.py index fdc362786873..445b883c2503 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc_asyncio.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc_asyncio.py index fb31a8e09dcf..3a4d95abdcd2 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/rest.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/rest.py index 8cf1c3a024d4..5ab14d225c9c 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/rest.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/pipeline_service/transports/rest.py @@ -227,6 +227,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PipelineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/async_client.py index 2d578774a93d..c0740263f07c 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> RuleSetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -888,7 +888,7 @@ async def sample_list_rule_sets(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -914,8 +914,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -924,7 +928,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -932,7 +936,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/client.py index 1e3f98b76fbe..330d692823da 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/client.py @@ -111,7 +111,7 @@ class RuleSetServiceClient(metaclass=RuleSetServiceClientMeta): """Service to manage customer specific RuleSets.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -475,7 +479,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -572,7 +576,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -668,7 +672,7 @@ def __init__( self._universe_domain = RuleSetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1351,7 +1355,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1377,8 +1381,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1387,7 +1395,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1396,7 +1404,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/README.rst b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/README.rst index 779e83f473d9..044c19d0a405 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/README.rst +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RuleSetServiceTransport` is the ABC for all transports. -- public child `RuleSetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RuleSetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRuleSetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RuleSetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RuleSetServiceTransport`` is the ABC for all transports. + +- public child ``RuleSetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RuleSetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRuleSetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RuleSetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/base.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/base.py index a1f032810132..0367780b74fd 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/base.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc.py index 15397de8c191..ac4ae2880e0b 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc_asyncio.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc_asyncio.py index 3f318a28deab..4c21d4d28859 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/rest.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/rest.py index 7389dac1e660..45fbe0b248d9 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/rest.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/rule_set_service/transports/rest.py @@ -420,6 +420,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RuleSetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/async_client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/async_client.py index 9be051cafa74..4cf6f172d5f0 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/async_client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> SynonymSetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -930,7 +930,7 @@ async def sample_list_synonym_sets(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -956,8 +956,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -966,7 +970,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -974,7 +978,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/client.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/client.py index 37eb13b8c3bd..a47fab7d51de 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/client.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/client.py @@ -114,7 +114,7 @@ class SynonymSetServiceClient(metaclass=SynonymSetServiceClientMeta): """A Service that manage/custom customer specified SynonymSets.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -456,7 +460,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -553,7 +557,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -653,7 +657,7 @@ def __init__( self._universe_domain = SynonymSetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1372,7 +1376,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1398,8 +1402,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1408,7 +1416,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1417,7 +1425,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/README.rst b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/README.rst index ac041fd50093..254db74d0250 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/README.rst +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SynonymSetServiceTransport` is the ABC for all transports. -- public child `SynonymSetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SynonymSetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSynonymSetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SynonymSetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SynonymSetServiceTransport`` is the ABC for all transports. + +- public child ``SynonymSetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SynonymSetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSynonymSetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SynonymSetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/base.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/base.py index 0ffa74f0831c..06ae030d37bd 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/base.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc.py index 8d1bb01fb6f0..e06729962ce2 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc_asyncio.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc_asyncio.py index 9e7068f63034..3ac41c81ac76 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/rest.py b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/rest.py index 05411c68ca75..b2eda5d22b0f 100644 --- a/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/rest.py +++ b/packages/google-cloud-contentwarehouse/google/cloud/contentwarehouse_v1/services/synonym_set_service/transports/rest.py @@ -425,6 +425,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SynonymSetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-contentwarehouse/noxfile.py b/packages/google-cloud-contentwarehouse/noxfile.py index 8acf4f4899f6..df7d5cd69569 100644 --- a/packages/google-cloud-contentwarehouse/noxfile.py +++ b/packages/google-cloud-contentwarehouse/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-contentwarehouse/setup.py b/packages/google-cloud-contentwarehouse/setup.py index 43a4f68b35c5..c178fb506885 100644 --- a/packages/google-cloud-contentwarehouse/setup.py +++ b/packages/google-cloud-contentwarehouse/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "google-cloud-documentai >= 2.0.0, <4.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] @@ -83,8 +83,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -96,7 +94,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-contentwarehouse/testing/constraints-3.7.txt b/packages/google-cloud-contentwarehouse/testing/constraints-3.7.txt deleted file mode 100644 index 1d6a49c103cd..000000000000 --- a/packages/google-cloud-contentwarehouse/testing/constraints-3.7.txt +++ /dev/null @@ -1,16 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -google-cloud-documentai==2.0.0 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-contentwarehouse/testing/constraints-3.8.txt b/packages/google-cloud-contentwarehouse/testing/constraints-3.8.txt deleted file mode 100644 index 3f7830f80cde..000000000000 --- a/packages/google-cloud-contentwarehouse/testing/constraints-3.8.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-cloud-documentai -grpc-google-iam-v1 diff --git a/packages/google-cloud-contentwarehouse/testing/constraints-3.9.txt b/packages/google-cloud-contentwarehouse/testing/constraints-3.9.txt index 3f7830f80cde..7168eec7d2ba 100644 --- a/packages/google-cloud-contentwarehouse/testing/constraints-3.9.txt +++ b/packages/google-cloud-contentwarehouse/testing/constraints-3.9.txt @@ -1,12 +1,15 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-cloud-documentai -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +google-cloud-documentai==2.0.0 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_link_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_link_service.py index c6af2ce1b655..bc70b53614d7 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_link_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_link_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentLinkServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): DocumentLinkServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentLinkServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1346,11 +1351,13 @@ def test_document_link_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4109,8 +4116,9 @@ def test_list_linked_targets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4175,18 +4183,20 @@ def test_list_linked_targets_rest_interceptors(null_interceptor): ) client = DocumentLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "post_list_linked_targets" - ) as post, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, - "post_list_linked_targets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "pre_list_linked_targets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "post_list_linked_targets" + ) as post, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, + "post_list_linked_targets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "pre_list_linked_targets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4244,8 +4254,9 @@ def test_list_linked_sources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4308,18 +4319,20 @@ def test_list_linked_sources_rest_interceptors(null_interceptor): ) client = DocumentLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "post_list_linked_sources" - ) as post, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, - "post_list_linked_sources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "pre_list_linked_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "post_list_linked_sources" + ) as post, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, + "post_list_linked_sources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "pre_list_linked_sources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4377,8 +4390,9 @@ def test_create_document_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4445,18 +4459,20 @@ def test_create_document_link_rest_interceptors(null_interceptor): ) client = DocumentLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "post_create_document_link" - ) as post, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, - "post_create_document_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "pre_create_document_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "post_create_document_link" + ) as post, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, + "post_create_document_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "pre_create_document_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4513,8 +4529,9 @@ def test_delete_document_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4573,13 +4590,13 @@ def test_delete_document_link_rest_interceptors(null_interceptor): ) client = DocumentLinkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentLinkServiceRestInterceptor, "pre_delete_document_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentLinkServiceRestInterceptor, "pre_delete_document_link" + ) as pre, + ): pre.assert_not_called() pb_message = document_link_service.DeleteDocumentLinkRequest.pb( document_link_service.DeleteDocumentLinkRequest() @@ -4626,8 +4643,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4827,11 +4845,14 @@ def test_document_link_service_base_transport(): def test_document_link_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contentwarehouse_v1.services.document_link_service.transports.DocumentLinkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contentwarehouse_v1.services.document_link_service.transports.DocumentLinkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentLinkServiceTransport( @@ -4848,9 +4869,12 @@ def test_document_link_service_base_transport_with_credentials_file(): def test_document_link_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contentwarehouse_v1.services.document_link_service.transports.DocumentLinkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contentwarehouse_v1.services.document_link_service.transports.DocumentLinkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentLinkServiceTransport() @@ -4922,11 +4946,12 @@ def test_document_link_service_transport_auth_gdch_credentials(transport_class): def test_document_link_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5537,6 +5562,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentLinkServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentLinkServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = DocumentLinkServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_schema_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_schema_service.py index 82e6936aae42..8e7f612c32d9 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_schema_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_schema_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentSchemaServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): DocumentSchemaServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentSchemaServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_document_schema_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4761,8 +4768,9 @@ def test_create_document_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4937,18 +4945,22 @@ def test_create_document_schema_rest_interceptors(null_interceptor): ) client = DocumentSchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "post_create_document_schema" - ) as post, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, - "post_create_document_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "pre_create_document_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_create_document_schema", + ) as post, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_create_document_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "pre_create_document_schema", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5005,8 +5017,9 @@ def test_update_document_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5077,18 +5090,22 @@ def test_update_document_schema_rest_interceptors(null_interceptor): ) client = DocumentSchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "post_update_document_schema" - ) as post, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, - "post_update_document_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "pre_update_document_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_update_document_schema", + ) as post, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_update_document_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "pre_update_document_schema", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5145,8 +5162,9 @@ def test_get_document_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5217,18 +5235,20 @@ def test_get_document_schema_rest_interceptors(null_interceptor): ) client = DocumentSchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "post_get_document_schema" - ) as post, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, - "post_get_document_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "pre_get_document_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, "post_get_document_schema" + ) as post, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_get_document_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, "pre_get_document_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5285,8 +5305,9 @@ def test_delete_document_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5345,13 +5366,14 @@ def test_delete_document_schema_rest_interceptors(null_interceptor): ) client = DocumentSchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "pre_delete_document_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "pre_delete_document_schema", + ) as pre, + ): pre.assert_not_called() pb_message = document_schema_service.DeleteDocumentSchemaRequest.pb( document_schema_service.DeleteDocumentSchemaRequest() @@ -5396,8 +5418,9 @@ def test_list_document_schemas_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5462,18 +5485,21 @@ def test_list_document_schemas_rest_interceptors(null_interceptor): ) client = DocumentSchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "post_list_document_schemas" - ) as post, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, - "post_list_document_schemas_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentSchemaServiceRestInterceptor, "pre_list_document_schemas" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_list_document_schemas", + ) as post, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, + "post_list_document_schemas_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentSchemaServiceRestInterceptor, "pre_list_document_schemas" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5533,8 +5559,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5757,11 +5784,14 @@ def test_document_schema_service_base_transport(): def test_document_schema_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contentwarehouse_v1.services.document_schema_service.transports.DocumentSchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contentwarehouse_v1.services.document_schema_service.transports.DocumentSchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentSchemaServiceTransport( @@ -5778,9 +5808,12 @@ def test_document_schema_service_base_transport_with_credentials_file(): def test_document_schema_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contentwarehouse_v1.services.document_schema_service.transports.DocumentSchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contentwarehouse_v1.services.document_schema_service.transports.DocumentSchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentSchemaServiceTransport() @@ -5854,11 +5887,12 @@ def test_document_schema_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6466,6 +6500,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentSchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentSchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = DocumentSchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_service.py index e5c79617c6e6..aebf0168aa1b 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_document_service.py @@ -145,6 +145,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -166,6 +167,10 @@ def test__get_default_mtls_endpoint(): assert ( DocumentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_document_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6364,8 +6371,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6425,17 +6433,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_create_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6493,8 +6504,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6592,17 +6604,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6655,8 +6669,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6716,17 +6731,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_update_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6784,8 +6802,9 @@ def test_delete_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6842,13 +6861,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = document_service_request.DeleteDocumentRequest.pb( document_service_request.DeleteDocumentRequest() @@ -6893,8 +6912,9 @@ def test_search_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6961,17 +6981,20 @@ def test_search_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_search_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_search_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_search_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_search_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_search_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_search_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7029,8 +7052,9 @@ def test_lock_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7128,17 +7152,20 @@ def test_lock_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_lock_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_lock_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_lock_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_lock_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_lock_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_lock_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7191,8 +7218,9 @@ def test_fetch_acl_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7252,17 +7280,19 @@ def test_fetch_acl_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_fetch_acl" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_fetch_acl_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_fetch_acl" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_fetch_acl" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_fetch_acl_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_fetch_acl" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7315,8 +7345,9 @@ def test_set_acl_rest_bad_request(request_type=document_service_request.SetAclRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7376,17 +7407,19 @@ def test_set_acl_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_set_acl" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_set_acl_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_set_acl" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_set_acl" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_set_acl_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_set_acl" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7443,8 +7476,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7720,11 +7754,14 @@ def test_document_service_base_transport(): def test_document_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contentwarehouse_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contentwarehouse_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport( @@ -7741,9 +7778,12 @@ def test_document_service_base_transport_with_credentials_file(): def test_document_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contentwarehouse_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contentwarehouse_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport() @@ -7815,11 +7855,12 @@ def test_document_service_transport_auth_gdch_credentials(transport_class): def test_document_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8460,6 +8501,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py index ef56b171ddab..2869b9e6fbe8 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_pipeline_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PipelineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): assert ( PipelineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PipelineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1310,11 +1315,13 @@ def test_pipeline_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2024,8 +2031,9 @@ def test_run_pipeline_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2082,19 +2090,20 @@ def test_run_pipeline_rest_interceptors(null_interceptor): ) client = PipelineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PipelineServiceRestInterceptor, "post_run_pipeline" - ) as post, mock.patch.object( - transports.PipelineServiceRestInterceptor, "post_run_pipeline_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PipelineServiceRestInterceptor, "pre_run_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PipelineServiceRestInterceptor, "post_run_pipeline" + ) as post, + mock.patch.object( + transports.PipelineServiceRestInterceptor, "post_run_pipeline_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PipelineServiceRestInterceptor, "pre_run_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2149,8 +2158,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2301,11 +2311,14 @@ def test_pipeline_service_base_transport(): def test_pipeline_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contentwarehouse_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contentwarehouse_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PipelineServiceTransport( @@ -2322,9 +2335,12 @@ def test_pipeline_service_base_transport_with_credentials_file(): def test_pipeline_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contentwarehouse_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contentwarehouse_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PipelineServiceTransport() @@ -2396,11 +2412,12 @@ def test_pipeline_service_transport_auth_gdch_credentials(transport_class): def test_pipeline_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3026,6 +3043,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PipelineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_rule_set_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_rule_set_service.py index b64401d96572..59ea963b0b6b 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_rule_set_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_rule_set_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RuleSetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( RuleSetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RuleSetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1287,11 +1292,13 @@ def test_rule_set_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4509,8 +4516,9 @@ def test_create_rule_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4709,17 +4717,20 @@ def test_create_rule_set_rest_interceptors(null_interceptor): ) client = RuleSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_create_rule_set" - ) as post, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_create_rule_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "pre_create_rule_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "post_create_rule_set" + ) as post, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, + "post_create_rule_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "pre_create_rule_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4772,8 +4783,9 @@ def test_get_rule_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4840,17 +4852,19 @@ def test_get_rule_set_rest_interceptors(null_interceptor): ) client = RuleSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_get_rule_set" - ) as post, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_get_rule_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "pre_get_rule_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "post_get_rule_set" + ) as post, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "post_get_rule_set_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "pre_get_rule_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4903,8 +4917,9 @@ def test_update_rule_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4971,17 +4986,20 @@ def test_update_rule_set_rest_interceptors(null_interceptor): ) client = RuleSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_update_rule_set" - ) as post, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_update_rule_set_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "pre_update_rule_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "post_update_rule_set" + ) as post, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, + "post_update_rule_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "pre_update_rule_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5034,8 +5052,9 @@ def test_delete_rule_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5092,13 +5111,13 @@ def test_delete_rule_set_rest_interceptors(null_interceptor): ) client = RuleSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "pre_delete_rule_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "pre_delete_rule_set" + ) as pre, + ): pre.assert_not_called() pb_message = ruleset_service_request.DeleteRuleSetRequest.pb( ruleset_service_request.DeleteRuleSetRequest() @@ -5143,8 +5162,9 @@ def test_list_rule_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5207,17 +5227,20 @@ def test_list_rule_sets_rest_interceptors(null_interceptor): ) client = RuleSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_list_rule_sets" - ) as post, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "post_list_rule_sets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RuleSetServiceRestInterceptor, "pre_list_rule_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "post_list_rule_sets" + ) as post, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, + "post_list_rule_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RuleSetServiceRestInterceptor, "pre_list_rule_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5277,8 +5300,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5491,11 +5515,14 @@ def test_rule_set_service_base_transport(): def test_rule_set_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contentwarehouse_v1.services.rule_set_service.transports.RuleSetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contentwarehouse_v1.services.rule_set_service.transports.RuleSetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RuleSetServiceTransport( @@ -5512,9 +5539,12 @@ def test_rule_set_service_base_transport_with_credentials_file(): def test_rule_set_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contentwarehouse_v1.services.rule_set_service.transports.RuleSetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contentwarehouse_v1.services.rule_set_service.transports.RuleSetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RuleSetServiceTransport() @@ -5586,11 +5616,12 @@ def test_rule_set_service_transport_auth_gdch_credentials(transport_class): def test_rule_set_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6220,6 +6251,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RuleSetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RuleSetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = RuleSetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_synonym_set_service.py b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_synonym_set_service.py index 28e0a60f7185..d1437a760fbe 100644 --- a/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_synonym_set_service.py +++ b/packages/google-cloud-contentwarehouse/tests/unit/gapic/contentwarehouse_v1/test_synonym_set_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SynonymSetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): SynonymSetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SynonymSetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1322,11 +1327,13 @@ def test_synonym_set_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4665,8 +4672,9 @@ def test_create_synonym_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4805,18 +4813,20 @@ def test_create_synonym_set_rest_interceptors(null_interceptor): ) client = SynonymSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "post_create_synonym_set" - ) as post, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, - "post_create_synonym_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "pre_create_synonym_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "post_create_synonym_set" + ) as post, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, + "post_create_synonym_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "pre_create_synonym_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4869,8 +4879,9 @@ def test_get_synonym_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4935,18 +4946,20 @@ def test_get_synonym_set_rest_interceptors(null_interceptor): ) client = SynonymSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "post_get_synonym_set" - ) as post, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, - "post_get_synonym_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "pre_get_synonym_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "post_get_synonym_set" + ) as post, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, + "post_get_synonym_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "pre_get_synonym_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4999,8 +5012,9 @@ def test_update_synonym_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5139,18 +5153,20 @@ def test_update_synonym_set_rest_interceptors(null_interceptor): ) client = SynonymSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "post_update_synonym_set" - ) as post, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, - "post_update_synonym_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "pre_update_synonym_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "post_update_synonym_set" + ) as post, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, + "post_update_synonym_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "pre_update_synonym_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5203,8 +5219,9 @@ def test_delete_synonym_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5261,13 +5278,13 @@ def test_delete_synonym_set_rest_interceptors(null_interceptor): ) client = SynonymSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "pre_delete_synonym_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "pre_delete_synonym_set" + ) as pre, + ): pre.assert_not_called() pb_message = synonymset_service_request.DeleteSynonymSetRequest.pb( synonymset_service_request.DeleteSynonymSetRequest() @@ -5312,8 +5329,9 @@ def test_list_synonym_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5378,18 +5396,20 @@ def test_list_synonym_sets_rest_interceptors(null_interceptor): ) client = SynonymSetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "post_list_synonym_sets" - ) as post, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, - "post_list_synonym_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SynonymSetServiceRestInterceptor, "pre_list_synonym_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "post_list_synonym_sets" + ) as post, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, + "post_list_synonym_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SynonymSetServiceRestInterceptor, "pre_list_synonym_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5449,8 +5469,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5671,11 +5692,14 @@ def test_synonym_set_service_base_transport(): def test_synonym_set_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.contentwarehouse_v1.services.synonym_set_service.transports.SynonymSetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.contentwarehouse_v1.services.synonym_set_service.transports.SynonymSetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SynonymSetServiceTransport( @@ -5692,9 +5716,12 @@ def test_synonym_set_service_base_transport_with_credentials_file(): def test_synonym_set_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.contentwarehouse_v1.services.synonym_set_service.transports.SynonymSetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.contentwarehouse_v1.services.synonym_set_service.transports.SynonymSetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SynonymSetServiceTransport() @@ -5766,11 +5793,12 @@ def test_synonym_set_service_transport_auth_gdch_credentials(transport_class): def test_synonym_set_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6376,6 +6404,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SynonymSetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SynonymSetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = SynonymSetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/async_client.py b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/async_client.py index 92e47c8fa1ae..b37ec7fe6e75 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/async_client.py +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> DataFusionTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/client.py b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/client.py index 8add7c61eded..5e78cb3150fd 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/client.py +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/client.py @@ -118,7 +118,7 @@ class DataFusionClient(metaclass=DataFusionClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = DataFusionClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/README.rst b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/README.rst index 009c54b92d48..04657642e277 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/README.rst +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataFusionTransport` is the ABC for all transports. -- public child `DataFusionGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataFusionGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataFusionRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataFusionRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataFusionTransport`` is the ABC for all transports. + +- public child ``DataFusionGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataFusionGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataFusionRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataFusionRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/base.py b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/base.py index 1fd204cf3e15..18179526fc3c 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/base.py +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py index 3a281ce3e74d..e55112d78fba 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py index 313603d506ab..51da19c9c378 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/rest.py b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/rest.py index a25aa3df9635..ba0f1b17a15b 100644 --- a/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/rest.py +++ b/packages/google-cloud-data-fusion/google/cloud/data_fusion_v1/services/data_fusion/transports/rest.py @@ -541,6 +541,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataFusionRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-data-fusion/noxfile.py b/packages/google-cloud-data-fusion/noxfile.py index 16b47c9a6525..3c8b012a79dd 100644 --- a/packages/google-cloud-data-fusion/noxfile.py +++ b/packages/google-cloud-data-fusion/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-data-fusion/setup.py b/packages/google-cloud-data-fusion/setup.py index ebd3573ab44b..786303ae21f7 100644 --- a/packages/google-cloud-data-fusion/setup.py +++ b/packages/google-cloud-data-fusion/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-data-fusion" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-data-fusion/testing/constraints-3.7.txt b/packages/google-cloud-data-fusion/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-data-fusion/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-data-fusion/testing/constraints-3.8.txt b/packages/google-cloud-data-fusion/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-data-fusion/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-data-fusion/testing/constraints-3.9.txt b/packages/google-cloud-data-fusion/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-data-fusion/testing/constraints-3.9.txt +++ b/packages/google-cloud-data-fusion/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-data-fusion/tests/unit/gapic/data_fusion_v1/test_data_fusion.py b/packages/google-cloud-data-fusion/tests/unit/gapic/data_fusion_v1/test_data_fusion.py index 22b24d264e14..5617e09723e5 100644 --- a/packages/google-cloud-data-fusion/tests/unit/gapic/data_fusion_v1/test_data_fusion.py +++ b/packages/google-cloud-data-fusion/tests/unit/gapic/data_fusion_v1/test_data_fusion.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataFusionClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DataFusionClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DataFusionClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1247,11 +1251,13 @@ def test_data_fusion_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5595,8 +5601,9 @@ def test_list_available_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5659,18 +5666,20 @@ def test_list_available_versions_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataFusionRestInterceptor, "post_list_available_versions" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, - "post_list_available_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_list_available_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_list_available_versions" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, + "post_list_available_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_list_available_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5726,8 +5735,9 @@ def test_list_instances_rest_bad_request(request_type=datafusion.ListInstancesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5792,17 +5802,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataFusionRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5855,8 +5867,9 @@ def test_get_instance_rest_bad_request(request_type=datafusion.GetInstanceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5959,17 +5972,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataFusionRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6020,8 +6035,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6188,19 +6204,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataFusionRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataFusionRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6253,8 +6270,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6311,19 +6329,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataFusionRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataFusionRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6378,8 +6397,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6548,19 +6568,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataFusionRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataFusionRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6613,8 +6634,9 @@ def test_restart_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6671,19 +6693,20 @@ def test_restart_instance_rest_interceptors(null_interceptor): ) client = DataFusionClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataFusionRestInterceptor, "post_restart_instance" - ) as post, mock.patch.object( - transports.DataFusionRestInterceptor, "post_restart_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataFusionRestInterceptor, "pre_restart_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataFusionRestInterceptor, "post_restart_instance" + ) as post, + mock.patch.object( + transports.DataFusionRestInterceptor, "post_restart_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataFusionRestInterceptor, "pre_restart_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6955,11 +6978,14 @@ def test_data_fusion_base_transport(): def test_data_fusion_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.data_fusion_v1.services.data_fusion.transports.DataFusionTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.data_fusion_v1.services.data_fusion.transports.DataFusionTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataFusionTransport( @@ -6976,9 +7002,12 @@ def test_data_fusion_base_transport_with_credentials_file(): def test_data_fusion_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.data_fusion_v1.services.data_fusion.transports.DataFusionTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.data_fusion_v1.services.data_fusion.transports.DataFusionTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataFusionTransport() @@ -7050,11 +7079,12 @@ def test_data_fusion_transport_auth_gdch_credentials(transport_class): def test_data_fusion_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py index 42059b7e257c..6bd4090deff1 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py @@ -257,7 +257,7 @@ def transport(self) -> AutoSuggestionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py index 8e4c822fa793..6ab4cf602ee3 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py @@ -179,7 +179,7 @@ class AutoSuggestionServiceClient(metaclass=AutoSuggestionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -187,7 +187,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -197,6 +197,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -482,7 +486,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -581,7 +585,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -684,7 +688,7 @@ def __init__( self._universe_domain = AutoSuggestionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/README.rst b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/README.rst index 27835fb8dc8e..7680a14ac82a 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/README.rst +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutoSuggestionServiceTransport` is the ABC for all transports. -- public child `AutoSuggestionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutoSuggestionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutoSuggestionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutoSuggestionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutoSuggestionServiceTransport`` is the ABC for all transports. + +- public child ``AutoSuggestionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutoSuggestionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutoSuggestionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutoSuggestionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py index 005668481edb..6e85587fc0d1 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc.py index 1cc0449e7792..8b558abc0eb8 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -254,6 +254,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py index 2ae7173d3cb9..8e403d8d3560 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -305,6 +305,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/rest.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/rest.py index 66e85fa23767..57b1ea8159fa 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/rest.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/rest.py @@ -279,6 +279,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutoSuggestionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/async_client.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/async_client.py index 665b6016a2ae..3bb14c7d4bc5 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/async_client.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> QuestionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/client.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/client.py index b3ad137f2fda..4c607d14e651 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/client.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/client.py @@ -131,7 +131,7 @@ class QuestionServiceClient(metaclass=QuestionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -478,7 +482,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -575,7 +579,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -676,7 +680,7 @@ def __init__( self._universe_domain = QuestionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/README.rst b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/README.rst index a8090f2ef993..285049be8020 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/README.rst +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`QuestionServiceTransport` is the ABC for all transports. -- public child `QuestionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `QuestionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseQuestionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `QuestionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``QuestionServiceTransport`` is the ABC for all transports. + +- public child ``QuestionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``QuestionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseQuestionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``QuestionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py index 6e2bb8e8783d..735e7b3fa9dd 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc.py index 8c40bee0dfb2..895ab51630d6 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -202,6 +202,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py index b342353bd45c..3a92c4f703cc 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -253,6 +253,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/rest.py b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/rest.py index 6e15c7087d31..b36b34ac5167 100644 --- a/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/rest.py +++ b/packages/google-cloud-data-qna/google/cloud/dataqna_v1alpha/services/question_service/transports/rest.py @@ -444,6 +444,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[QuestionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-data-qna/noxfile.py b/packages/google-cloud-data-qna/noxfile.py index 93617c461076..c8b498a837e3 100644 --- a/packages/google-cloud-data-qna/noxfile.py +++ b/packages/google-cloud-data-qna/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-data-qna/setup.py b/packages/google-cloud-data-qna/setup.py index 40b6f593b6ee..0329c5b2deaa 100644 --- a/packages/google-cloud-data-qna/setup.py +++ b/packages/google-cloud-data-qna/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-data-qna" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-data-qna/testing/constraints-3.7.txt b/packages/google-cloud-data-qna/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-data-qna/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-data-qna/testing/constraints-3.8.txt b/packages/google-cloud-data-qna/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-data-qna/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-data-qna/testing/constraints-3.9.txt b/packages/google-cloud-data-qna/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-data-qna/testing/constraints-3.9.txt +++ b/packages/google-cloud-data-qna/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py b/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py index 5662670bdc23..f4d3b24e3447 100644 --- a/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py +++ b/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutoSuggestionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): AutoSuggestionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AutoSuggestionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1341,11 +1346,13 @@ def test_auto_suggestion_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1912,8 +1919,9 @@ def test_suggest_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1973,18 +1981,20 @@ def test_suggest_queries_rest_interceptors(null_interceptor): ) client = AutoSuggestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoSuggestionServiceRestInterceptor, "post_suggest_queries" - ) as post, mock.patch.object( - transports.AutoSuggestionServiceRestInterceptor, - "post_suggest_queries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutoSuggestionServiceRestInterceptor, "pre_suggest_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoSuggestionServiceRestInterceptor, "post_suggest_queries" + ) as post, + mock.patch.object( + transports.AutoSuggestionServiceRestInterceptor, + "post_suggest_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoSuggestionServiceRestInterceptor, "pre_suggest_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2109,11 +2119,14 @@ def test_auto_suggestion_service_base_transport(): def test_auto_suggestion_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataqna_v1alpha.services.auto_suggestion_service.transports.AutoSuggestionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataqna_v1alpha.services.auto_suggestion_service.transports.AutoSuggestionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoSuggestionServiceTransport( @@ -2130,9 +2143,12 @@ def test_auto_suggestion_service_base_transport_with_credentials_file(): def test_auto_suggestion_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataqna_v1alpha.services.auto_suggestion_service.transports.AutoSuggestionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataqna_v1alpha.services.auto_suggestion_service.transports.AutoSuggestionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoSuggestionServiceTransport() @@ -2206,11 +2222,12 @@ def test_auto_suggestion_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_question_service.py b/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_question_service.py index 9e567a45518d..e5bf1ea47323 100644 --- a/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_question_service.py +++ b/packages/google-cloud-data-qna/tests/unit/gapic/dataqna_v1alpha/test_question_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert QuestionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): assert ( QuestionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + QuestionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1314,11 +1319,13 @@ def test_question_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4414,8 +4421,9 @@ def test_get_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4486,17 +4494,19 @@ def test_get_question_rest_interceptors(null_interceptor): ) client = QuestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_get_question" - ) as post, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_get_question_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.QuestionServiceRestInterceptor, "pre_get_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "post_get_question" + ) as post, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "post_get_question_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "pre_get_question" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4549,8 +4559,9 @@ def test_create_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4772,17 +4783,20 @@ def test_create_question_rest_interceptors(null_interceptor): ) client = QuestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_create_question" - ) as post, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_create_question_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.QuestionServiceRestInterceptor, "pre_create_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "post_create_question" + ) as post, + mock.patch.object( + transports.QuestionServiceRestInterceptor, + "post_create_question_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "pre_create_question" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4835,8 +4849,9 @@ def test_execute_question_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4907,17 +4922,20 @@ def test_execute_question_rest_interceptors(null_interceptor): ) client = QuestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_execute_question" - ) as post, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_execute_question_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.QuestionServiceRestInterceptor, "pre_execute_question" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "post_execute_question" + ) as post, + mock.patch.object( + transports.QuestionServiceRestInterceptor, + "post_execute_question_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "pre_execute_question" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4972,8 +4990,9 @@ def test_get_user_feedback_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5042,18 +5061,20 @@ def test_get_user_feedback_rest_interceptors(null_interceptor): ) client = QuestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_get_user_feedback" - ) as post, mock.patch.object( - transports.QuestionServiceRestInterceptor, - "post_get_user_feedback_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.QuestionServiceRestInterceptor, "pre_get_user_feedback" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "post_get_user_feedback" + ) as post, + mock.patch.object( + transports.QuestionServiceRestInterceptor, + "post_get_user_feedback_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "pre_get_user_feedback" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5110,8 +5131,9 @@ def test_update_user_feedback_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5254,18 +5276,20 @@ def test_update_user_feedback_rest_interceptors(null_interceptor): ) client = QuestionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.QuestionServiceRestInterceptor, "post_update_user_feedback" - ) as post, mock.patch.object( - transports.QuestionServiceRestInterceptor, - "post_update_user_feedback_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.QuestionServiceRestInterceptor, "pre_update_user_feedback" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "post_update_user_feedback" + ) as post, + mock.patch.object( + transports.QuestionServiceRestInterceptor, + "post_update_user_feedback_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.QuestionServiceRestInterceptor, "pre_update_user_feedback" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5477,11 +5501,14 @@ def test_question_service_base_transport(): def test_question_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataqna_v1alpha.services.question_service.transports.QuestionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataqna_v1alpha.services.question_service.transports.QuestionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.QuestionServiceTransport( @@ -5498,9 +5525,12 @@ def test_question_service_base_transport_with_credentials_file(): def test_question_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataqna_v1alpha.services.question_service.transports.QuestionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataqna_v1alpha.services.question_service.transports.QuestionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.QuestionServiceTransport() @@ -5572,11 +5602,12 @@ def test_question_service_transport_auth_gdch_credentials(transport_class): def test_question_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/async_client.py b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/async_client.py index 3422c999bb6e..d2a1d3ed2cb0 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/async_client.py +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> DatabaseCenterTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/client.py b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/client.py index c75abee343b1..428ceca78876 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/client.py +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/client.py @@ -111,7 +111,7 @@ class DatabaseCenterClient(metaclass=DatabaseCenterClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -414,7 +418,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -511,7 +515,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +611,7 @@ def __init__( self._universe_domain = DatabaseCenterClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/README.rst b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/README.rst index 126c80456a41..01ca1986b9d5 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/README.rst +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DatabaseCenterTransport` is the ABC for all transports. -- public child `DatabaseCenterGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DatabaseCenterGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDatabaseCenterRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DatabaseCenterRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DatabaseCenterTransport`` is the ABC for all transports. + +- public child ``DatabaseCenterGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DatabaseCenterGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDatabaseCenterRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DatabaseCenterRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/base.py b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/base.py index 9db010c1a324..c7eb9a239d33 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/base.py +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc.py b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc.py index f1ff89583629..425f5b7abe80 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc.py +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc_asyncio.py b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc_asyncio.py index 279c319655f3..7ed25adbbc88 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc_asyncio.py +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/rest.py b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/rest.py index bd143bdeb961..93796818b42b 100644 --- a/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/rest.py +++ b/packages/google-cloud-databasecenter/google/cloud/databasecenter_v1beta/services/database_center/transports/rest.py @@ -426,6 +426,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DatabaseCenterRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-databasecenter/noxfile.py b/packages/google-cloud-databasecenter/noxfile.py index def5207f9e47..6c5929eecc08 100644 --- a/packages/google-cloud-databasecenter/noxfile.py +++ b/packages/google-cloud-databasecenter/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-databasecenter/setup.py b/packages/google-cloud-databasecenter/setup.py index 5d7d917c6627..8c9e493f4f97 100644 --- a/packages/google-cloud-databasecenter/setup.py +++ b/packages/google-cloud-databasecenter/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-databasecenter" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-databasecenter/testing/constraints-3.7.txt b/packages/google-cloud-databasecenter/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-databasecenter/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-databasecenter/testing/constraints-3.8.txt b/packages/google-cloud-databasecenter/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-databasecenter/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-databasecenter/testing/constraints-3.9.txt b/packages/google-cloud-databasecenter/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-databasecenter/testing/constraints-3.9.txt +++ b/packages/google-cloud-databasecenter/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-databasecenter/tests/unit/gapic/databasecenter_v1beta/test_database_center.py b/packages/google-cloud-databasecenter/tests/unit/gapic/databasecenter_v1beta/test_database_center.py index 6188a26dc3c8..fee6a8f4aba6 100644 --- a/packages/google-cloud-databasecenter/tests/unit/gapic/databasecenter_v1beta/test_database_center.py +++ b/packages/google-cloud-databasecenter/tests/unit/gapic/databasecenter_v1beta/test_database_center.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DatabaseCenterClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( DatabaseCenterClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DatabaseCenterClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1281,11 +1286,13 @@ def test_database_center_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4509,8 +4516,9 @@ def test_query_products_rest_bad_request(request_type=service.QueryProductsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4575,17 +4583,20 @@ def test_query_products_rest_interceptors(null_interceptor): ) client = DatabaseCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_query_products" - ) as post, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_query_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "pre_query_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "post_query_products" + ) as post, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, + "post_query_products_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "pre_query_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4636,8 +4647,9 @@ def test_aggregate_fleet_rest_bad_request(request_type=service.AggregateFleetReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4706,17 +4718,20 @@ def test_aggregate_fleet_rest_interceptors(null_interceptor): ) client = DatabaseCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_aggregate_fleet" - ) as post, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_aggregate_fleet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "pre_aggregate_fleet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "post_aggregate_fleet" + ) as post, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, + "post_aggregate_fleet_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "pre_aggregate_fleet" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4769,8 +4784,9 @@ def test_query_database_resource_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4835,18 +4851,22 @@ def test_query_database_resource_groups_rest_interceptors(null_interceptor): ) client = DatabaseCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_query_database_resource_groups" - ) as post, mock.patch.object( - transports.DatabaseCenterRestInterceptor, - "post_query_database_resource_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "pre_query_database_resource_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, + "post_query_database_resource_groups", + ) as post, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, + "post_query_database_resource_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, + "pre_query_database_resource_groups", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4904,8 +4924,9 @@ def test_aggregate_issue_stats_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4972,18 +4993,20 @@ def test_aggregate_issue_stats_rest_interceptors(null_interceptor): ) client = DatabaseCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_aggregate_issue_stats" - ) as post, mock.patch.object( - transports.DatabaseCenterRestInterceptor, - "post_aggregate_issue_stats_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "pre_aggregate_issue_stats" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "post_aggregate_issue_stats" + ) as post, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, + "post_aggregate_issue_stats_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "pre_aggregate_issue_stats" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5039,8 +5062,9 @@ def test_query_issues_rest_bad_request(request_type=service.QueryIssuesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5105,17 +5129,19 @@ def test_query_issues_rest_interceptors(null_interceptor): ) client = DatabaseCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_query_issues" - ) as post, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "post_query_issues_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatabaseCenterRestInterceptor, "pre_query_issues" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "post_query_issues" + ) as post, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "post_query_issues_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatabaseCenterRestInterceptor, "pre_query_issues" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5325,11 +5351,14 @@ def test_database_center_base_transport(): def test_database_center_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.databasecenter_v1beta.services.database_center.transports.DatabaseCenterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.databasecenter_v1beta.services.database_center.transports.DatabaseCenterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatabaseCenterTransport( @@ -5346,9 +5375,12 @@ def test_database_center_base_transport_with_credentials_file(): def test_database_center_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.databasecenter_v1beta.services.database_center.transports.DatabaseCenterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.databasecenter_v1beta.services.database_center.transports.DatabaseCenterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatabaseCenterTransport() @@ -5420,11 +5452,12 @@ def test_database_center_transport_auth_gdch_credentials(transport_class): def test_database_center_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/async_client.py b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/async_client.py index 1ae0a7f007ee..c5879f287f5b 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/async_client.py +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> LineageTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2367,7 +2367,7 @@ async def sample_batch_search_link_processes(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2393,8 +2393,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2403,7 +2407,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2411,7 +2415,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2422,7 +2426,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2448,8 +2452,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2458,7 +2466,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2466,7 +2474,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2477,7 +2485,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2507,8 +2515,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2517,7 +2529,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2525,7 +2537,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2533,7 +2545,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2562,8 +2574,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2572,7 +2588,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2580,7 +2596,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/client.py b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/client.py index 501eafd2add4..c0a168340b71 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/client.py +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/client.py @@ -122,7 +122,7 @@ class LineageClient(metaclass=LineageClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -497,7 +501,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -594,7 +598,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -690,7 +694,7 @@ def __init__( self._universe_domain = LineageClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2818,7 +2822,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2844,8 +2848,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2854,7 +2862,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2863,7 +2871,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2877,7 +2885,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2903,8 +2911,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2913,7 +2925,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2922,7 +2934,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2936,7 +2948,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2966,8 +2978,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2976,7 +2992,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2984,7 +3000,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2992,7 +3008,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3021,8 +3037,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3031,7 +3051,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3039,7 +3059,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/README.rst b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/README.rst index 91ab0cc123ef..0c716b5f7f42 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/README.rst +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LineageTransport` is the ABC for all transports. -- public child `LineageGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LineageGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLineageRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LineageRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LineageTransport`` is the ABC for all transports. + +- public child ``LineageGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LineageGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLineageRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LineageRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/base.py b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/base.py index a04716fdf230..7b79ca946ce8 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/base.py +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc.py b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc.py index 7600bd83a57b..e64835376797 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc.py +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc_asyncio.py index fd1890014625..3f5ac970b08e 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/rest.py b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/rest.py index 6e6127f4810e..7263c9637005 100644 --- a/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/rest.py +++ b/packages/google-cloud-datacatalog-lineage/google/cloud/datacatalog_lineage_v1/services/lineage/transports/rest.py @@ -1128,6 +1128,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LineageRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-datacatalog-lineage/noxfile.py b/packages/google-cloud-datacatalog-lineage/noxfile.py index 8fcf2f3583e7..9efcd0b59a66 100644 --- a/packages/google-cloud-datacatalog-lineage/noxfile.py +++ b/packages/google-cloud-datacatalog-lineage/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-datacatalog-lineage/setup.py b/packages/google-cloud-datacatalog-lineage/setup.py index 71a7cf9c3f1b..c32a94431bd7 100644 --- a/packages/google-cloud-datacatalog-lineage/setup.py +++ b/packages/google-cloud-datacatalog-lineage/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-datacatalog-lineage" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-datacatalog-lineage/testing/constraints-3.7.txt b/packages/google-cloud-datacatalog-lineage/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-datacatalog-lineage/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-datacatalog-lineage/testing/constraints-3.8.txt b/packages/google-cloud-datacatalog-lineage/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-datacatalog-lineage/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-datacatalog-lineage/testing/constraints-3.9.txt b/packages/google-cloud-datacatalog-lineage/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-datacatalog-lineage/testing/constraints-3.9.txt +++ b/packages/google-cloud-datacatalog-lineage/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-datacatalog-lineage/tests/unit/gapic/datacatalog_lineage_v1/test_lineage.py b/packages/google-cloud-datacatalog-lineage/tests/unit/gapic/datacatalog_lineage_v1/test_lineage.py index 67b3d95537fb..50365b1d8f32 100644 --- a/packages/google-cloud-datacatalog-lineage/tests/unit/gapic/datacatalog_lineage_v1/test_lineage.py +++ b/packages/google-cloud-datacatalog-lineage/tests/unit/gapic/datacatalog_lineage_v1/test_lineage.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LineageClient._get_default_mtls_endpoint(None) is None assert LineageClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -143,6 +144,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert LineageClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert LineageClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1222,11 +1224,13 @@ def test_lineage_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12157,8 +12161,9 @@ def test_process_open_lineage_run_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12291,18 +12296,20 @@ def test_process_open_lineage_run_event_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_process_open_lineage_run_event" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, - "post_process_open_lineage_run_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_process_open_lineage_run_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_process_open_lineage_run_event" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, + "post_process_open_lineage_run_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_process_open_lineage_run_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12358,8 +12365,9 @@ def test_create_process_rest_bad_request(request_type=lineage.CreateProcessReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12495,17 +12503,19 @@ def test_create_process_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_create_process" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_create_process_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_create_process" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_create_process" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_create_process_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_create_process" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12556,8 +12566,9 @@ def test_update_process_rest_bad_request(request_type=lineage.UpdateProcessReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12695,17 +12706,19 @@ def test_update_process_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_update_process" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_update_process_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_update_process" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_update_process" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_update_process_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_update_process" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12754,8 +12767,9 @@ def test_get_process_rest_bad_request(request_type=lineage.GetProcessRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12818,17 +12832,17 @@ def test_get_process_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_get_process" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_get_process_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_get_process" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_get_process" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_get_process_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_get_process") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12877,8 +12891,9 @@ def test_list_processes_rest_bad_request(request_type=lineage.ListProcessesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12939,17 +12954,19 @@ def test_list_processes_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_list_processes" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_list_processes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_list_processes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_list_processes" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_list_processes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_list_processes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13000,8 +13017,9 @@ def test_delete_process_rest_bad_request(request_type=lineage.DeleteProcessReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13056,19 +13074,20 @@ def test_delete_process_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LineageRestInterceptor, "post_delete_process" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_delete_process_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_delete_process" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LineageRestInterceptor, "post_delete_process" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_delete_process_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_delete_process" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13117,8 +13136,9 @@ def test_create_run_rest_bad_request(request_type=lineage.CreateRunRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13258,17 +13278,15 @@ def test_create_run_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_create_run" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_create_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_create_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LineageRestInterceptor, "post_create_run") as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_create_run_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_create_run") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13321,8 +13339,9 @@ def test_update_run_rest_bad_request(request_type=lineage.UpdateRunRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13466,17 +13485,15 @@ def test_update_run_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_update_run" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_update_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_update_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LineageRestInterceptor, "post_update_run") as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_update_run_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_update_run") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13527,8 +13544,9 @@ def test_get_run_rest_bad_request(request_type=lineage.GetRunRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13595,17 +13613,15 @@ def test_get_run_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_get_run" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_get_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_get_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LineageRestInterceptor, "post_get_run") as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_get_run_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_get_run") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13654,8 +13670,9 @@ def test_list_runs_rest_bad_request(request_type=lineage.ListRunsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13716,17 +13733,15 @@ def test_list_runs_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_list_runs" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_list_runs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_list_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.LineageRestInterceptor, "post_list_runs") as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_list_runs_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_list_runs") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13777,8 +13792,9 @@ def test_delete_run_rest_bad_request(request_type=lineage.DeleteRunRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13835,19 +13851,16 @@ def test_delete_run_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LineageRestInterceptor, "post_delete_run" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_delete_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_delete_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.LineageRestInterceptor, "post_delete_run") as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_delete_run_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_delete_run") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13900,8 +13913,9 @@ def test_create_lineage_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14042,17 +14056,19 @@ def test_create_lineage_event_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_create_lineage_event" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_create_lineage_event_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_create_lineage_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_create_lineage_event" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_create_lineage_event_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_create_lineage_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14107,8 +14123,9 @@ def test_get_lineage_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14171,17 +14188,19 @@ def test_get_lineage_event_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_get_lineage_event" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_get_lineage_event_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_get_lineage_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_get_lineage_event" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_get_lineage_event_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_get_lineage_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14234,8 +14253,9 @@ def test_list_lineage_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14298,17 +14318,19 @@ def test_list_lineage_events_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_list_lineage_events" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_list_lineage_events_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_list_lineage_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_list_lineage_events" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_list_lineage_events_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_list_lineage_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14365,8 +14387,9 @@ def test_delete_lineage_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14423,13 +14446,13 @@ def test_delete_lineage_event_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "pre_delete_lineage_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "pre_delete_lineage_event" + ) as pre, + ): pre.assert_not_called() pb_message = lineage.DeleteLineageEventRequest.pb( lineage.DeleteLineageEventRequest() @@ -14472,8 +14495,9 @@ def test_search_links_rest_bad_request(request_type=lineage.SearchLinksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14534,17 +14558,17 @@ def test_search_links_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_search_links" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, "post_search_links_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_search_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_search_links" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, "post_search_links_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LineageRestInterceptor, "pre_search_links") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14597,8 +14621,9 @@ def test_batch_search_link_processes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14659,18 +14684,20 @@ def test_batch_search_link_processes_rest_interceptors(null_interceptor): ) client = LineageClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LineageRestInterceptor, "post_batch_search_link_processes" - ) as post, mock.patch.object( - transports.LineageRestInterceptor, - "post_batch_search_link_processes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LineageRestInterceptor, "pre_batch_search_link_processes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LineageRestInterceptor, "post_batch_search_link_processes" + ) as post, + mock.patch.object( + transports.LineageRestInterceptor, + "post_batch_search_link_processes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LineageRestInterceptor, "pre_batch_search_link_processes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14730,8 +14757,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14792,8 +14820,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14854,8 +14883,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14916,8 +14946,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15419,11 +15450,14 @@ def test_lineage_base_transport(): def test_lineage_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_lineage_v1.services.lineage.transports.LineageTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_lineage_v1.services.lineage.transports.LineageTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LineageTransport( @@ -15440,9 +15474,12 @@ def test_lineage_base_transport_with_credentials_file(): def test_lineage_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_lineage_v1.services.lineage.transports.LineageTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_lineage_v1.services.lineage.transports.LineageTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LineageTransport() @@ -15514,11 +15551,12 @@ def test_lineage_transport_auth_gdch_credentials(transport_class): def test_lineage_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16217,6 +16255,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = LineageClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = LineageAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = LineageClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16356,6 +16426,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = LineageClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LineageAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = LineageClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16501,6 +16603,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = LineageClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LineageAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = LineageClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16646,6 +16782,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = LineageClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LineageAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = LineageClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/async_client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/async_client.py index 881e6516df72..9d07364a4f38 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/async_client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/async_client.py @@ -225,7 +225,7 @@ def transport(self) -> DataCatalogTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5190,7 +5190,7 @@ async def sample_retrieve_effective_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5216,8 +5216,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5226,7 +5230,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5234,7 +5238,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5245,7 +5249,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5271,8 +5275,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5281,7 +5289,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5289,7 +5297,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5300,7 +5308,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5330,8 +5338,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5340,7 +5352,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5348,7 +5360,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5356,7 +5368,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5385,8 +5397,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5395,7 +5411,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5403,7 +5419,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/client.py index 095a1bb96a2d..747b89fdfcbf 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/client.py @@ -134,7 +134,7 @@ class DataCatalogClient(metaclass=DataCatalogClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -142,7 +142,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -152,6 +152,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -583,7 +587,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -680,7 +684,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -776,7 +780,7 @@ def __init__( self._universe_domain = DataCatalogClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5635,7 +5639,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5661,8 +5665,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5671,7 +5679,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5680,7 +5688,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5694,7 +5702,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5720,8 +5728,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5730,7 +5742,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5739,7 +5751,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5753,7 +5765,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5783,8 +5795,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5793,7 +5809,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5801,7 +5817,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5809,7 +5825,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5838,8 +5854,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5848,7 +5868,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5856,7 +5876,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/README.rst b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/README.rst index e7afdebe4753..788f1933ecda 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/README.rst +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataCatalogTransport` is the ABC for all transports. -- public child `DataCatalogGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataCatalogGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataCatalogRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataCatalogRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataCatalogTransport`` is the ABC for all transports. + +- public child ``DataCatalogGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataCatalogGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataCatalogRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataCatalogRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/base.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/base.py index c89b2e2e8911..cffda4737711 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/base.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc.py index c12a1d3be238..f21f6e6ed34f 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc_asyncio.py index 8ec5238a8ae3..9ced91c27638 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/data_catalog/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/async_client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/async_client.py index 74ebf6617281..7e218ccc7d2a 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/async_client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> PolicyTagManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1839,7 +1839,7 @@ async def sample_test_iam_permissions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1865,8 +1865,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1875,7 +1879,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1883,7 +1887,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1894,7 +1898,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1920,8 +1924,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1930,7 +1938,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1938,7 +1946,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1949,7 +1957,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1979,8 +1987,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1989,7 +2001,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1997,7 +2009,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2005,7 +2017,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2034,8 +2046,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2044,7 +2060,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2052,7 +2068,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py index 0758554089f8..6d8b14584642 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/client.py @@ -121,7 +121,7 @@ class PolicyTagManagerClient(metaclass=PolicyTagManagerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -470,7 +474,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = PolicyTagManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2270,7 +2274,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2296,8 +2300,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2306,7 +2314,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2315,7 +2323,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2329,7 +2337,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2355,8 +2363,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2365,7 +2377,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2374,7 +2386,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2388,7 +2400,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2418,8 +2430,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2428,7 +2444,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2436,7 +2452,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2444,7 +2460,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2473,8 +2489,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2483,7 +2503,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2491,7 +2511,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/README.rst b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/README.rst index a9973d430094..0ce21691276a 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/README.rst +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PolicyTagManagerTransport` is the ABC for all transports. -- public child `PolicyTagManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PolicyTagManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePolicyTagManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PolicyTagManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PolicyTagManagerTransport`` is the ABC for all transports. + +- public child ``PolicyTagManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PolicyTagManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePolicyTagManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PolicyTagManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/base.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/base.py index f1b35581b45c..5c91a99c3602 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/base.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc.py index 602cc85730cf..396a9f6a3a88 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -197,6 +197,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc_asyncio.py index bc6d031113e9..f5e4bc4f4f6a 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -248,6 +248,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/async_client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/async_client.py index 65e9dc957d00..f4e86a1d5225 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/async_client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> PolicyTagManagerSerializationTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -645,7 +645,7 @@ async def sample_export_taxonomies(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -671,8 +671,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -681,7 +685,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -689,7 +693,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -700,7 +704,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -726,8 +730,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -736,7 +744,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -744,7 +752,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -755,7 +763,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -785,8 +793,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -795,7 +807,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -803,7 +815,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -811,7 +823,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -840,8 +852,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -850,7 +866,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -858,7 +874,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py index 9fcee8849987..975fb6e9f781 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/client.py @@ -125,7 +125,7 @@ class PolicyTagManagerSerializationClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -454,7 +458,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -553,7 +557,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -657,7 +661,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1083,7 +1087,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1109,8 +1113,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1119,7 +1127,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1128,7 +1136,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1142,7 +1150,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1168,8 +1176,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1178,7 +1190,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1187,7 +1199,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1201,7 +1213,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1231,8 +1243,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1241,7 +1257,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1249,7 +1265,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1257,7 +1273,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1286,8 +1302,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1296,7 +1316,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1304,7 +1324,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/README.rst b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/README.rst index f68f3c8a5265..9ffc824316fc 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/README.rst +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PolicyTagManagerSerializationTransport` is the ABC for all transports. -- public child `PolicyTagManagerSerializationGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PolicyTagManagerSerializationGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePolicyTagManagerSerializationRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PolicyTagManagerSerializationRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PolicyTagManagerSerializationTransport`` is the ABC for all transports. + +- public child ``PolicyTagManagerSerializationGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PolicyTagManagerSerializationGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePolicyTagManagerSerializationRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PolicyTagManagerSerializationRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/base.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/base.py index ec541df1d5a0..60df90c8fa65 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/base.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc.py index 959b09df4ed8..e835cc04b805 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -198,6 +198,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py index 296ccbe05df3..ab555672928c 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -249,6 +249,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/async_client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/async_client.py index 0c46f093ad7f..5d504ccd4b69 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/async_client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> DataCatalogTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py index 8b403441e329..3b9e9ea1d3b3 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/client.py @@ -130,7 +130,7 @@ class DataCatalogClient(metaclass=DataCatalogClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -579,7 +583,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -676,7 +680,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -772,7 +776,7 @@ def __init__( self._universe_domain = DataCatalogClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/README.rst b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/README.rst index e7afdebe4753..788f1933ecda 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/README.rst +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataCatalogTransport` is the ABC for all transports. -- public child `DataCatalogGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataCatalogGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataCatalogRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataCatalogRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataCatalogTransport`` is the ABC for all transports. + +- public child ``DataCatalogGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataCatalogGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataCatalogRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataCatalogRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/base.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/base.py index cb9b02489621..76f12cc1f74e 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/base.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc.py index c36c6aff036f..614e7f3d5e69 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc_asyncio.py index 1c2802909238..8cc22b1ddfe4 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/data_catalog/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/async_client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/async_client.py index 8f564d9e1862..9f8776cf2e48 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/async_client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> PolicyTagManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py index 37c508d440d2..10d48e721b93 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/client.py @@ -117,7 +117,7 @@ class PolicyTagManagerClient(metaclass=PolicyTagManagerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -466,7 +470,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -563,7 +567,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = PolicyTagManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/README.rst b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/README.rst index a9973d430094..0ce21691276a 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/README.rst +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PolicyTagManagerTransport` is the ABC for all transports. -- public child `PolicyTagManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PolicyTagManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePolicyTagManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PolicyTagManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PolicyTagManagerTransport`` is the ABC for all transports. + +- public child ``PolicyTagManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PolicyTagManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePolicyTagManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PolicyTagManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/base.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/base.py index 2f2230bbecf3..fb642f7dea30 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/base.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc.py index 7ab021ce03a9..3ee47b64beb7 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc_asyncio.py index ad875c05b72b..6c35ec7a1440 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/async_client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/async_client.py index df3bf1c86a2f..cda8f18eea89 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/async_client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> PolicyTagManagerSerializationTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py index c5aefb9f07fa..e799121c3c51 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/client.py @@ -122,7 +122,7 @@ class PolicyTagManagerSerializationClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -550,7 +554,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -654,7 +658,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/README.rst b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/README.rst index f68f3c8a5265..9ffc824316fc 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/README.rst +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PolicyTagManagerSerializationTransport` is the ABC for all transports. -- public child `PolicyTagManagerSerializationGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PolicyTagManagerSerializationGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePolicyTagManagerSerializationRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PolicyTagManagerSerializationRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PolicyTagManagerSerializationTransport`` is the ABC for all transports. + +- public child ``PolicyTagManagerSerializationGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PolicyTagManagerSerializationGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePolicyTagManagerSerializationRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PolicyTagManagerSerializationRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/base.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/base.py index e715a6a4dde9..9786f122f3cd 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/base.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc.py index 90c5ddcaa3a4..003307160de6 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py index 73de14a40b1c..47f4d5cc35a6 100644 --- a/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py +++ b/packages/google-cloud-datacatalog/google/cloud/datacatalog_v1beta1/services/policy_tag_manager_serialization/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datacatalog/noxfile.py b/packages/google-cloud-datacatalog/noxfile.py index 321e99d5fecf..f794cd6cff01 100644 --- a/packages/google-cloud-datacatalog/noxfile.py +++ b/packages/google-cloud-datacatalog/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-datacatalog/setup.py b/packages/google-cloud-datacatalog/setup.py index 0376693d7463..24130873fc0e 100644 --- a/packages/google-cloud-datacatalog/setup.py +++ b/packages/google-cloud-datacatalog/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-datacatalog/testing/constraints-3.7.txt b/packages/google-cloud-datacatalog/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-datacatalog/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-datacatalog/testing/constraints-3.8.txt b/packages/google-cloud-datacatalog/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-datacatalog/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-datacatalog/testing/constraints-3.9.txt b/packages/google-cloud-datacatalog/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-datacatalog/testing/constraints-3.9.txt +++ b/packages/google-cloud-datacatalog/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_data_catalog.py b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_data_catalog.py index fdc3104f3afd..35b65dfcfb33 100644 --- a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_data_catalog.py +++ b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_data_catalog.py @@ -146,6 +146,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataCatalogClient._get_default_mtls_endpoint(None) is None assert ( @@ -164,6 +165,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DataCatalogClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DataCatalogClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1253,11 +1257,13 @@ def test_data_catalog_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -16003,11 +16009,14 @@ def test_data_catalog_base_transport(): def test_data_catalog_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_v1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_v1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataCatalogTransport( @@ -16024,9 +16033,12 @@ def test_data_catalog_base_transport_with_credentials_file(): def test_data_catalog_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_v1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_v1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataCatalogTransport() @@ -16097,11 +16109,12 @@ def test_data_catalog_transport_auth_gdch_credentials(transport_class): def test_data_catalog_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16800,6 +16813,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataCatalogClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataCatalogAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataCatalogClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16939,6 +16984,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataCatalogClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataCatalogAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataCatalogClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17084,6 +17161,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataCatalogClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataCatalogAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataCatalogClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17229,6 +17340,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataCatalogClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataCatalogAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DataCatalogClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py index ff79aa03702a..29cee60a3c30 100644 --- a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py +++ b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PolicyTagManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): PolicyTagManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PolicyTagManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1287,11 +1292,13 @@ def test_policy_tag_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6746,11 +6753,14 @@ def test_policy_tag_manager_base_transport(): def test_policy_tag_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_v1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_v1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerTransport( @@ -6767,9 +6777,12 @@ def test_policy_tag_manager_base_transport_with_credentials_file(): def test_policy_tag_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_v1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_v1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerTransport() @@ -6840,11 +6853,12 @@ def test_policy_tag_manager_transport_auth_gdch_credentials(transport_class): def test_policy_tag_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7395,6 +7409,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = PolicyTagManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = PolicyTagManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = PolicyTagManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7534,6 +7580,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PolicyTagManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PolicyTagManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PolicyTagManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7679,6 +7757,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PolicyTagManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PolicyTagManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PolicyTagManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7824,6 +7936,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PolicyTagManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PolicyTagManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = PolicyTagManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py index 37f19612c440..f125c6304dba 100644 --- a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py +++ b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1/test_policy_tag_manager_serialization.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PolicyTagManagerSerializationClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): PolicyTagManagerSerializationClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PolicyTagManagerSerializationClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1364,11 +1369,13 @@ def test_policy_tag_manager_serialization_client_create_channel_credentials_file ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2486,11 +2493,14 @@ def test_policy_tag_manager_serialization_base_transport(): def test_policy_tag_manager_serialization_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_v1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_v1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerSerializationTransport( @@ -2507,9 +2517,12 @@ def test_policy_tag_manager_serialization_base_transport_with_credentials_file() def test_policy_tag_manager_serialization_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_v1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_v1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerSerializationTransport() @@ -2587,11 +2600,12 @@ def test_policy_tag_manager_serialization_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3119,6 +3133,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = PolicyTagManagerSerializationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = PolicyTagManagerSerializationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = PolicyTagManagerSerializationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3258,6 +3304,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PolicyTagManagerSerializationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PolicyTagManagerSerializationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PolicyTagManagerSerializationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3403,6 +3481,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PolicyTagManagerSerializationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PolicyTagManagerSerializationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PolicyTagManagerSerializationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3548,6 +3660,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PolicyTagManagerSerializationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PolicyTagManagerSerializationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = PolicyTagManagerSerializationClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py index aa8451b783a1..d7f0ad9bfecc 100644 --- a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py +++ b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_data_catalog.py @@ -138,6 +138,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataCatalogClient._get_default_mtls_endpoint(None) is None assert ( @@ -156,6 +157,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DataCatalogClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DataCatalogClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1245,11 +1249,13 @@ def test_data_catalog_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -13068,11 +13074,14 @@ def test_data_catalog_base_transport(): def test_data_catalog_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_v1beta1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_v1beta1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataCatalogTransport( @@ -13089,9 +13098,12 @@ def test_data_catalog_base_transport_with_credentials_file(): def test_data_catalog_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_v1beta1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_v1beta1.services.data_catalog.transports.DataCatalogTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataCatalogTransport() @@ -13162,11 +13174,12 @@ def test_data_catalog_transport_auth_gdch_credentials(transport_class): def test_data_catalog_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py index 746e284643ce..ec4a19f7a43d 100644 --- a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py +++ b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PolicyTagManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): PolicyTagManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PolicyTagManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1287,11 +1292,13 @@ def test_policy_tag_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6742,11 +6749,14 @@ def test_policy_tag_manager_base_transport(): def test_policy_tag_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_v1beta1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_v1beta1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerTransport( @@ -6763,9 +6773,12 @@ def test_policy_tag_manager_base_transport_with_credentials_file(): def test_policy_tag_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_v1beta1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_v1beta1.services.policy_tag_manager.transports.PolicyTagManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerTransport() @@ -6836,11 +6849,12 @@ def test_policy_tag_manager_transport_auth_gdch_credentials(transport_class): def test_policy_tag_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py index 6de0b099daf3..be395f035d0b 100644 --- a/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py +++ b/packages/google-cloud-datacatalog/tests/unit/gapic/datacatalog_v1beta1/test_policy_tag_manager_serialization.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PolicyTagManagerSerializationClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): PolicyTagManagerSerializationClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PolicyTagManagerSerializationClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1363,11 +1368,13 @@ def test_policy_tag_manager_serialization_client_create_channel_credentials_file ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2158,11 +2165,14 @@ def test_policy_tag_manager_serialization_base_transport(): def test_policy_tag_manager_serialization_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datacatalog_v1beta1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datacatalog_v1beta1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerSerializationTransport( @@ -2179,9 +2189,12 @@ def test_policy_tag_manager_serialization_base_transport_with_credentials_file() def test_policy_tag_manager_serialization_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datacatalog_v1beta1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datacatalog_v1beta1.services.policy_tag_manager_serialization.transports.PolicyTagManagerSerializationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyTagManagerSerializationTransport() @@ -2259,11 +2272,12 @@ def test_policy_tag_manager_serialization_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py index 21c083e974b2..44d241a05d69 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> FlexTemplatesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py index aad5ad945f49..a56172efa3bd 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py @@ -108,7 +108,7 @@ class FlexTemplatesServiceClient(metaclass=FlexTemplatesServiceClientMeta): """Provides a service for Flex templates.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = FlexTemplatesServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/README.rst b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/README.rst index d93e612e8ab6..bb4ddedee9c7 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/README.rst +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FlexTemplatesServiceTransport` is the ABC for all transports. -- public child `FlexTemplatesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FlexTemplatesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFlexTemplatesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FlexTemplatesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FlexTemplatesServiceTransport`` is the ABC for all transports. + +- public child ``FlexTemplatesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FlexTemplatesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFlexTemplatesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FlexTemplatesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py index 05dc6b65a854..18ea57af04bc 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py index 964262e87d16..317f5c000c8c 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py index 91b3405f61f5..c725d364ff2f 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/rest.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/rest.py index 2d7f5a28f3a6..b00a5578b717 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/rest.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/rest.py @@ -203,6 +203,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FlexTemplatesServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py index b3337d87f608..ef8fc85f37d2 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> JobsV1Beta3Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py index 214322989b64..c32d650fe3de 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py @@ -115,7 +115,7 @@ class JobsV1Beta3Client(metaclass=JobsV1Beta3ClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -418,7 +422,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -515,7 +519,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = JobsV1Beta3Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/README.rst b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/README.rst index 7993c7b26ee2..28c0c6311641 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/README.rst +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`JobsV1Beta3Transport` is the ABC for all transports. -- public child `JobsV1Beta3GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `JobsV1Beta3GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseJobsV1Beta3RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `JobsV1Beta3RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``JobsV1Beta3Transport`` is the ABC for all transports. + +- public child ``JobsV1Beta3GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``JobsV1Beta3GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseJobsV1Beta3RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``JobsV1Beta3RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py index 4449ab7f7843..d7791ca1c53c 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py index fa050c3ef497..3344d058bc7d 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py index 882f96e637ff..fd5776d0ebb6 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/rest.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/rest.py index 3182dc290dbd..997499f8012a 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/rest.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/rest.py @@ -463,6 +463,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[JobsV1Beta3RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py index cfdca28e67be..8d539b0379c4 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> MessagesV1Beta3Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py index 9ac1e76c719c..aca5fdabde10 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py @@ -111,7 +111,7 @@ class MessagesV1Beta3Client(metaclass=MessagesV1Beta3ClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -414,7 +418,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -511,7 +515,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = MessagesV1Beta3Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/README.rst b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/README.rst index 64c407da638a..7754721ef099 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/README.rst +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MessagesV1Beta3Transport` is the ABC for all transports. -- public child `MessagesV1Beta3GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MessagesV1Beta3GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMessagesV1Beta3RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MessagesV1Beta3RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MessagesV1Beta3Transport`` is the ABC for all transports. + +- public child ``MessagesV1Beta3GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MessagesV1Beta3GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMessagesV1Beta3RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MessagesV1Beta3RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py index 80b51f5ad61a..b3bf56b34341 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py index 88e8dc1fdcd6..9f5b29076f00 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py index 4bcd35c209a4..f7a72f18b339 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/rest.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/rest.py index 3c4f5546456b..f035536be9a2 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/rest.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/rest.py @@ -204,6 +204,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MessagesV1Beta3RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py index e27246eb9f20..51f1b2838310 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> MetricsV1Beta3Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py index 543841a1cf18..465c103c134e 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py @@ -113,7 +113,7 @@ class MetricsV1Beta3Client(metaclass=MetricsV1Beta3ClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -416,7 +420,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -513,7 +517,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -609,7 +613,7 @@ def __init__( self._universe_domain = MetricsV1Beta3Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/README.rst b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/README.rst index 3bb0a6941588..251270d6923e 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/README.rst +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetricsV1Beta3Transport` is the ABC for all transports. -- public child `MetricsV1Beta3GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetricsV1Beta3GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetricsV1Beta3RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetricsV1Beta3RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetricsV1Beta3Transport`` is the ABC for all transports. + +- public child ``MetricsV1Beta3GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetricsV1Beta3GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetricsV1Beta3RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetricsV1Beta3RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py index 888af0a02fa9..0945279d3665 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py index 90f8f3c174c6..2e7e1831c7fe 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py index 3b46b73fe2b7..6b1c0534f178 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/rest.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/rest.py index 3bfa5024d694..68e9f7914a1f 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/rest.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/rest.py @@ -310,6 +310,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MetricsV1Beta3RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py index ce9668041e3f..bc14836aa717 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> SnapshotsV1Beta3Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py index fcf145e9b87b..b55613ce60ff 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py @@ -113,7 +113,7 @@ class SnapshotsV1Beta3Client(metaclass=SnapshotsV1Beta3ClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -416,7 +420,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -513,7 +517,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = SnapshotsV1Beta3Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/README.rst b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/README.rst index 4d5eaa1d8a12..a3f77b7de774 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/README.rst +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnapshotsV1Beta3Transport` is the ABC for all transports. -- public child `SnapshotsV1Beta3GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnapshotsV1Beta3GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnapshotsV1Beta3RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnapshotsV1Beta3RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnapshotsV1Beta3Transport`` is the ABC for all transports. + +- public child ``SnapshotsV1Beta3GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnapshotsV1Beta3GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnapshotsV1Beta3RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnapshotsV1Beta3RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py index 40f69af51e3b..fc0b37944e34 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py index 00db0d39d253..1cb1f7f0444d 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py index 73a03df1194e..ea3c904ab9e3 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/rest.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/rest.py index 25d1a8036d97..6990d97af93c 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/rest.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/rest.py @@ -312,6 +312,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SnapshotsV1Beta3RestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py index 6fa111477a2a..3d27dbf4581a 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> TemplatesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py index 3d2bbc592c8e..36177981b8a6 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/client.py @@ -113,7 +113,7 @@ class TemplatesServiceClient(metaclass=TemplatesServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -416,7 +420,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -513,7 +517,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = TemplatesServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/README.rst b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/README.rst index d417b6026a51..5bcaf89f9905 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/README.rst +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TemplatesServiceTransport` is the ABC for all transports. -- public child `TemplatesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TemplatesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTemplatesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TemplatesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TemplatesServiceTransport`` is the ABC for all transports. + +- public child ``TemplatesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TemplatesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTemplatesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TemplatesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py index 1a810c00bac4..198738946d5d 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py index 22e00007b60f..e8f3721ab55d 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py index f20e0578890a..9d5d072a86d2 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/rest.py b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/rest.py index 2ef723df7729..87be3f7fb9af 100644 --- a/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/rest.py +++ b/packages/google-cloud-dataflow-client/google/cloud/dataflow_v1beta3/services/templates_service/transports/rest.py @@ -310,6 +310,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TemplatesServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataflow-client/noxfile.py b/packages/google-cloud-dataflow-client/noxfile.py index af182353c4c7..5f8f599d2b0d 100644 --- a/packages/google-cloud-dataflow-client/noxfile.py +++ b/packages/google-cloud-dataflow-client/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dataflow-client/setup.py b/packages/google-cloud-dataflow-client/setup.py index 54b61c50ad9f..7d1acd8882be 100644 --- a/packages/google-cloud-dataflow-client/setup.py +++ b/packages/google-cloud-dataflow-client/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dataflow-client" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dataflow-client/testing/constraints-3.7.txt b/packages/google-cloud-dataflow-client/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-dataflow-client/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-dataflow-client/testing/constraints-3.8.txt b/packages/google-cloud-dataflow-client/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-dataflow-client/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-dataflow-client/testing/constraints-3.9.txt b/packages/google-cloud-dataflow-client/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-dataflow-client/testing/constraints-3.9.txt +++ b/packages/google-cloud-dataflow-client/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py index 062fdbb5a686..d9eae8551835 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FlexTemplatesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): FlexTemplatesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FlexTemplatesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1339,11 +1344,13 @@ def test_flex_templates_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1849,8 +1856,9 @@ def test_launch_flex_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1910,18 +1918,20 @@ def test_launch_flex_template_rest_interceptors(null_interceptor): ) client = FlexTemplatesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlexTemplatesServiceRestInterceptor, "post_launch_flex_template" - ) as post, mock.patch.object( - transports.FlexTemplatesServiceRestInterceptor, - "post_launch_flex_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FlexTemplatesServiceRestInterceptor, "pre_launch_flex_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FlexTemplatesServiceRestInterceptor, "post_launch_flex_template" + ) as post, + mock.patch.object( + transports.FlexTemplatesServiceRestInterceptor, + "post_launch_flex_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FlexTemplatesServiceRestInterceptor, "pre_launch_flex_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2048,11 +2058,14 @@ def test_flex_templates_service_base_transport(): def test_flex_templates_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataflow_v1beta3.services.flex_templates_service.transports.FlexTemplatesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataflow_v1beta3.services.flex_templates_service.transports.FlexTemplatesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FlexTemplatesServiceTransport( @@ -2072,9 +2085,12 @@ def test_flex_templates_service_base_transport_with_credentials_file(): def test_flex_templates_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataflow_v1beta3.services.flex_templates_service.transports.FlexTemplatesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataflow_v1beta3.services.flex_templates_service.transports.FlexTemplatesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FlexTemplatesServiceTransport() @@ -2152,11 +2168,12 @@ def test_flex_templates_service_transport_auth_gdch_credentials(transport_class) def test_flex_templates_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py index 6abe4d7b3ced..e729d9096035 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert JobsV1Beta3Client._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert JobsV1Beta3Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + JobsV1Beta3Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1248,11 +1252,13 @@ def test_jobs_v1_beta3_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4441,8 +4447,9 @@ def test_create_job_rest_bad_request(request_type=jobs.CreateJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4839,17 +4846,19 @@ def test_create_job_rest_interceptors(null_interceptor): ) client = JobsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_create_job" - ) as post, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_create_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "pre_create_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_create_job" + ) as post, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_create_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "pre_create_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4898,8 +4907,9 @@ def test_get_job_rest_bad_request(request_type=jobs.GetJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4990,17 +5000,17 @@ def test_get_job_rest_interceptors(null_interceptor): ) client = JobsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_get_job" - ) as post, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_get_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "pre_get_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_get_job" + ) as post, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_get_job_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.JobsV1Beta3RestInterceptor, "pre_get_job") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5049,8 +5059,9 @@ def test_update_job_rest_bad_request(request_type=jobs.UpdateJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5447,17 +5458,19 @@ def test_update_job_rest_interceptors(null_interceptor): ) client = JobsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_update_job" - ) as post, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_update_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "pre_update_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_update_job" + ) as post, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_update_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "pre_update_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5506,8 +5519,9 @@ def test_list_jobs_rest_bad_request(request_type=jobs.ListJobsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5570,17 +5584,19 @@ def test_list_jobs_rest_interceptors(null_interceptor): ) client = JobsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_list_jobs" - ) as post, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_list_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "pre_list_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_list_jobs" + ) as post, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_list_jobs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "pre_list_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5629,8 +5645,9 @@ def test_aggregated_list_jobs_rest_bad_request(request_type=jobs.ListJobsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5693,17 +5710,20 @@ def test_aggregated_list_jobs_rest_interceptors(null_interceptor): ) client = JobsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_aggregated_list_jobs" - ) as post, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_aggregated_list_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "pre_aggregated_list_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_aggregated_list_jobs" + ) as post, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, + "post_aggregated_list_jobs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "pre_aggregated_list_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5764,8 +5784,9 @@ def test_snapshot_job_rest_bad_request(request_type=jobs.SnapshotJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5840,17 +5861,19 @@ def test_snapshot_job_rest_interceptors(null_interceptor): ) client = JobsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_snapshot_job" - ) as post, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "post_snapshot_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobsV1Beta3RestInterceptor, "pre_snapshot_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_snapshot_job" + ) as post, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "post_snapshot_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobsV1Beta3RestInterceptor, "pre_snapshot_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6100,11 +6123,14 @@ def test_jobs_v1_beta3_base_transport(): def test_jobs_v1_beta3_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.transports.JobsV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.transports.JobsV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.JobsV1Beta3Transport( @@ -6124,9 +6150,12 @@ def test_jobs_v1_beta3_base_transport_with_credentials_file(): def test_jobs_v1_beta3_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.transports.JobsV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.transports.JobsV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.JobsV1Beta3Transport() @@ -6204,11 +6233,12 @@ def test_jobs_v1_beta3_transport_auth_gdch_credentials(transport_class): def test_jobs_v1_beta3_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py index a54f9497257d..6d7728a7d3b0 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MessagesV1Beta3Client._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( MessagesV1Beta3Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MessagesV1Beta3Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1305,11 +1310,13 @@ def test_messages_v1_beta3_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2098,8 +2105,9 @@ def test_list_job_messages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2162,18 +2170,20 @@ def test_list_job_messages_rest_interceptors(null_interceptor): ) client = MessagesV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MessagesV1Beta3RestInterceptor, "post_list_job_messages" - ) as post, mock.patch.object( - transports.MessagesV1Beta3RestInterceptor, - "post_list_job_messages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MessagesV1Beta3RestInterceptor, "pre_list_job_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MessagesV1Beta3RestInterceptor, "post_list_job_messages" + ) as post, + mock.patch.object( + transports.MessagesV1Beta3RestInterceptor, + "post_list_job_messages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MessagesV1Beta3RestInterceptor, "pre_list_job_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2297,11 +2307,14 @@ def test_messages_v1_beta3_base_transport(): def test_messages_v1_beta3_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataflow_v1beta3.services.messages_v1_beta3.transports.MessagesV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataflow_v1beta3.services.messages_v1_beta3.transports.MessagesV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MessagesV1Beta3Transport( @@ -2321,9 +2334,12 @@ def test_messages_v1_beta3_base_transport_with_credentials_file(): def test_messages_v1_beta3_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataflow_v1beta3.services.messages_v1_beta3.transports.MessagesV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataflow_v1beta3.services.messages_v1_beta3.transports.MessagesV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MessagesV1Beta3Transport() @@ -2401,11 +2417,12 @@ def test_messages_v1_beta3_transport_auth_gdch_credentials(transport_class): def test_messages_v1_beta3_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py index d91c7d97ba10..2ed5719ebe0f 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetricsV1Beta3Client._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( MetricsV1Beta3Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetricsV1Beta3Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_metrics_v1_beta3_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3044,8 +3051,9 @@ def test_get_job_metrics_rest_bad_request(request_type=metrics.GetJobMetricsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3105,17 +3113,20 @@ def test_get_job_metrics_rest_interceptors(null_interceptor): ) client = MetricsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "post_get_job_metrics" - ) as post, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "post_get_job_metrics_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "pre_get_job_metrics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, "post_get_job_metrics" + ) as post, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, + "post_get_job_metrics_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, "pre_get_job_metrics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3166,8 +3177,9 @@ def test_get_job_execution_details_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3230,18 +3242,20 @@ def test_get_job_execution_details_rest_interceptors(null_interceptor): ) client = MetricsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "post_get_job_execution_details" - ) as post, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, - "post_get_job_execution_details_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "pre_get_job_execution_details" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, "post_get_job_execution_details" + ) as post, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, + "post_get_job_execution_details_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, "pre_get_job_execution_details" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3301,8 +3315,9 @@ def test_get_stage_execution_details_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3370,18 +3385,20 @@ def test_get_stage_execution_details_rest_interceptors(null_interceptor): ) client = MetricsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "post_get_stage_execution_details" - ) as post, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, - "post_get_stage_execution_details_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MetricsV1Beta3RestInterceptor, "pre_get_stage_execution_details" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, "post_get_stage_execution_details" + ) as post, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, + "post_get_stage_execution_details_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetricsV1Beta3RestInterceptor, "pre_get_stage_execution_details" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3551,11 +3568,14 @@ def test_metrics_v1_beta3_base_transport(): def test_metrics_v1_beta3_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataflow_v1beta3.services.metrics_v1_beta3.transports.MetricsV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataflow_v1beta3.services.metrics_v1_beta3.transports.MetricsV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsV1Beta3Transport( @@ -3575,9 +3595,12 @@ def test_metrics_v1_beta3_base_transport_with_credentials_file(): def test_metrics_v1_beta3_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataflow_v1beta3.services.metrics_v1_beta3.transports.MetricsV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataflow_v1beta3.services.metrics_v1_beta3.transports.MetricsV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsV1Beta3Transport() @@ -3655,11 +3678,12 @@ def test_metrics_v1_beta3_transport_auth_gdch_credentials(transport_class): def test_metrics_v1_beta3_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py index 47fc295b8243..8a35834189af 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnapshotsV1Beta3Client._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): SnapshotsV1Beta3Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SnapshotsV1Beta3Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1311,11 +1316,13 @@ def test_snapshots_v1_beta3_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2491,8 +2498,9 @@ def test_get_snapshot_rest_bad_request(request_type=snapshots.GetSnapshotRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2571,17 +2579,20 @@ def test_get_snapshot_rest_interceptors(null_interceptor): ) client = SnapshotsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "post_get_snapshot" - ) as post, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "post_get_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "pre_get_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, "post_get_snapshot" + ) as post, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, + "post_get_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, "pre_get_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2634,8 +2645,9 @@ def test_delete_snapshot_rest_bad_request(request_type=snapshots.DeleteSnapshotR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2699,17 +2711,20 @@ def test_delete_snapshot_rest_interceptors(null_interceptor): ) client = SnapshotsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "post_delete_snapshot" - ) as post, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "post_delete_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "pre_delete_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, "post_delete_snapshot" + ) as post, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, + "post_delete_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, "pre_delete_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2762,8 +2777,9 @@ def test_list_snapshots_rest_bad_request(request_type=snapshots.ListSnapshotsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2823,17 +2839,20 @@ def test_list_snapshots_rest_interceptors(null_interceptor): ) client = SnapshotsV1Beta3Client(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "post_list_snapshots" - ) as post, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "post_list_snapshots_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SnapshotsV1Beta3RestInterceptor, "pre_list_snapshots" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, "post_list_snapshots" + ) as post, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, + "post_list_snapshots_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SnapshotsV1Beta3RestInterceptor, "pre_list_snapshots" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2997,11 +3016,14 @@ def test_snapshots_v1_beta3_base_transport(): def test_snapshots_v1_beta3_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataflow_v1beta3.services.snapshots_v1_beta3.transports.SnapshotsV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataflow_v1beta3.services.snapshots_v1_beta3.transports.SnapshotsV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotsV1Beta3Transport( @@ -3021,9 +3043,12 @@ def test_snapshots_v1_beta3_base_transport_with_credentials_file(): def test_snapshots_v1_beta3_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataflow_v1beta3.services.snapshots_v1_beta3.transports.SnapshotsV1Beta3Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataflow_v1beta3.services.snapshots_v1_beta3.transports.SnapshotsV1Beta3Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnapshotsV1Beta3Transport() @@ -3101,11 +3126,12 @@ def test_snapshots_v1_beta3_transport_auth_gdch_credentials(transport_class): def test_snapshots_v1_beta3_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py index f2d8c7870151..649aff91a891 100644 --- a/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py +++ b/packages/google-cloud-dataflow-client/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TemplatesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): TemplatesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TemplatesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1311,11 +1316,13 @@ def test_templates_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2557,8 +2564,9 @@ def test_create_job_from_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2649,18 +2657,20 @@ def test_create_job_from_template_rest_interceptors(null_interceptor): ) client = TemplatesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "post_create_job_from_template" - ) as post, mock.patch.object( - transports.TemplatesServiceRestInterceptor, - "post_create_job_from_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "pre_create_job_from_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, "post_create_job_from_template" + ) as post, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, + "post_create_job_from_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, "pre_create_job_from_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2711,8 +2721,9 @@ def test_launch_template_rest_bad_request(request_type=templates.LaunchTemplateR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2868,17 +2879,20 @@ def test_launch_template_rest_interceptors(null_interceptor): ) client = TemplatesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "post_launch_template" - ) as post, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "post_launch_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "pre_launch_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, "post_launch_template" + ) as post, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, + "post_launch_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, "pre_launch_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2931,8 +2945,9 @@ def test_get_template_rest_bad_request(request_type=templates.GetTemplateRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2995,17 +3010,20 @@ def test_get_template_rest_interceptors(null_interceptor): ) client = TemplatesServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "post_get_template" - ) as post, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "post_get_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TemplatesServiceRestInterceptor, "pre_get_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, "post_get_template" + ) as post, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, + "post_get_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TemplatesServiceRestInterceptor, "pre_get_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3171,11 +3189,14 @@ def test_templates_service_base_transport(): def test_templates_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataflow_v1beta3.services.templates_service.transports.TemplatesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataflow_v1beta3.services.templates_service.transports.TemplatesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TemplatesServiceTransport( @@ -3195,9 +3216,12 @@ def test_templates_service_base_transport_with_credentials_file(): def test_templates_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataflow_v1beta3.services.templates_service.transports.TemplatesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataflow_v1beta3.services.templates_service.transports.TemplatesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TemplatesServiceTransport() @@ -3275,11 +3299,12 @@ def test_templates_service_transport_auth_gdch_credentials(transport_class): def test_templates_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/async_client.py b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/async_client.py index 481f31533f56..ed8b5c6d9601 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/async_client.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/async_client.py @@ -218,7 +218,7 @@ def transport(self) -> DataformTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5954,7 +5954,7 @@ async def sample_update_config(): async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6046,8 +6046,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6056,7 +6060,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6064,7 +6070,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6075,7 +6081,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6168,8 +6174,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6178,7 +6188,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6186,7 +6198,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6197,7 +6209,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6228,8 +6240,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6240,7 +6256,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6248,7 +6266,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6259,7 +6277,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6285,8 +6303,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6295,7 +6317,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6303,7 +6325,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6314,7 +6336,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6340,8 +6362,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6350,7 +6376,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6358,7 +6384,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/client.py b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/client.py index 9a5e9bb987bd..ed73b0c1c29c 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/client.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/client.py @@ -120,7 +120,7 @@ class DataformClient(metaclass=DataformClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -680,7 +684,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -777,7 +781,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -873,7 +877,7 @@ def __init__( self._universe_domain = DataformClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6491,7 +6495,7 @@ def __exit__(self, type, value, traceback): def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6583,8 +6587,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6593,7 +6601,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6602,7 +6612,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6616,7 +6626,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6709,8 +6719,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6719,7 +6733,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6728,7 +6744,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6742,7 +6758,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6773,8 +6789,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6783,7 +6803,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6792,7 +6814,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6806,7 +6828,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6832,8 +6854,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6842,7 +6868,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6851,7 +6877,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6865,7 +6891,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6891,8 +6917,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6901,7 +6931,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6910,7 +6940,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/README.rst b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/README.rst index 86836b25e0fb..a4cf3305c7a6 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/README.rst +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataformTransport` is the ABC for all transports. -- public child `DataformGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataformGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataformRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataformRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataformTransport`` is the ABC for all transports. + +- public child ``DataformGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataformGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataformRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataformRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/base.py b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/base.py index 5cdc9fdfb8cb..422ffe84419b 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/base.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc.py b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc.py index 76f83464d7cc..78f86e1a36db 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc_asyncio.py b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc_asyncio.py index ce738b857c31..5e4c76267485 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/rest.py b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/rest.py index 977d3222d30c..f72c465465a1 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/rest.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1/services/dataform/transports/rest.py @@ -3130,6 +3130,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataformRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/async_client.py b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/async_client.py index b20c950fe3de..6b5152a84e8b 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/async_client.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/async_client.py @@ -228,7 +228,7 @@ def transport(self) -> DataformTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -8011,7 +8011,7 @@ async def sample_test_iam_permissions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8037,8 +8037,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8047,7 +8051,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8055,7 +8059,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8066,7 +8070,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8092,8 +8096,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8102,7 +8110,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8110,7 +8118,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8121,7 +8129,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8151,8 +8159,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8161,7 +8173,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8169,7 +8181,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8177,7 +8189,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8206,8 +8218,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8216,7 +8232,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8224,7 +8240,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8232,7 +8248,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8258,8 +8274,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8268,7 +8288,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8276,7 +8296,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8287,7 +8307,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8313,8 +8333,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8323,7 +8347,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8331,7 +8355,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/client.py b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/client.py index 3159cd594bf4..8940bf17b2a6 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/client.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/client.py @@ -126,7 +126,7 @@ class DataformClient(metaclass=DataformClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -732,7 +736,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -829,7 +833,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -925,7 +929,7 @@ def __init__( self._universe_domain = DataformClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -8550,7 +8554,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8576,8 +8580,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8586,7 +8594,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8595,7 +8603,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8609,7 +8617,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8635,8 +8643,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8645,7 +8657,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8654,7 +8666,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8668,7 +8680,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8698,8 +8710,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8708,7 +8724,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8716,7 +8732,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8724,7 +8740,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8753,8 +8769,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8763,7 +8783,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8771,7 +8791,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8779,7 +8799,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8805,8 +8825,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8815,7 +8839,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8824,7 +8848,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8838,7 +8862,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8864,8 +8888,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8874,7 +8902,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8883,7 +8911,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/README.rst b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/README.rst index 86836b25e0fb..a4cf3305c7a6 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/README.rst +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataformTransport` is the ABC for all transports. -- public child `DataformGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataformGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataformRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataformRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataformTransport`` is the ABC for all transports. + +- public child ``DataformGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataformGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataformRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataformRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/base.py b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/base.py index 9ec9faa5efc5..591851e49c46 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/base.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/base.py @@ -92,6 +92,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -141,6 +145,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc.py b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc.py index 90d69f342d3a..64f0744b56d0 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc_asyncio.py b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc_asyncio.py index 4a47e3f04cda..fee378513bf3 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/rest.py b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/rest.py index 05d9c361f7f8..d34a42488fe4 100644 --- a/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/rest.py +++ b/packages/google-cloud-dataform/google/cloud/dataform_v1beta1/services/dataform/transports/rest.py @@ -4022,6 +4022,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataformRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataform/noxfile.py b/packages/google-cloud-dataform/noxfile.py index 67672a2444b6..99e35e60981f 100644 --- a/packages/google-cloud-dataform/noxfile.py +++ b/packages/google-cloud-dataform/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dataform/setup.py b/packages/google-cloud-dataform/setup.py index d1840076f334..9921901841e7 100644 --- a/packages/google-cloud-dataform/setup.py +++ b/packages/google-cloud-dataform/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dataform/testing/constraints-3.7.txt b/packages/google-cloud-dataform/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-dataform/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataform/testing/constraints-3.8.txt b/packages/google-cloud-dataform/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-dataform/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-dataform/testing/constraints-3.9.txt b/packages/google-cloud-dataform/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-dataform/testing/constraints-3.9.txt +++ b/packages/google-cloud-dataform/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1/test_dataform.py b/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1/test_dataform.py index bedb5070066e..1bed06d8187a 100644 --- a/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1/test_dataform.py +++ b/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1/test_dataform.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataformClient._get_default_mtls_endpoint(None) is None assert DataformClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -146,6 +147,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DataformClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert DataformClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1235,11 +1237,13 @@ def test_dataform_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -32572,8 +32576,9 @@ def test_list_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32636,17 +32641,19 @@ def test_list_repositories_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_repositories" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_repositories_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_repositories" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_repositories_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_repositories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32699,8 +32706,9 @@ def test_get_repository_rest_bad_request(request_type=dataform.GetRepositoryRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32776,17 +32784,19 @@ def test_get_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32837,8 +32847,9 @@ def test_create_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33008,17 +33019,19 @@ def test_create_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33075,8 +33088,9 @@ def test_update_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33250,17 +33264,19 @@ def test_update_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33313,8 +33329,9 @@ def test_delete_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33369,13 +33386,13 @@ def test_delete_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_repository" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteRepositoryRequest.pb( dataform.DeleteRepositoryRequest() @@ -33420,8 +33437,9 @@ def test_commit_repository_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33482,18 +33500,20 @@ def test_commit_repository_changes_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_commit_repository_changes" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_commit_repository_changes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_commit_repository_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_commit_repository_changes" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_commit_repository_changes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_commit_repository_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33551,8 +33571,9 @@ def test_read_repository_file_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33613,17 +33634,20 @@ def test_read_repository_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_read_repository_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_read_repository_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_read_repository_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_read_repository_file" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_read_repository_file_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_read_repository_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33681,8 +33705,9 @@ def test_query_repository_directory_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33745,18 +33770,22 @@ def test_query_repository_directory_contents_rest_interceptors(null_interceptor) ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_repository_directory_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_repository_directory_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_repository_directory_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_repository_directory_contents", + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_repository_directory_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, + "pre_query_repository_directory_contents", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33814,8 +33843,9 @@ def test_fetch_repository_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33876,18 +33906,20 @@ def test_fetch_repository_history_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_repository_history" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_fetch_repository_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_repository_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_repository_history" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_repository_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_repository_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33945,8 +33977,9 @@ def test_compute_repository_access_token_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34012,19 +34045,22 @@ def test_compute_repository_access_token_status_rest_interceptors(null_intercept ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, - "post_compute_repository_access_token_status", - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_compute_repository_access_token_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_compute_repository_access_token_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, + "post_compute_repository_access_token_status", + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_compute_repository_access_token_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, + "pre_compute_repository_access_token_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34082,8 +34118,9 @@ def test_fetch_remote_branches_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34144,17 +34181,20 @@ def test_fetch_remote_branches_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_remote_branches" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_remote_branches_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_remote_branches" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_remote_branches" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_remote_branches_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_remote_branches" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34210,8 +34250,9 @@ def test_list_workspaces_rest_bad_request(request_type=dataform.ListWorkspacesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34274,17 +34315,19 @@ def test_list_workspaces_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workspaces" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workspaces_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_workspaces" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workspaces" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workspaces_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_workspaces" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34337,8 +34380,9 @@ def test_get_workspace_rest_bad_request(request_type=dataform.GetWorkspaceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34403,17 +34447,19 @@ def test_get_workspace_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workspace" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workspace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workspace" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workspace_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_workspace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34464,8 +34510,9 @@ def test_create_workspace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34601,17 +34648,19 @@ def test_create_workspace_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workspace" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workspace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workspace" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workspace_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_workspace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34666,8 +34715,9 @@ def test_delete_workspace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34724,13 +34774,13 @@ def test_delete_workspace_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_workspace" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteWorkspaceRequest.pb( dataform.DeleteWorkspaceRequest() @@ -34777,8 +34827,9 @@ def test_install_npm_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34838,17 +34889,20 @@ def test_install_npm_packages_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_install_npm_packages" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_install_npm_packages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_install_npm_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_install_npm_packages" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_install_npm_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_install_npm_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34906,8 +34960,9 @@ def test_pull_git_commits_rest_bad_request(request_type=dataform.PullGitCommitsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34967,17 +35022,19 @@ def test_pull_git_commits_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_pull_git_commits" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_pull_git_commits_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_pull_git_commits" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_pull_git_commits" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_pull_git_commits_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_pull_git_commits" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35030,8 +35087,9 @@ def test_push_git_commits_rest_bad_request(request_type=dataform.PushGitCommitsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35091,17 +35149,19 @@ def test_push_git_commits_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_push_git_commits" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_push_git_commits_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_push_git_commits" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_push_git_commits" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_push_git_commits_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_push_git_commits" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35156,8 +35216,9 @@ def test_fetch_file_git_statuses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35217,17 +35278,20 @@ def test_fetch_file_git_statuses_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_git_statuses" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_git_statuses_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_file_git_statuses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_file_git_statuses" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_file_git_statuses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_file_git_statuses" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35287,8 +35351,9 @@ def test_fetch_git_ahead_behind_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35353,17 +35418,20 @@ def test_fetch_git_ahead_behind_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_git_ahead_behind" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_git_ahead_behind_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_git_ahead_behind" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_git_ahead_behind" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_git_ahead_behind_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_git_ahead_behind" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35423,8 +35491,9 @@ def test_commit_workspace_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35484,18 +35553,20 @@ def test_commit_workspace_changes_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_commit_workspace_changes" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_commit_workspace_changes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_commit_workspace_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_commit_workspace_changes" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_commit_workspace_changes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_commit_workspace_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35555,8 +35626,9 @@ def test_reset_workspace_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35616,17 +35688,20 @@ def test_reset_workspace_changes_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_reset_workspace_changes" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_reset_workspace_changes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_reset_workspace_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_reset_workspace_changes" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_reset_workspace_changes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_reset_workspace_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35684,8 +35759,9 @@ def test_fetch_file_diff_rest_bad_request(request_type=dataform.FetchFileDiffReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35748,17 +35824,19 @@ def test_fetch_file_diff_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_diff" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_diff_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_file_diff" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_file_diff" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_file_diff_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_file_diff" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35813,8 +35891,9 @@ def test_query_directory_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35877,18 +35956,20 @@ def test_query_directory_contents_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_directory_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_directory_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_directory_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_directory_contents" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_directory_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_directory_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35946,8 +36027,9 @@ def test_search_files_rest_bad_request(request_type=dataform.SearchFilesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36010,17 +36092,19 @@ def test_search_files_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_search_files" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_search_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_search_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_search_files" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_search_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_search_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36073,8 +36157,9 @@ def test_make_directory_rest_bad_request(request_type=dataform.MakeDirectoryRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36134,17 +36219,19 @@ def test_make_directory_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_make_directory" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_make_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_make_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_make_directory" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_make_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_make_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36199,8 +36286,9 @@ def test_remove_directory_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36260,17 +36348,19 @@ def test_remove_directory_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_directory" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_remove_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_directory" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_remove_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36325,8 +36415,9 @@ def test_move_directory_rest_bad_request(request_type=dataform.MoveDirectoryRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36386,17 +36477,19 @@ def test_move_directory_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_move_directory" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_move_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_move_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_directory" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_move_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36449,8 +36542,9 @@ def test_read_file_rest_bad_request(request_type=dataform.ReadFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36513,17 +36607,15 @@ def test_read_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_read_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_read_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_read_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DataformRestInterceptor, "post_read_file") as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_read_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_read_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36574,8 +36666,9 @@ def test_remove_file_rest_bad_request(request_type=dataform.RemoveFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36635,17 +36728,17 @@ def test_remove_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_remove_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_file" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_remove_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36698,8 +36791,9 @@ def test_move_file_rest_bad_request(request_type=dataform.MoveFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36759,17 +36853,15 @@ def test_move_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_move_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_move_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_move_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DataformRestInterceptor, "post_move_file") as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_move_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36820,8 +36912,9 @@ def test_write_file_rest_bad_request(request_type=dataform.WriteFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36881,17 +36974,17 @@ def test_write_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_write_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_write_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_write_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_write_file" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_write_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_write_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36942,8 +37035,9 @@ def test_list_release_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37006,17 +37100,20 @@ def test_list_release_configs_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_release_configs" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_release_configs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_release_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_release_configs" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_release_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_release_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37076,8 +37173,9 @@ def test_get_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37152,17 +37250,19 @@ def test_get_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_release_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_release_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_release_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_release_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_release_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37215,8 +37315,9 @@ def test_create_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37396,17 +37497,20 @@ def test_create_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_release_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_release_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_release_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_release_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_release_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37463,8 +37567,9 @@ def test_update_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37648,17 +37753,20 @@ def test_update_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_release_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_release_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_release_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_update_release_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_release_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37713,8 +37821,9 @@ def test_delete_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37771,13 +37880,13 @@ def test_delete_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_release_config" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteReleaseConfigRequest.pb( dataform.DeleteReleaseConfigRequest() @@ -37822,8 +37931,9 @@ def test_list_compilation_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37886,18 +37996,20 @@ def test_list_compilation_results_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_compilation_results" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_list_compilation_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_compilation_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_compilation_results" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_compilation_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_compilation_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37957,8 +38069,9 @@ def test_get_compilation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38028,17 +38141,20 @@ def test_get_compilation_result_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_compilation_result" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_compilation_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_compilation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_compilation_result" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_get_compilation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_compilation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38091,8 +38207,9 @@ def test_create_compilation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38267,18 +38384,20 @@ def test_create_compilation_result_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_compilation_result" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_create_compilation_result_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_compilation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_compilation_result" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_compilation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_compilation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38333,8 +38452,9 @@ def test_query_compilation_result_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38397,18 +38517,20 @@ def test_query_compilation_result_actions_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_compilation_result_actions" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_compilation_result_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_compilation_result_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_compilation_result_actions" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_compilation_result_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_compilation_result_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38466,8 +38588,9 @@ def test_list_workflow_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38530,17 +38653,20 @@ def test_list_workflow_configs_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workflow_configs" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workflow_configs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_workflow_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workflow_configs" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_workflow_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_workflow_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38600,8 +38726,9 @@ def test_get_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38674,17 +38801,19 @@ def test_get_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workflow_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workflow_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_workflow_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38737,8 +38866,9 @@ def test_create_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38916,17 +39046,20 @@ def test_create_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workflow_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workflow_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workflow_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_workflow_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_workflow_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38983,8 +39116,9 @@ def test_update_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39166,17 +39300,20 @@ def test_update_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_workflow_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_workflow_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_workflow_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_update_workflow_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_workflow_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39231,8 +39368,9 @@ def test_delete_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39289,13 +39427,13 @@ def test_delete_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_workflow_config" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteWorkflowConfigRequest.pb( dataform.DeleteWorkflowConfigRequest() @@ -39340,8 +39478,9 @@ def test_list_workflow_invocations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39404,18 +39543,20 @@ def test_list_workflow_invocations_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workflow_invocations" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_list_workflow_invocations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_workflow_invocations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workflow_invocations" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_workflow_invocations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_workflow_invocations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39475,8 +39616,9 @@ def test_get_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39546,17 +39688,20 @@ def test_get_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_invocation" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_invocation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workflow_invocation" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_get_workflow_invocation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_workflow_invocation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39611,8 +39756,9 @@ def test_create_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39776,18 +39922,20 @@ def test_create_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workflow_invocation" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_create_workflow_invocation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workflow_invocation" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_workflow_invocation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_workflow_invocation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39844,8 +39992,9 @@ def test_delete_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39902,13 +40051,13 @@ def test_delete_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_workflow_invocation" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteWorkflowInvocationRequest.pb( dataform.DeleteWorkflowInvocationRequest() @@ -39955,8 +40104,9 @@ def test_cancel_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40016,18 +40166,20 @@ def test_cancel_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_cancel_workflow_invocation" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_cancel_workflow_invocation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_cancel_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_cancel_workflow_invocation" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_cancel_workflow_invocation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_cancel_workflow_invocation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40087,8 +40239,9 @@ def test_query_workflow_invocation_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40151,18 +40304,20 @@ def test_query_workflow_invocation_actions_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_workflow_invocation_actions" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_workflow_invocation_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_workflow_invocation_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_workflow_invocation_actions" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_workflow_invocation_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_workflow_invocation_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40218,8 +40373,9 @@ def test_get_config_rest_bad_request(request_type=dataform.GetConfigRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40282,17 +40438,17 @@ def test_get_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_config_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_get_config") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40341,8 +40497,9 @@ def test_update_config_rest_bad_request(request_type=dataform.UpdateConfigReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40476,17 +40633,19 @@ def test_update_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40537,8 +40696,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -40597,8 +40757,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -40659,8 +40820,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -40723,8 +40885,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -40787,8 +40950,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -42108,11 +42272,14 @@ def test_dataform_base_transport(): def test_dataform_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataform_v1.services.dataform.transports.DataformTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataform_v1.services.dataform.transports.DataformTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataformTransport( @@ -42132,9 +42299,12 @@ def test_dataform_base_transport_with_credentials_file(): def test_dataform_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataform_v1.services.dataform.transports.DataformTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataform_v1.services.dataform.transports.DataformTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataformTransport() @@ -42212,11 +42382,12 @@ def test_dataform_transport_auth_gdch_credentials(transport_class): def test_dataform_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -43231,6 +43402,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -43372,6 +43577,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -43536,6 +43775,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataformClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -43703,6 +43977,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataformClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -43880,6 +44189,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataformClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1beta1/test_dataform.py b/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1beta1/test_dataform.py index ee66e805419b..68a7ccfe4902 100644 --- a/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1beta1/test_dataform.py +++ b/packages/google-cloud-dataform/tests/unit/gapic/dataform_v1beta1/test_dataform.py @@ -140,6 +140,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataformClient._get_default_mtls_endpoint(None) is None assert DataformClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -156,6 +157,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DataformClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert DataformClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1245,11 +1247,13 @@ def test_dataform_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -43189,8 +43193,9 @@ def test_get_team_folder_rest_bad_request(request_type=dataform.GetTeamFolderReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43257,17 +43262,19 @@ def test_get_team_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_team_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_team_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_team_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_team_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_team_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_team_folder" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43318,8 +43325,9 @@ def test_create_team_folder_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43461,17 +43469,19 @@ def test_create_team_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_team_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_team_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_team_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_team_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_team_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_team_folder" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43528,8 +43538,9 @@ def test_update_team_folder_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43675,17 +43686,19 @@ def test_update_team_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_team_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_team_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_team_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_team_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_team_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_team_folder" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43738,8 +43751,9 @@ def test_delete_team_folder_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43794,13 +43808,13 @@ def test_delete_team_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_team_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_team_folder" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteTeamFolderRequest.pb( dataform.DeleteTeamFolderRequest() @@ -43847,8 +43861,9 @@ def test_query_team_folder_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43911,18 +43926,20 @@ def test_query_team_folder_contents_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_team_folder_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_team_folder_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_team_folder_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_team_folder_contents" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_team_folder_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_team_folder_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43980,8 +43997,9 @@ def test_search_team_folders_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44042,17 +44060,19 @@ def test_search_team_folders_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_search_team_folders" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_search_team_folders_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_search_team_folders" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_search_team_folders" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_search_team_folders_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_search_team_folders" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44105,8 +44125,9 @@ def test_get_folder_rest_bad_request(request_type=dataform.GetFolderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44177,17 +44198,17 @@ def test_get_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_get_folder") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44236,8 +44257,9 @@ def test_create_folder_rest_bad_request(request_type=dataform.CreateFolderReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44385,17 +44407,19 @@ def test_create_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_folder" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44446,8 +44470,9 @@ def test_update_folder_rest_bad_request(request_type=dataform.UpdateFolderReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44597,17 +44622,19 @@ def test_update_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_folder" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44656,8 +44683,9 @@ def test_delete_folder_rest_bad_request(request_type=dataform.DeleteFolderReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44712,13 +44740,13 @@ def test_delete_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_folder" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteFolderRequest.pb(dataform.DeleteFolderRequest()) transcode.return_value = { @@ -44761,8 +44789,9 @@ def test_query_folder_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44823,17 +44852,20 @@ def test_query_folder_contents_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_folder_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_query_folder_contents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_folder_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_folder_contents" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_folder_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_folder_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44891,8 +44923,9 @@ def test_query_user_root_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44953,18 +44986,20 @@ def test_query_user_root_contents_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_user_root_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_user_root_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_user_root_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_user_root_contents" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_user_root_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_user_root_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45020,8 +45055,9 @@ def test_move_folder_rest_bad_request(request_type=dataform.MoveFolderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45076,19 +45112,18 @@ def test_move_folder_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataformRestInterceptor, "post_move_folder" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_move_folder_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_move_folder" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataformRestInterceptor, "post_move_folder" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_folder_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_move_folder") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45139,8 +45174,9 @@ def test_list_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45203,17 +45239,19 @@ def test_list_repositories_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_repositories" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_repositories_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_repositories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_repositories" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_repositories_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_repositories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45266,8 +45304,9 @@ def test_get_repository_rest_bad_request(request_type=dataform.GetRepositoryRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45347,17 +45386,19 @@ def test_get_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45408,8 +45449,9 @@ def test_create_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45585,17 +45627,19 @@ def test_create_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45652,8 +45696,9 @@ def test_update_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45833,17 +45878,19 @@ def test_update_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45896,8 +45943,9 @@ def test_delete_repository_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45952,13 +46000,13 @@ def test_delete_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_repository" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteRepositoryRequest.pb( dataform.DeleteRepositoryRequest() @@ -46001,8 +46049,9 @@ def test_move_repository_rest_bad_request(request_type=dataform.MoveRepositoryRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46057,19 +46106,20 @@ def test_move_repository_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataformRestInterceptor, "post_move_repository" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_move_repository_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_move_repository" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataformRestInterceptor, "post_move_repository" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_repository_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_move_repository" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46120,8 +46170,9 @@ def test_commit_repository_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46182,18 +46233,20 @@ def test_commit_repository_changes_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_commit_repository_changes" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_commit_repository_changes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_commit_repository_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_commit_repository_changes" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_commit_repository_changes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_commit_repository_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46251,8 +46304,9 @@ def test_read_repository_file_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46313,17 +46367,20 @@ def test_read_repository_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_read_repository_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_read_repository_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_read_repository_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_read_repository_file" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_read_repository_file_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_read_repository_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46381,8 +46438,9 @@ def test_query_repository_directory_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46445,18 +46503,22 @@ def test_query_repository_directory_contents_rest_interceptors(null_interceptor) ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_repository_directory_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_repository_directory_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_repository_directory_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_repository_directory_contents", + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_repository_directory_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, + "pre_query_repository_directory_contents", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46514,8 +46576,9 @@ def test_fetch_repository_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46576,18 +46639,20 @@ def test_fetch_repository_history_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_repository_history" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_fetch_repository_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_repository_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_repository_history" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_repository_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_repository_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46645,8 +46710,9 @@ def test_compute_repository_access_token_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46712,19 +46778,22 @@ def test_compute_repository_access_token_status_rest_interceptors(null_intercept ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, - "post_compute_repository_access_token_status", - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_compute_repository_access_token_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_compute_repository_access_token_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, + "post_compute_repository_access_token_status", + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_compute_repository_access_token_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, + "pre_compute_repository_access_token_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46782,8 +46851,9 @@ def test_fetch_remote_branches_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46844,17 +46914,20 @@ def test_fetch_remote_branches_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_remote_branches" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_remote_branches_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_remote_branches" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_remote_branches" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_remote_branches_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_remote_branches" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46910,8 +46983,9 @@ def test_list_workspaces_rest_bad_request(request_type=dataform.ListWorkspacesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46974,17 +47048,19 @@ def test_list_workspaces_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workspaces" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workspaces_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_workspaces" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workspaces" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workspaces_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_workspaces" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47037,8 +47113,9 @@ def test_get_workspace_rest_bad_request(request_type=dataform.GetWorkspaceReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47105,17 +47182,19 @@ def test_get_workspace_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workspace" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workspace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workspace" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workspace_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_workspace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47166,8 +47245,9 @@ def test_create_workspace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47307,17 +47387,19 @@ def test_create_workspace_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workspace" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workspace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workspace" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workspace_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_workspace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47372,8 +47454,9 @@ def test_delete_workspace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47430,13 +47513,13 @@ def test_delete_workspace_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_workspace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_workspace" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteWorkspaceRequest.pb( dataform.DeleteWorkspaceRequest() @@ -47483,8 +47566,9 @@ def test_install_npm_packages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47544,17 +47628,20 @@ def test_install_npm_packages_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_install_npm_packages" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_install_npm_packages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_install_npm_packages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_install_npm_packages" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_install_npm_packages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_install_npm_packages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47612,8 +47699,9 @@ def test_pull_git_commits_rest_bad_request(request_type=dataform.PullGitCommitsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47673,17 +47761,19 @@ def test_pull_git_commits_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_pull_git_commits" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_pull_git_commits_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_pull_git_commits" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_pull_git_commits" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_pull_git_commits_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_pull_git_commits" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47736,8 +47826,9 @@ def test_push_git_commits_rest_bad_request(request_type=dataform.PushGitCommitsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47797,17 +47888,19 @@ def test_push_git_commits_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_push_git_commits" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_push_git_commits_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_push_git_commits" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_push_git_commits" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_push_git_commits_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_push_git_commits" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47862,8 +47955,9 @@ def test_fetch_file_git_statuses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47923,17 +48017,20 @@ def test_fetch_file_git_statuses_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_git_statuses" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_git_statuses_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_file_git_statuses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_file_git_statuses" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_file_git_statuses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_file_git_statuses" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47993,8 +48090,9 @@ def test_fetch_git_ahead_behind_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48059,17 +48157,20 @@ def test_fetch_git_ahead_behind_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_git_ahead_behind" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_git_ahead_behind_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_git_ahead_behind" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_git_ahead_behind" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_fetch_git_ahead_behind_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_git_ahead_behind" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48129,8 +48230,9 @@ def test_commit_workspace_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48190,18 +48292,20 @@ def test_commit_workspace_changes_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_commit_workspace_changes" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_commit_workspace_changes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_commit_workspace_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_commit_workspace_changes" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_commit_workspace_changes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_commit_workspace_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48261,8 +48365,9 @@ def test_reset_workspace_changes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48322,17 +48427,20 @@ def test_reset_workspace_changes_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_reset_workspace_changes" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_reset_workspace_changes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_reset_workspace_changes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_reset_workspace_changes" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_reset_workspace_changes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_reset_workspace_changes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48390,8 +48498,9 @@ def test_fetch_file_diff_rest_bad_request(request_type=dataform.FetchFileDiffReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48454,17 +48563,19 @@ def test_fetch_file_diff_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_diff" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_fetch_file_diff_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_fetch_file_diff" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_file_diff" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_fetch_file_diff_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_fetch_file_diff" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48519,8 +48630,9 @@ def test_query_directory_contents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48583,18 +48695,20 @@ def test_query_directory_contents_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_directory_contents" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_directory_contents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_directory_contents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_directory_contents" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_directory_contents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_directory_contents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48652,8 +48766,9 @@ def test_search_files_rest_bad_request(request_type=dataform.SearchFilesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48716,17 +48831,19 @@ def test_search_files_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_search_files" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_search_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_search_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_search_files" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_search_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_search_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48779,8 +48896,9 @@ def test_make_directory_rest_bad_request(request_type=dataform.MakeDirectoryRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48840,17 +48958,19 @@ def test_make_directory_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_make_directory" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_make_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_make_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_make_directory" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_make_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_make_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48905,8 +49025,9 @@ def test_remove_directory_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48966,17 +49087,19 @@ def test_remove_directory_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_directory" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_remove_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_directory" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_remove_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49031,8 +49154,9 @@ def test_move_directory_rest_bad_request(request_type=dataform.MoveDirectoryRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49092,17 +49216,19 @@ def test_move_directory_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_move_directory" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_move_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_move_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_directory" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_move_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49155,8 +49281,9 @@ def test_read_file_rest_bad_request(request_type=dataform.ReadFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49219,17 +49346,15 @@ def test_read_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_read_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_read_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_read_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DataformRestInterceptor, "post_read_file") as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_read_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_read_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49280,8 +49405,9 @@ def test_remove_file_rest_bad_request(request_type=dataform.RemoveFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49341,17 +49467,17 @@ def test_remove_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_remove_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_remove_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_file" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_remove_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_remove_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49404,8 +49530,9 @@ def test_move_file_rest_bad_request(request_type=dataform.MoveFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49465,17 +49592,15 @@ def test_move_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_move_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_move_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_move_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DataformRestInterceptor, "post_move_file") as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_move_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_move_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49526,8 +49651,9 @@ def test_write_file_rest_bad_request(request_type=dataform.WriteFileRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49587,17 +49713,17 @@ def test_write_file_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_write_file" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_write_file_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_write_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_write_file" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_write_file_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_write_file") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49648,8 +49774,9 @@ def test_list_release_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49712,17 +49839,20 @@ def test_list_release_configs_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_release_configs" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_release_configs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_release_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_release_configs" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_release_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_release_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49782,8 +49912,9 @@ def test_get_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49858,17 +49989,19 @@ def test_get_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_release_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_release_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_release_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_release_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_release_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49921,8 +50054,9 @@ def test_create_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50102,17 +50236,20 @@ def test_create_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_release_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_release_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_release_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_release_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_release_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50169,8 +50306,9 @@ def test_update_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50354,17 +50492,20 @@ def test_update_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_release_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_release_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_release_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_update_release_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_release_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50419,8 +50560,9 @@ def test_delete_release_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50477,13 +50619,13 @@ def test_delete_release_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_release_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_release_config" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteReleaseConfigRequest.pb( dataform.DeleteReleaseConfigRequest() @@ -50528,8 +50670,9 @@ def test_list_compilation_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50592,18 +50735,20 @@ def test_list_compilation_results_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_compilation_results" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_list_compilation_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_compilation_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_compilation_results" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_compilation_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_compilation_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50663,8 +50808,9 @@ def test_get_compilation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50734,17 +50880,20 @@ def test_get_compilation_result_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_compilation_result" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_compilation_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_compilation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_compilation_result" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_get_compilation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_compilation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50797,8 +50946,9 @@ def test_create_compilation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50974,18 +51124,20 @@ def test_create_compilation_result_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_compilation_result" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_create_compilation_result_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_compilation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_compilation_result" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_compilation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_compilation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51040,8 +51192,9 @@ def test_query_compilation_result_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51104,18 +51257,20 @@ def test_query_compilation_result_actions_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_compilation_result_actions" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_compilation_result_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_compilation_result_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_compilation_result_actions" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_compilation_result_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_compilation_result_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51173,8 +51328,9 @@ def test_list_workflow_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51237,17 +51393,20 @@ def test_list_workflow_configs_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workflow_configs" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workflow_configs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_workflow_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workflow_configs" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_workflow_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_workflow_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51307,8 +51466,9 @@ def test_get_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51381,17 +51541,19 @@ def test_get_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workflow_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workflow_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_workflow_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51444,8 +51606,9 @@ def test_create_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51624,17 +51787,20 @@ def test_create_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workflow_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workflow_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workflow_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_workflow_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_workflow_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51691,8 +51857,9 @@ def test_update_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51875,17 +52042,20 @@ def test_update_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_workflow_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_workflow_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_workflow_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_update_workflow_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_workflow_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51940,8 +52110,9 @@ def test_delete_workflow_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51998,13 +52169,13 @@ def test_delete_workflow_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_workflow_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_workflow_config" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteWorkflowConfigRequest.pb( dataform.DeleteWorkflowConfigRequest() @@ -52049,8 +52220,9 @@ def test_list_workflow_invocations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52113,18 +52285,20 @@ def test_list_workflow_invocations_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_list_workflow_invocations" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_list_workflow_invocations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_list_workflow_invocations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_list_workflow_invocations" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_list_workflow_invocations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_list_workflow_invocations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52184,8 +52358,9 @@ def test_get_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52255,17 +52430,20 @@ def test_get_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_invocation" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_workflow_invocation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_workflow_invocation" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_get_workflow_invocation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_workflow_invocation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52320,8 +52498,9 @@ def test_create_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52487,18 +52666,20 @@ def test_create_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_create_workflow_invocation" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_create_workflow_invocation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_create_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_create_workflow_invocation" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_create_workflow_invocation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_create_workflow_invocation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52555,8 +52736,9 @@ def test_delete_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52613,13 +52795,13 @@ def test_delete_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "pre_delete_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "pre_delete_workflow_invocation" + ) as pre, + ): pre.assert_not_called() pb_message = dataform.DeleteWorkflowInvocationRequest.pb( dataform.DeleteWorkflowInvocationRequest() @@ -52666,8 +52848,9 @@ def test_cancel_workflow_invocation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52727,18 +52910,20 @@ def test_cancel_workflow_invocation_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_cancel_workflow_invocation" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_cancel_workflow_invocation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_cancel_workflow_invocation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_cancel_workflow_invocation" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_cancel_workflow_invocation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_cancel_workflow_invocation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52798,8 +52983,9 @@ def test_query_workflow_invocation_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52862,18 +53048,20 @@ def test_query_workflow_invocation_actions_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_query_workflow_invocation_actions" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, - "post_query_workflow_invocation_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_query_workflow_invocation_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_query_workflow_invocation_actions" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_query_workflow_invocation_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_query_workflow_invocation_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52929,8 +53117,9 @@ def test_get_config_rest_bad_request(request_type=dataform.GetConfigRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52995,17 +53184,17 @@ def test_get_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_config_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataformRestInterceptor, "pre_get_config") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53054,8 +53243,9 @@ def test_update_config_rest_bad_request(request_type=dataform.UpdateConfigReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53192,17 +53382,19 @@ def test_update_config_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_update_config" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_update_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_update_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_config" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_update_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_update_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53255,8 +53447,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53318,17 +53511,19 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_get_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53381,8 +53576,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53444,17 +53640,19 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, "post_set_iam_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53507,8 +53705,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -53568,17 +53767,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = DataformClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataformRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.DataformRestInterceptor, "post_test_iam_permissions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataformRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataformRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.DataformRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataformRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -53634,8 +53836,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -53694,8 +53897,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -53756,8 +53960,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -53818,8 +54023,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -53880,8 +54086,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -53942,8 +54149,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -55657,11 +55865,14 @@ def test_dataform_base_transport(): def test_dataform_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataform_v1beta1.services.dataform.transports.DataformTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataform_v1beta1.services.dataform.transports.DataformTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataformTransport( @@ -55681,9 +55892,12 @@ def test_dataform_base_transport_with_credentials_file(): def test_dataform_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataform_v1beta1.services.dataform.transports.DataformTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataform_v1beta1.services.dataform.transports.DataformTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataformTransport() @@ -55761,11 +55975,12 @@ def test_dataform_transport_auth_gdch_credentials(transport_class): def test_dataform_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -56913,6 +57128,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -57052,6 +57299,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -57197,6 +57476,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -57342,6 +57655,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -57487,6 +57834,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), @@ -57628,6 +58009,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataformClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataformAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataformClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py index b7cf96316290..777c02ddc1fa 100644 --- a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py +++ b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/async_client.py @@ -237,7 +237,7 @@ def transport(self) -> DataLabelingServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py index 770fef7ee18b..d7b4db47ddab 100644 --- a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py +++ b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/client.py @@ -129,7 +129,7 @@ class DataLabelingServiceClient(metaclass=DataLabelingServiceClientMeta): """Service for the AI Platform Data Labeling API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -137,7 +137,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -147,6 +147,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -597,7 +601,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -694,7 +698,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -794,7 +798,7 @@ def __init__( self._universe_domain = DataLabelingServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/README.rst b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/README.rst index c56dab0b25aa..0c19a4934a6a 100644 --- a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/README.rst +++ b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataLabelingServiceTransport` is the ABC for all transports. -- public child `DataLabelingServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataLabelingServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataLabelingServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataLabelingServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataLabelingServiceTransport`` is the ABC for all transports. + +- public child ``DataLabelingServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataLabelingServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataLabelingServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataLabelingServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py index eba768caf61e..5178da23dee6 100644 --- a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py +++ b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/base.py @@ -94,6 +94,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -143,6 +147,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py index 1c0e49f0cfb1..642f3eb85e6c 100644 --- a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py +++ b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc.py @@ -68,7 +68,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -198,6 +198,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py index 74e92932b47a..72a6e0b8495c 100644 --- a/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-datalabeling/google/cloud/datalabeling_v1beta1/services/data_labeling_service/transports/grpc_asyncio.py @@ -74,7 +74,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -109,7 +109,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -249,6 +249,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datalabeling/noxfile.py b/packages/google-cloud-datalabeling/noxfile.py index 9714fa50d6e3..668cc6b359a3 100644 --- a/packages/google-cloud-datalabeling/noxfile.py +++ b/packages/google-cloud-datalabeling/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-datalabeling/setup.py b/packages/google-cloud-datalabeling/setup.py index 2ab32d941f44..a2f94176571b 100644 --- a/packages/google-cloud-datalabeling/setup.py +++ b/packages/google-cloud-datalabeling/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-datalabeling" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-datalabeling/testing/constraints-3.7.txt b/packages/google-cloud-datalabeling/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-datalabeling/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-datalabeling/testing/constraints-3.8.txt b/packages/google-cloud-datalabeling/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-datalabeling/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-datalabeling/testing/constraints-3.9.txt b/packages/google-cloud-datalabeling/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-datalabeling/testing/constraints-3.9.txt +++ b/packages/google-cloud-datalabeling/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-datalabeling/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py b/packages/google-cloud-datalabeling/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py index ba4428a68774..e80763c0cc43 100644 --- a/packages/google-cloud-datalabeling/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py +++ b/packages/google-cloud-datalabeling/tests/unit/gapic/datalabeling_v1beta1/test_data_labeling_service.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataLabelingServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -165,6 +166,10 @@ def test__get_default_mtls_endpoint(): DataLabelingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataLabelingServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1324,11 +1329,13 @@ def test_data_labeling_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -16832,11 +16839,14 @@ def test_data_labeling_service_base_transport(): def test_data_labeling_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datalabeling_v1beta1.services.data_labeling_service.transports.DataLabelingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datalabeling_v1beta1.services.data_labeling_service.transports.DataLabelingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataLabelingServiceTransport( @@ -16853,9 +16863,12 @@ def test_data_labeling_service_base_transport_with_credentials_file(): def test_data_labeling_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datalabeling_v1beta1.services.data_labeling_service.transports.DataLabelingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datalabeling_v1beta1.services.data_labeling_service.transports.DataLabelingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataLabelingServiceTransport() @@ -16926,11 +16939,12 @@ def test_data_labeling_service_transport_auth_gdch_credentials(transport_class): def test_data_labeling_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/async_client.py index 3ab471f83f5e..949902dba981 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/async_client.py @@ -226,7 +226,7 @@ def transport(self) -> BusinessGlossaryServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2238,7 +2238,7 @@ async def sample_list_glossary_terms(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2264,8 +2264,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2274,7 +2278,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2282,7 +2286,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2293,7 +2297,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2319,8 +2323,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2329,7 +2337,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2337,7 +2345,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2348,7 +2356,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2378,8 +2386,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2388,7 +2400,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2396,7 +2408,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2404,7 +2416,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2433,8 +2445,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2443,7 +2459,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2451,7 +2467,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2459,7 +2475,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2485,8 +2501,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2495,7 +2515,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2503,7 +2523,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2514,7 +2534,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2540,8 +2560,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2550,7 +2574,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2558,7 +2582,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/client.py index baf54d3e1378..eefba269edee 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/client.py @@ -128,7 +128,7 @@ class BusinessGlossaryServiceClient(metaclass=BusinessGlossaryServiceClientMeta) """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -501,7 +505,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -600,7 +604,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -702,7 +706,7 @@ def __init__( self._universe_domain = BusinessGlossaryServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2667,7 +2671,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2693,8 +2697,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2703,7 +2711,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2712,7 +2720,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2726,7 +2734,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2752,8 +2760,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2762,7 +2774,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2771,7 +2783,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2785,7 +2797,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2815,8 +2827,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2825,7 +2841,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2833,7 +2849,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2841,7 +2857,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2870,8 +2886,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2880,7 +2900,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2888,7 +2908,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2896,7 +2916,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2922,8 +2942,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2932,7 +2956,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2941,7 +2965,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2955,7 +2979,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2981,8 +3005,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2991,7 +3019,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3000,7 +3028,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/README.rst index 2b7007a38bee..d94998aa621f 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BusinessGlossaryServiceTransport` is the ABC for all transports. -- public child `BusinessGlossaryServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BusinessGlossaryServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBusinessGlossaryServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BusinessGlossaryServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BusinessGlossaryServiceTransport`` is the ABC for all transports. + +- public child ``BusinessGlossaryServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BusinessGlossaryServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBusinessGlossaryServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BusinessGlossaryServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/base.py index 8b8aef7ceeb7..156d99923e33 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc.py index 22579f3da3d3..723f739ebc9b 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -197,6 +197,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc_asyncio.py index 641c11ca8d9c..8a38b3f63626 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -248,6 +248,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/rest.py index 728a97074555..41ba5db8d775 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/business_glossary_service/transports/rest.py @@ -1093,6 +1093,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BusinessGlossaryServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/async_client.py index 6b781ad5a3c9..6de67b355552 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> CatalogServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3994,7 +3994,7 @@ async def sample_get_entry_link(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4020,8 +4020,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4030,7 +4034,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4038,7 +4042,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4049,7 +4053,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4075,8 +4079,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4085,7 +4093,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4093,7 +4101,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4104,7 +4112,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4134,8 +4142,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4144,7 +4156,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4152,7 +4164,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4160,7 +4172,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4189,8 +4201,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4199,7 +4215,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4207,7 +4223,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4215,7 +4231,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4241,8 +4257,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4251,7 +4271,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4259,7 +4279,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4270,7 +4290,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4296,8 +4316,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4306,7 +4330,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4314,7 +4338,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/client.py index c706274a5246..1f571590b86f 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/client.py @@ -127,7 +127,7 @@ class CatalogServiceClient(metaclass=CatalogServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -594,7 +598,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -691,7 +695,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -787,7 +791,7 @@ def __init__( self._universe_domain = CatalogServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4481,7 +4485,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4507,8 +4511,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4517,7 +4525,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4526,7 +4534,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4540,7 +4548,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4566,8 +4574,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4576,7 +4588,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4585,7 +4597,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4599,7 +4611,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4629,8 +4641,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4639,7 +4655,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4647,7 +4663,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4655,7 +4671,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4684,8 +4700,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4694,7 +4714,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4702,7 +4722,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4710,7 +4730,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4736,8 +4756,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4746,7 +4770,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4755,7 +4779,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4769,7 +4793,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4795,8 +4819,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4805,7 +4833,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4814,7 +4842,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/README.rst index c14dcbeef235..c74b646c6e7d 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CatalogServiceTransport` is the ABC for all transports. -- public child `CatalogServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CatalogServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCatalogServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CatalogServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CatalogServiceTransport`` is the ABC for all transports. + +- public child ``CatalogServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CatalogServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCatalogServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CatalogServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/base.py index 069c61a2420d..6b8bc174fd7b 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc.py index 9f5827ed69d6..a461471e8323 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc_asyncio.py index 0fdd54fe1c03..21a5a8d9348f 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/rest.py index 778d5fc50dd2..cccaed28ed81 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/catalog_service/transports/rest.py @@ -1823,6 +1823,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CatalogServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/async_client.py index b5bb3cd4a158..b8ad6897ffda 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> CmekServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -967,7 +967,7 @@ async def sample_get_encryption_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -993,8 +993,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1003,7 +1007,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1011,7 +1015,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1022,7 +1026,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1048,8 +1052,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1058,7 +1066,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1066,7 +1074,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1077,7 +1085,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1107,8 +1115,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1117,7 +1129,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1125,7 +1137,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1133,7 +1145,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1162,8 +1174,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1172,7 +1188,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1180,7 +1196,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1188,7 +1204,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1214,8 +1230,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1224,7 +1244,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1232,7 +1252,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1243,7 +1263,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1269,8 +1289,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1279,7 +1303,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1287,7 +1311,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/client.py index 5d65cb7d283f..3a11536d8985 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/client.py @@ -123,7 +123,7 @@ class CmekServiceClient(metaclass=CmekServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = CmekServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1407,7 +1411,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1433,8 +1437,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1443,7 +1451,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1452,7 +1460,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1466,7 +1474,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1492,8 +1500,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1502,7 +1514,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1511,7 +1523,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1525,7 +1537,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1555,8 +1567,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1565,7 +1581,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1573,7 +1589,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1581,7 +1597,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1610,8 +1626,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1620,7 +1640,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1628,7 +1648,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1636,7 +1656,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1662,8 +1682,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1672,7 +1696,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1681,7 +1705,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1695,7 +1719,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1721,8 +1745,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1731,7 +1759,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1740,7 +1768,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/README.rst index 911db2245cc9..6871f10b4154 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CmekServiceTransport` is the ABC for all transports. -- public child `CmekServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CmekServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCmekServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CmekServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CmekServiceTransport`` is the ABC for all transports. + +- public child ``CmekServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CmekServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCmekServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CmekServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/base.py index 17a34d5ff705..98ee1c80dcc0 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc.py index a5426e971748..a542703fd441 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc_asyncio.py index 447751908f27..2215514c8668 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/rest.py index 487d695b15d1..d557c8f106f1 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/cmek_service/transports/rest.py @@ -580,6 +580,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CmekServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/async_client.py index 54b867651a3c..fef5b7922cf4 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> ContentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1255,7 +1255,7 @@ async def sample_list_content(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1281,8 +1281,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1291,7 +1295,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1299,7 +1303,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1310,7 +1314,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1336,8 +1340,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1346,7 +1354,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1354,7 +1362,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1365,7 +1373,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1395,8 +1403,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1405,7 +1417,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1413,7 +1425,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1421,7 +1433,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1450,8 +1462,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1460,7 +1476,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1468,7 +1484,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1476,7 +1492,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1502,8 +1518,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1512,7 +1532,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1520,7 +1540,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1531,7 +1551,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1557,8 +1577,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1567,7 +1591,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1575,7 +1599,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/client.py index bf5516331df4..93e4251ad183 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/client.py @@ -123,7 +123,7 @@ class ContentServiceClient(metaclass=ContentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = ContentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1704,7 +1708,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1730,8 +1734,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1740,7 +1748,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1749,7 +1757,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1763,7 +1771,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1789,8 +1797,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1799,7 +1811,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1808,7 +1820,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1822,7 +1834,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1852,8 +1864,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1862,7 +1878,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1870,7 +1886,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1878,7 +1894,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1907,8 +1923,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1917,7 +1937,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1925,7 +1945,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1933,7 +1953,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1959,8 +1979,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1969,7 +1993,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1978,7 +2002,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1992,7 +2016,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2018,8 +2042,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2028,7 +2056,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2037,7 +2065,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/README.rst index f737919bf8e5..dc9359b99854 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContentServiceTransport` is the ABC for all transports. -- public child `ContentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContentServiceTransport`` is the ABC for all transports. + +- public child ``ContentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/base.py index 0c2bb003288c..d613fb59f077 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc.py index 5732be0f6088..583f95e9fad9 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc_asyncio.py index e9ab0f2067ba..5ac88813f808 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/rest.py index 644b58bab2a7..c8a2d2a822d5 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/content_service/transports/rest.py @@ -700,6 +700,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/async_client.py index b1be57c4fe74..06633fdab8fc 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> DataScanServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1552,7 +1552,7 @@ async def sample_generate_data_quality_rules(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1578,8 +1578,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1588,7 +1592,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1596,7 +1600,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1607,7 +1611,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1633,8 +1637,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1643,7 +1651,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1651,7 +1659,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1662,7 +1670,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1692,8 +1700,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1702,7 +1714,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1710,7 +1722,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1718,7 +1730,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1747,8 +1759,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1757,7 +1773,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1765,7 +1781,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1773,7 +1789,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1799,8 +1815,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1809,7 +1829,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1817,7 +1837,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1828,7 +1848,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1854,8 +1874,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1864,7 +1888,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1872,7 +1896,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/client.py index 8c7b962bf90f..a834adf87dd8 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/client.py @@ -134,7 +134,7 @@ class DataScanServiceClient(metaclass=DataScanServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -142,7 +142,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -152,6 +152,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -550,7 +554,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -647,7 +651,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -745,7 +749,7 @@ def __init__( self._universe_domain = DataScanServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2051,7 +2055,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2077,8 +2081,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2087,7 +2095,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2096,7 +2104,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2110,7 +2118,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2136,8 +2144,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2146,7 +2158,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2155,7 +2167,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2169,7 +2181,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2199,8 +2211,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2209,7 +2225,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2217,7 +2233,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2225,7 +2241,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2254,8 +2270,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2264,7 +2284,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2272,7 +2292,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2280,7 +2300,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2306,8 +2326,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2316,7 +2340,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2325,7 +2349,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2339,7 +2363,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2365,8 +2389,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2375,7 +2403,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2384,7 +2412,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/README.rst index e27965be0a36..bfaa3738f436 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataScanServiceTransport` is the ABC for all transports. -- public child `DataScanServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataScanServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataScanServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataScanServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataScanServiceTransport`` is the ABC for all transports. + +- public child ``DataScanServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataScanServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataScanServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataScanServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/base.py index cdf8a5a245b8..54d8396a666d 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc.py index c84cfb816974..84a2b6f9252c 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc_asyncio.py index 790d15d0a9dc..eef46c6f9540 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/rest.py index 5fef49be9000..ae72d7d525f2 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_scan_service/transports/rest.py @@ -804,6 +804,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataScanServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/async_client.py index c3336d8da889..4ac240fe9c37 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> DataTaxonomyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2403,7 +2403,7 @@ async def sample_get_data_attribute(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2429,8 +2429,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2439,7 +2443,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2447,7 +2451,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2458,7 +2462,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2484,8 +2488,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2494,7 +2502,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2502,7 +2510,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2513,7 +2521,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2543,8 +2551,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2553,7 +2565,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2561,7 +2573,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2569,7 +2581,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2598,8 +2610,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2608,7 +2624,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2616,7 +2632,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2624,7 +2640,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2650,8 +2666,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2660,7 +2680,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2668,7 +2688,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2679,7 +2699,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2705,8 +2725,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2715,7 +2739,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2723,7 +2747,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/client.py index 031d2c764fd1..6e0360a74368 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/client.py @@ -125,7 +125,7 @@ class DataTaxonomyServiceClient(metaclass=DataTaxonomyServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -496,7 +500,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -593,7 +597,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -693,7 +697,7 @@ def __init__( self._universe_domain = DataTaxonomyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2843,7 +2847,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2869,8 +2873,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2879,7 +2887,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2888,7 +2896,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2902,7 +2910,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2928,8 +2936,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2938,7 +2950,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2947,7 +2959,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2961,7 +2973,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2991,8 +3003,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3001,7 +3017,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3009,7 +3025,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3017,7 +3033,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3046,8 +3062,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3056,7 +3076,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3064,7 +3084,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3072,7 +3092,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3098,8 +3118,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3108,7 +3132,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3117,7 +3141,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3131,7 +3155,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3157,8 +3181,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3167,7 +3195,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3176,7 +3204,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/README.rst index 5c194fc01362..a1bfa8e2b991 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataTaxonomyServiceTransport` is the ABC for all transports. -- public child `DataTaxonomyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataTaxonomyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataTaxonomyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataTaxonomyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataTaxonomyServiceTransport`` is the ABC for all transports. + +- public child ``DataTaxonomyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataTaxonomyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataTaxonomyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataTaxonomyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/base.py index 9044360f2dbc..4f2ac03d5bcc 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc.py index 59ee565fb440..cd99da121df5 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc_asyncio.py index e7bcccf26cb8..12a9a4aa64f4 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/rest.py index 462f0849fe61..e03128a475ac 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/data_taxonomy_service/transports/rest.py @@ -1161,6 +1161,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataTaxonomyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/async_client.py index 30c65f074824..5e427f9469ec 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/async_client.py @@ -217,7 +217,7 @@ def transport(self) -> DataplexServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4603,7 +4603,7 @@ async def sample_list_sessions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4629,8 +4629,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4639,7 +4643,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4647,7 +4651,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4658,7 +4662,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4684,8 +4688,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4694,7 +4702,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4702,7 +4710,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4713,7 +4721,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4743,8 +4751,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4753,7 +4765,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4761,7 +4773,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4769,7 +4781,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4798,8 +4810,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4808,7 +4824,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4816,7 +4832,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4824,7 +4840,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4850,8 +4866,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4860,7 +4880,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4868,7 +4888,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4879,7 +4899,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4905,8 +4925,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4915,7 +4939,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4923,7 +4947,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/client.py index f6678d498fbc..909e4dceff29 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/client.py @@ -127,7 +127,7 @@ class DataplexServiceClient(metaclass=DataplexServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -630,7 +634,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -727,7 +731,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -825,7 +829,7 @@ def __init__( self._universe_domain = DataplexServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5121,7 +5125,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5147,8 +5151,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5157,7 +5165,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5166,7 +5174,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5180,7 +5188,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5206,8 +5214,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5216,7 +5228,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5225,7 +5237,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5239,7 +5251,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5269,8 +5281,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5279,7 +5295,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5287,7 +5303,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5295,7 +5311,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5324,8 +5340,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5334,7 +5354,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5342,7 +5362,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5350,7 +5370,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5376,8 +5396,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5386,7 +5410,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5395,7 +5419,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5409,7 +5433,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5435,8 +5459,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5445,7 +5473,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5454,7 +5482,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/README.rst index a70e22115784..f7d8d9934df1 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataplexServiceTransport` is the ABC for all transports. -- public child `DataplexServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataplexServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataplexServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataplexServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataplexServiceTransport`` is the ABC for all transports. + +- public child ``DataplexServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataplexServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataplexServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataplexServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/base.py index 112dd943bb03..b4eb00af44ae 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc.py index b00aca45496a..293a188d844b 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc_asyncio.py index eb9bc555138c..bcdce8dfc282 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/rest.py index 1c9ba98cca18..d4f808670106 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/dataplex_service/transports/rest.py @@ -2045,6 +2045,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataplexServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/async_client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/async_client.py index 2dd1feb92a78..8c403578ac60 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/async_client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/async_client.py @@ -199,7 +199,7 @@ def transport(self) -> MetadataServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1339,7 +1339,7 @@ async def sample_list_partitions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1365,8 +1365,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1375,7 +1379,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1383,7 +1387,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1394,7 +1398,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1420,8 +1424,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1430,7 +1438,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1438,7 +1446,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1449,7 +1457,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1479,8 +1487,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1489,7 +1501,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1497,7 +1509,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1505,7 +1517,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1534,8 +1546,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1544,7 +1560,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1552,7 +1568,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1560,7 +1576,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1586,8 +1602,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1596,7 +1616,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1604,7 +1624,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1615,7 +1635,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1641,8 +1661,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1651,7 +1675,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1659,7 +1683,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/client.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/client.py index ae2c69b47801..6c6715f9ba9c 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/client.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/client.py @@ -119,7 +119,7 @@ class MetadataServiceClient(metaclass=MetadataServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -502,7 +506,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -599,7 +603,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -697,7 +701,7 @@ def __init__( self._universe_domain = MetadataServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1810,7 +1814,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1836,8 +1840,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1846,7 +1854,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1855,7 +1863,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1869,7 +1877,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1895,8 +1903,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1905,7 +1917,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1914,7 +1926,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1928,7 +1940,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1958,8 +1970,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1968,7 +1984,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1976,7 +1992,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1984,7 +2000,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2013,8 +2029,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2023,7 +2043,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2031,7 +2051,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2039,7 +2059,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2065,8 +2085,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2075,7 +2099,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2084,7 +2108,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2098,7 +2122,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2124,8 +2148,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2134,7 +2162,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2143,7 +2171,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/README.rst b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/README.rst index ff25cadba5cb..5482aff6abd0 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/README.rst +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetadataServiceTransport` is the ABC for all transports. -- public child `MetadataServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetadataServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetadataServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetadataServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetadataServiceTransport`` is the ABC for all transports. + +- public child ``MetadataServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetadataServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetadataServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetadataServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/base.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/base.py index 65caf71e4f91..018b293cf455 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/base.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc.py index 12fb99798187..a44ff587cae5 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc_asyncio.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc_asyncio.py index cf8c58cf95c1..f93e66bd67dc 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/rest.py b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/rest.py index dfdf03150fd0..c7fb452c9026 100644 --- a/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/rest.py +++ b/packages/google-cloud-dataplex/google/cloud/dataplex_v1/services/metadata_service/transports/rest.py @@ -709,6 +709,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MetadataServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataplex/noxfile.py b/packages/google-cloud-dataplex/noxfile.py index a642425b55bd..5ad2a0b7505f 100644 --- a/packages/google-cloud-dataplex/noxfile.py +++ b/packages/google-cloud-dataplex/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dataplex/setup.py b/packages/google-cloud-dataplex/setup.py index 98f4cb41e409..d8d13bca3ceb 100644 --- a/packages/google-cloud-dataplex/setup.py +++ b/packages/google-cloud-dataplex/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dataplex/testing/constraints-3.7.txt b/packages/google-cloud-dataplex/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-dataplex/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataplex/testing/constraints-3.8.txt b/packages/google-cloud-dataplex/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-dataplex/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-dataplex/testing/constraints-3.9.txt b/packages/google-cloud-dataplex/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-dataplex/testing/constraints-3.9.txt +++ b/packages/google-cloud-dataplex/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_business_glossary_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_business_glossary_service.py index 56f6a0730fe7..b3cf5a4db5da 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_business_glossary_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_business_glossary_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BusinessGlossaryServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): BusinessGlossaryServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BusinessGlossaryServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1360,11 +1365,13 @@ def test_business_glossary_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -11283,8 +11290,9 @@ def test_create_glossary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11420,20 +11428,21 @@ def test_create_glossary_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_create_glossary" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_create_glossary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_create_glossary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "post_create_glossary" + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_create_glossary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_create_glossary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11488,8 +11497,9 @@ def test_update_glossary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11627,20 +11637,21 @@ def test_update_glossary_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_update_glossary" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_update_glossary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_update_glossary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "post_update_glossary" + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_update_glossary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_update_glossary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11693,8 +11704,9 @@ def test_delete_glossary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11751,20 +11763,21 @@ def test_delete_glossary_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_delete_glossary" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_delete_glossary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_delete_glossary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "post_delete_glossary" + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_delete_glossary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_delete_glossary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11817,8 +11830,9 @@ def test_get_glossary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11893,18 +11907,20 @@ def test_get_glossary_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_get_glossary" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_get_glossary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_get_glossary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "post_get_glossary" + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_get_glossary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_get_glossary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11957,8 +11973,9 @@ def test_list_glossaries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12023,18 +12040,20 @@ def test_list_glossaries_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_list_glossaries" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_list_glossaries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_list_glossaries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "post_list_glossaries" + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_list_glossaries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_list_glossaries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12092,8 +12111,9 @@ def test_create_glossary_category_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12241,20 +12261,22 @@ def test_create_glossary_category_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_create_glossary_category", - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_create_glossary_category_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "pre_create_glossary_category", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_create_glossary_category", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_create_glossary_category_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_create_glossary_category", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12313,8 +12335,9 @@ def test_update_glossary_category_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12466,20 +12489,22 @@ def test_update_glossary_category_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_update_glossary_category", - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_update_glossary_category_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "pre_update_glossary_category", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_update_glossary_category", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_update_glossary_category_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_update_glossary_category", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12536,8 +12561,9 @@ def test_delete_glossary_category_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12596,14 +12622,14 @@ def test_delete_glossary_category_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "pre_delete_glossary_category", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_delete_glossary_category", + ) as pre, + ): pre.assert_not_called() pb_message = business_glossary.DeleteGlossaryCategoryRequest.pb( business_glossary.DeleteGlossaryCategoryRequest() @@ -12650,8 +12676,9 @@ def test_get_glossary_category_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12724,18 +12751,22 @@ def test_get_glossary_category_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_get_glossary_category" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_get_glossary_category_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_get_glossary_category" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_get_glossary_category", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_get_glossary_category_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_get_glossary_category", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12790,8 +12821,9 @@ def test_list_glossary_categories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12856,20 +12888,22 @@ def test_list_glossary_categories_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_list_glossary_categories", - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_list_glossary_categories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "pre_list_glossary_categories", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_list_glossary_categories", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_list_glossary_categories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_list_glossary_categories", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12927,8 +12961,9 @@ def test_create_glossary_term_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13076,18 +13111,22 @@ def test_create_glossary_term_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_create_glossary_term" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_create_glossary_term_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_create_glossary_term" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_create_glossary_term", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_create_glossary_term_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_create_glossary_term", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13146,8 +13185,9 @@ def test_update_glossary_term_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13299,18 +13339,22 @@ def test_update_glossary_term_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_update_glossary_term" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_update_glossary_term_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_update_glossary_term" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_update_glossary_term", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_update_glossary_term_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_update_glossary_term", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13367,8 +13411,9 @@ def test_delete_glossary_term_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13427,13 +13472,14 @@ def test_delete_glossary_term_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_delete_glossary_term" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "pre_delete_glossary_term", + ) as pre, + ): pre.assert_not_called() pb_message = business_glossary.DeleteGlossaryTermRequest.pb( business_glossary.DeleteGlossaryTermRequest() @@ -13480,8 +13526,9 @@ def test_get_glossary_term_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13554,18 +13601,20 @@ def test_get_glossary_term_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_get_glossary_term" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_get_glossary_term_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_get_glossary_term" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "post_get_glossary_term" + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_get_glossary_term_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_get_glossary_term" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13620,8 +13669,9 @@ def test_list_glossary_terms_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13686,18 +13736,21 @@ def test_list_glossary_terms_rest_interceptors(null_interceptor): ) client = BusinessGlossaryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "post_list_glossary_terms" - ) as post, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, - "post_list_glossary_terms_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BusinessGlossaryServiceRestInterceptor, "pre_list_glossary_terms" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_list_glossary_terms", + ) as post, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, + "post_list_glossary_terms_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BusinessGlossaryServiceRestInterceptor, "pre_list_glossary_terms" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13755,8 +13808,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13815,8 +13869,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13877,8 +13932,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13939,8 +13995,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14001,8 +14058,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14063,8 +14121,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14534,11 +14593,14 @@ def test_business_glossary_service_base_transport(): def test_business_glossary_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.business_glossary_service.transports.BusinessGlossaryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.business_glossary_service.transports.BusinessGlossaryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BusinessGlossaryServiceTransport( @@ -14555,9 +14617,12 @@ def test_business_glossary_service_base_transport_with_credentials_file(): def test_business_glossary_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.business_glossary_service.transports.BusinessGlossaryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.business_glossary_service.transports.BusinessGlossaryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BusinessGlossaryServiceTransport() @@ -14631,11 +14696,12 @@ def test_business_glossary_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -15338,6 +15404,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BusinessGlossaryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BusinessGlossaryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BusinessGlossaryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15477,6 +15575,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BusinessGlossaryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BusinessGlossaryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BusinessGlossaryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15622,6 +15752,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BusinessGlossaryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BusinessGlossaryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BusinessGlossaryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15767,6 +15931,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BusinessGlossaryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BusinessGlossaryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = BusinessGlossaryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15912,6 +16110,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BusinessGlossaryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BusinessGlossaryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BusinessGlossaryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16057,6 +16289,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BusinessGlossaryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BusinessGlossaryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = BusinessGlossaryServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_catalog_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_catalog_service.py index 729871a82bd8..6547dcfcd00e 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_catalog_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_catalog_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CatalogServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( CatalogServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CatalogServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1295,11 +1300,13 @@ def test_catalog_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -20061,8 +20068,9 @@ def test_create_entry_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20201,19 +20209,21 @@ def test_create_entry_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_create_entry_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_entry_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_create_entry_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_create_entry_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20266,8 +20276,9 @@ def test_update_entry_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20408,19 +20419,21 @@ def test_update_entry_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_update_entry_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_update_entry_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_update_entry_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_update_entry_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_update_entry_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_update_entry_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20471,8 +20484,9 @@ def test_delete_entry_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20529,19 +20543,21 @@ def test_delete_entry_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_delete_entry_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_delete_entry_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_delete_entry_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_delete_entry_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20590,8 +20606,9 @@ def test_list_entry_types_rest_bad_request(request_type=catalog.ListEntryTypesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20656,17 +20673,20 @@ def test_list_entry_types_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_entry_types" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_entry_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_list_entry_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_list_entry_types" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_list_entry_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_list_entry_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20717,8 +20737,9 @@ def test_get_entry_type_rest_bad_request(request_type=catalog.GetEntryTypeReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20795,17 +20816,20 @@ def test_get_entry_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_get_entry_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_entry_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_get_entry_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_get_entry_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20856,8 +20880,9 @@ def test_create_aspect_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21016,20 +21041,21 @@ def test_create_aspect_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_aspect_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_create_aspect_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_create_aspect_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_aspect_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_create_aspect_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_create_aspect_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21086,8 +21112,9 @@ def test_update_aspect_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21250,20 +21277,21 @@ def test_update_aspect_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_update_aspect_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_update_aspect_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_update_aspect_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_update_aspect_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_update_aspect_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_update_aspect_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21316,8 +21344,9 @@ def test_delete_aspect_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21374,20 +21403,21 @@ def test_delete_aspect_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_aspect_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_delete_aspect_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_delete_aspect_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_delete_aspect_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_delete_aspect_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_delete_aspect_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21440,8 +21470,9 @@ def test_list_aspect_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21506,17 +21537,20 @@ def test_list_aspect_types_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_aspect_types" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_aspect_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_list_aspect_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_list_aspect_types" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_list_aspect_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_list_aspect_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21567,8 +21601,9 @@ def test_get_aspect_type_rest_bad_request(request_type=catalog.GetAspectTypeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21646,17 +21681,20 @@ def test_get_aspect_type_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_aspect_type" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_aspect_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_get_aspect_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_aspect_type" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_get_aspect_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_get_aspect_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21707,8 +21745,9 @@ def test_create_entry_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21843,20 +21882,21 @@ def test_create_entry_group_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry_group" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_create_entry_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_create_entry_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_entry_group" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_create_entry_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_create_entry_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21913,8 +21953,9 @@ def test_update_entry_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22053,20 +22094,21 @@ def test_update_entry_group_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_update_entry_group" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_update_entry_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_update_entry_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_update_entry_group" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_update_entry_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_update_entry_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22119,8 +22161,9 @@ def test_delete_entry_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22177,20 +22220,21 @@ def test_delete_entry_group_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry_group" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_delete_entry_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_delete_entry_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_delete_entry_group" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_delete_entry_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_delete_entry_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22243,8 +22287,9 @@ def test_list_entry_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22309,17 +22354,20 @@ def test_list_entry_groups_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_entry_groups" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_entry_groups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_list_entry_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_list_entry_groups" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_list_entry_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_list_entry_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22370,8 +22418,9 @@ def test_get_entry_group_rest_bad_request(request_type=catalog.GetEntryGroupRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22444,17 +22493,20 @@ def test_get_entry_group_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_group" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_get_entry_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_entry_group" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_get_entry_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_get_entry_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22503,8 +22555,9 @@ def test_create_entry_rest_bad_request(request_type=catalog.CreateEntryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22661,17 +22714,19 @@ def test_create_entry_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_create_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_entry" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_entry_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_create_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22724,8 +22779,9 @@ def test_update_entry_rest_bad_request(request_type=catalog.UpdateEntryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22886,17 +22942,19 @@ def test_update_entry_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_update_entry" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_update_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_update_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_update_entry" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_update_entry_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_update_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22947,8 +23005,9 @@ def test_delete_entry_rest_bad_request(request_type=catalog.DeleteEntryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23019,17 +23078,19 @@ def test_delete_entry_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_delete_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_delete_entry" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_delete_entry_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_delete_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23078,8 +23139,9 @@ def test_list_entries_rest_bad_request(request_type=catalog.ListEntriesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23142,17 +23204,19 @@ def test_list_entries_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_entries" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_entries_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_list_entries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_list_entries" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_list_entries_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_list_entries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23205,8 +23269,9 @@ def test_get_entry_rest_bad_request(request_type=catalog.GetEntryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23277,17 +23342,19 @@ def test_get_entry_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_get_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_entry" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_entry_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_get_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23336,8 +23403,9 @@ def test_lookup_entry_rest_bad_request(request_type=catalog.LookupEntryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23406,17 +23474,19 @@ def test_lookup_entry_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_lookup_entry" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_lookup_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_lookup_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_lookup_entry" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_lookup_entry_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_lookup_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23465,8 +23535,9 @@ def test_search_entries_rest_bad_request(request_type=catalog.SearchEntriesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23533,17 +23604,20 @@ def test_search_entries_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_search_entries" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_search_entries_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_search_entries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_search_entries" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_search_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_search_entries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23596,8 +23670,9 @@ def test_create_metadata_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23781,20 +23856,21 @@ def test_create_metadata_job_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_metadata_job" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_create_metadata_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_create_metadata_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_metadata_job" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_create_metadata_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_create_metadata_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23845,8 +23921,9 @@ def test_get_metadata_job_rest_bad_request(request_type=catalog.GetMetadataJobRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23913,17 +23990,20 @@ def test_get_metadata_job_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_metadata_job" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_metadata_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_get_metadata_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_metadata_job" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_get_metadata_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_get_metadata_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23974,8 +24054,9 @@ def test_list_metadata_jobs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24040,18 +24121,20 @@ def test_list_metadata_jobs_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_list_metadata_jobs" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, - "post_list_metadata_jobs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_list_metadata_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_list_metadata_jobs" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_list_metadata_jobs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_list_metadata_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24106,8 +24189,9 @@ def test_cancel_metadata_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24164,13 +24248,13 @@ def test_cancel_metadata_job_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_cancel_metadata_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_cancel_metadata_job" + ) as pre, + ): pre.assert_not_called() pb_message = catalog.CancelMetadataJobRequest.pb( catalog.CancelMetadataJobRequest() @@ -24215,8 +24299,9 @@ def test_create_entry_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24355,17 +24440,20 @@ def test_create_entry_link_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry_link" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_create_entry_link_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_create_entry_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_create_entry_link" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_create_entry_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_create_entry_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24418,8 +24506,9 @@ def test_delete_entry_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24486,17 +24575,20 @@ def test_delete_entry_link_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry_link" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_delete_entry_link_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_delete_entry_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_delete_entry_link" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_delete_entry_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_delete_entry_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24547,8 +24639,9 @@ def test_get_entry_link_rest_bad_request(request_type=catalog.GetEntryLinkReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24615,17 +24708,20 @@ def test_get_entry_link_rest_interceptors(null_interceptor): ) client = CatalogServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_link" - ) as post, mock.patch.object( - transports.CatalogServiceRestInterceptor, "post_get_entry_link_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CatalogServiceRestInterceptor, "pre_get_entry_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "post_get_entry_link" + ) as post, + mock.patch.object( + transports.CatalogServiceRestInterceptor, + "post_get_entry_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CatalogServiceRestInterceptor, "pre_get_entry_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24676,8 +24772,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24736,8 +24833,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24798,8 +24896,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24860,8 +24959,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24922,8 +25022,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24984,8 +25085,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25761,11 +25863,14 @@ def test_catalog_service_base_transport(): def test_catalog_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.catalog_service.transports.CatalogServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.catalog_service.transports.CatalogServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CatalogServiceTransport( @@ -25782,9 +25887,12 @@ def test_catalog_service_base_transport_with_credentials_file(): def test_catalog_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.catalog_service.transports.CatalogServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.catalog_service.transports.CatalogServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CatalogServiceTransport() @@ -25856,11 +25964,12 @@ def test_catalog_service_transport_auth_gdch_credentials(transport_class): def test_catalog_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -26711,6 +26820,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CatalogServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CatalogServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CatalogServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26850,6 +26991,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CatalogServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CatalogServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CatalogServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26995,6 +27168,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CatalogServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CatalogServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CatalogServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27140,6 +27347,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CatalogServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CatalogServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CatalogServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27285,6 +27526,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CatalogServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CatalogServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CatalogServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27426,6 +27701,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CatalogServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CatalogServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CatalogServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_cmek_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_cmek_service.py index 6cae16bec650..39c89a355837 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_cmek_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_cmek_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CmekServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CmekServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CmekServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1257,11 +1261,13 @@ def test_cmek_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4695,8 +4701,9 @@ def test_create_encryption_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4830,20 +4837,21 @@ def test_create_encryption_config_rest_interceptors(null_interceptor): ) client = CmekServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CmekServiceRestInterceptor, "post_create_encryption_config" - ) as post, mock.patch.object( - transports.CmekServiceRestInterceptor, - "post_create_encryption_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekServiceRestInterceptor, "pre_create_encryption_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CmekServiceRestInterceptor, "post_create_encryption_config" + ) as post, + mock.patch.object( + transports.CmekServiceRestInterceptor, + "post_create_encryption_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekServiceRestInterceptor, "pre_create_encryption_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4900,8 +4908,9 @@ def test_update_encryption_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5039,20 +5048,21 @@ def test_update_encryption_config_rest_interceptors(null_interceptor): ) client = CmekServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CmekServiceRestInterceptor, "post_update_encryption_config" - ) as post, mock.patch.object( - transports.CmekServiceRestInterceptor, - "post_update_encryption_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekServiceRestInterceptor, "pre_update_encryption_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CmekServiceRestInterceptor, "post_update_encryption_config" + ) as post, + mock.patch.object( + transports.CmekServiceRestInterceptor, + "post_update_encryption_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekServiceRestInterceptor, "pre_update_encryption_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5107,8 +5117,9 @@ def test_delete_encryption_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5167,20 +5178,21 @@ def test_delete_encryption_config_rest_interceptors(null_interceptor): ) client = CmekServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CmekServiceRestInterceptor, "post_delete_encryption_config" - ) as post, mock.patch.object( - transports.CmekServiceRestInterceptor, - "post_delete_encryption_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekServiceRestInterceptor, "pre_delete_encryption_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CmekServiceRestInterceptor, "post_delete_encryption_config" + ) as post, + mock.patch.object( + transports.CmekServiceRestInterceptor, + "post_delete_encryption_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekServiceRestInterceptor, "pre_delete_encryption_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5233,8 +5245,9 @@ def test_list_encryption_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5299,18 +5312,20 @@ def test_list_encryption_configs_rest_interceptors(null_interceptor): ) client = CmekServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmekServiceRestInterceptor, "post_list_encryption_configs" - ) as post, mock.patch.object( - transports.CmekServiceRestInterceptor, - "post_list_encryption_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekServiceRestInterceptor, "pre_list_encryption_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmekServiceRestInterceptor, "post_list_encryption_configs" + ) as post, + mock.patch.object( + transports.CmekServiceRestInterceptor, + "post_list_encryption_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekServiceRestInterceptor, "pre_list_encryption_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5367,8 +5382,9 @@ def test_get_encryption_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5441,18 +5457,20 @@ def test_get_encryption_config_rest_interceptors(null_interceptor): ) client = CmekServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmekServiceRestInterceptor, "post_get_encryption_config" - ) as post, mock.patch.object( - transports.CmekServiceRestInterceptor, - "post_get_encryption_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekServiceRestInterceptor, "pre_get_encryption_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmekServiceRestInterceptor, "post_get_encryption_config" + ) as post, + mock.patch.object( + transports.CmekServiceRestInterceptor, + "post_get_encryption_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekServiceRestInterceptor, "pre_get_encryption_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5505,8 +5523,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5565,8 +5584,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5627,8 +5647,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5689,8 +5710,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5751,8 +5773,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5813,8 +5836,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6064,11 +6088,14 @@ def test_cmek_service_base_transport(): def test_cmek_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.cmek_service.transports.CmekServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.cmek_service.transports.CmekServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmekServiceTransport( @@ -6085,9 +6112,12 @@ def test_cmek_service_base_transport_with_credentials_file(): def test_cmek_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.cmek_service.transports.CmekServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.cmek_service.transports.CmekServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmekServiceTransport() @@ -6159,11 +6189,12 @@ def test_cmek_service_transport_auth_gdch_credentials(transport_class): def test_cmek_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6786,6 +6817,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CmekServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CmekServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CmekServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6925,6 +6988,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CmekServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CmekServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CmekServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7070,6 +7165,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CmekServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CmekServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CmekServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7215,6 +7344,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CmekServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CmekServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CmekServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7360,6 +7523,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CmekServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CmekServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CmekServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7501,6 +7698,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CmekServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CmekServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CmekServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_content_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_content_service.py index c13277ecd576..c013bf4f5538 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_content_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_content_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): assert ( ContentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ContentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1294,11 +1299,13 @@ def test_content_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6009,8 +6016,9 @@ def test_create_content_rest_bad_request(request_type=gcd_content.CreateContentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6159,17 +6167,20 @@ def test_create_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_create_content" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_create_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_create_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_create_content" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, + "post_create_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_create_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6224,8 +6235,9 @@ def test_update_content_rest_bad_request(request_type=gcd_content.UpdateContentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6378,17 +6390,20 @@ def test_update_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_update_content" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_update_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_update_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_update_content" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, + "post_update_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_update_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6441,8 +6456,9 @@ def test_delete_content_rest_bad_request(request_type=content.DeleteContentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6501,13 +6517,13 @@ def test_delete_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_delete_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_delete_content" + ) as pre, + ): pre.assert_not_called() pb_message = content.DeleteContentRequest.pb(content.DeleteContentRequest()) transcode.return_value = { @@ -6550,8 +6566,9 @@ def test_get_content_rest_bad_request(request_type=content.GetContentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6623,17 +6640,19 @@ def test_get_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_get_content" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_get_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_get_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_get_content" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_get_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_get_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6686,8 +6705,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6751,17 +6771,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6814,8 +6837,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6879,17 +6903,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6942,8 +6969,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7005,18 +7033,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7070,8 +7100,9 @@ def test_list_content_rest_bad_request(request_type=content.ListContentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7134,17 +7165,19 @@ def test_list_content_rest_interceptors(null_interceptor): ) client = ContentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_list_content" - ) as post, mock.patch.object( - transports.ContentServiceRestInterceptor, "post_list_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContentServiceRestInterceptor, "pre_list_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_list_content" + ) as post, + mock.patch.object( + transports.ContentServiceRestInterceptor, "post_list_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContentServiceRestInterceptor, "pre_list_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7197,8 +7230,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7257,8 +7291,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7319,8 +7354,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7381,8 +7417,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7443,8 +7480,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7505,8 +7543,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7789,11 +7828,14 @@ def test_content_service_base_transport(): def test_content_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentServiceTransport( @@ -7810,9 +7852,12 @@ def test_content_service_base_transport_with_credentials_file(): def test_content_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.content_service.transports.ContentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContentServiceTransport() @@ -7884,11 +7929,12 @@ def test_content_service_transport_auth_gdch_credentials(transport_class): def test_content_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8503,6 +8549,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ContentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ContentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ContentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8642,6 +8720,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ContentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ContentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ContentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8787,6 +8897,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ContentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ContentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ContentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8932,6 +9076,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ContentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ContentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ContentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9077,6 +9255,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ContentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ContentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ContentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9218,6 +9430,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ContentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ContentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ContentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_scan_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_scan_service.py index 2d51bbae6565..0c7a576f807b 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_scan_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_scan_service.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataScanServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -164,6 +165,10 @@ def test__get_default_mtls_endpoint(): assert ( DataScanServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataScanServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1328,11 +1333,13 @@ def test_data_scan_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7219,8 +7226,9 @@ def test_create_data_scan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7577,19 +7585,21 @@ def test_create_data_scan_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_create_data_scan" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_create_data_scan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_create_data_scan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_create_data_scan" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_create_data_scan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_create_data_scan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7644,8 +7654,9 @@ def test_update_data_scan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8004,19 +8015,21 @@ def test_update_data_scan_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_update_data_scan" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_update_data_scan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_update_data_scan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_update_data_scan" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_update_data_scan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_update_data_scan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8069,8 +8082,9 @@ def test_delete_data_scan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8127,19 +8141,21 @@ def test_delete_data_scan_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_delete_data_scan" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_delete_data_scan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_delete_data_scan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_delete_data_scan" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_delete_data_scan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_delete_data_scan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8190,8 +8206,9 @@ def test_get_data_scan_rest_bad_request(request_type=datascans.GetDataScanReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8264,17 +8281,20 @@ def test_get_data_scan_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_get_data_scan" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_get_data_scan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_get_data_scan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_get_data_scan" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_get_data_scan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_get_data_scan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8323,8 +8343,9 @@ def test_list_data_scans_rest_bad_request(request_type=datascans.ListDataScansRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8389,17 +8410,20 @@ def test_list_data_scans_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_list_data_scans" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_list_data_scans_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_list_data_scans" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_list_data_scans" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_list_data_scans_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_list_data_scans" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8450,8 +8474,9 @@ def test_run_data_scan_rest_bad_request(request_type=datascans.RunDataScanReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8511,17 +8536,20 @@ def test_run_data_scan_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_run_data_scan" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_run_data_scan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_run_data_scan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_run_data_scan" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_run_data_scan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_run_data_scan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8576,8 +8604,9 @@ def test_get_data_scan_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8650,18 +8679,20 @@ def test_get_data_scan_job_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_get_data_scan_job" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, - "post_get_data_scan_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_get_data_scan_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_get_data_scan_job" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_get_data_scan_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_get_data_scan_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8714,8 +8745,9 @@ def test_list_data_scan_jobs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8778,18 +8810,20 @@ def test_list_data_scan_jobs_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_list_data_scan_jobs" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, - "post_list_data_scan_jobs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_list_data_scan_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "post_list_data_scan_jobs" + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_list_data_scan_jobs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_list_data_scan_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8844,8 +8878,9 @@ def test_generate_data_quality_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8905,18 +8940,21 @@ def test_generate_data_quality_rules_rest_interceptors(null_interceptor): ) client = DataScanServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataScanServiceRestInterceptor, "post_generate_data_quality_rules" - ) as post, mock.patch.object( - transports.DataScanServiceRestInterceptor, - "post_generate_data_quality_rules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataScanServiceRestInterceptor, "pre_generate_data_quality_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_generate_data_quality_rules", + ) as post, + mock.patch.object( + transports.DataScanServiceRestInterceptor, + "post_generate_data_quality_rules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataScanServiceRestInterceptor, "pre_generate_data_quality_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8974,8 +9012,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9034,8 +9073,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9096,8 +9136,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9158,8 +9199,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9220,8 +9262,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9282,8 +9325,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9613,11 +9657,14 @@ def test_data_scan_service_base_transport(): def test_data_scan_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.data_scan_service.transports.DataScanServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.data_scan_service.transports.DataScanServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataScanServiceTransport( @@ -9634,9 +9681,12 @@ def test_data_scan_service_base_transport_with_credentials_file(): def test_data_scan_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.data_scan_service.transports.DataScanServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.data_scan_service.transports.DataScanServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataScanServiceTransport() @@ -9708,11 +9758,12 @@ def test_data_scan_service_transport_auth_gdch_credentials(transport_class): def test_data_scan_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10445,6 +10496,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataScanServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataScanServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataScanServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10584,6 +10667,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataScanServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataScanServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataScanServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10729,6 +10844,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataScanServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataScanServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataScanServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10874,6 +11023,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataScanServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataScanServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataScanServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11019,6 +11202,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataScanServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataScanServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataScanServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11160,6 +11377,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataScanServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataScanServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataScanServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_taxonomy_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_taxonomy_service.py index 4eb4f6804ed5..b541d7578c54 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_taxonomy_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_data_taxonomy_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataTaxonomyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -156,6 +157,10 @@ def test__get_default_mtls_endpoint(): DataTaxonomyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataTaxonomyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1355,11 +1360,13 @@ def test_data_taxonomy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -11506,8 +11513,9 @@ def test_create_data_taxonomy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11645,20 +11653,21 @@ def test_create_data_taxonomy_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_create_data_taxonomy" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_create_data_taxonomy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_create_data_taxonomy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_create_data_taxonomy" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_create_data_taxonomy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_create_data_taxonomy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11715,8 +11724,9 @@ def test_update_data_taxonomy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11858,20 +11868,21 @@ def test_update_data_taxonomy_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_update_data_taxonomy" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_update_data_taxonomy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_update_data_taxonomy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_update_data_taxonomy" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_update_data_taxonomy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_update_data_taxonomy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11924,8 +11935,9 @@ def test_delete_data_taxonomy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11982,20 +11994,21 @@ def test_delete_data_taxonomy_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_delete_data_taxonomy" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_delete_data_taxonomy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_delete_data_taxonomy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_delete_data_taxonomy" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_delete_data_taxonomy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_delete_data_taxonomy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12048,8 +12061,9 @@ def test_list_data_taxonomies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12114,18 +12128,20 @@ def test_list_data_taxonomies_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_list_data_taxonomies" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_list_data_taxonomies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_list_data_taxonomies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_list_data_taxonomies" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_list_data_taxonomies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_list_data_taxonomies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12183,8 +12199,9 @@ def test_get_data_taxonomy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12259,18 +12276,20 @@ def test_get_data_taxonomy_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_get_data_taxonomy" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_get_data_taxonomy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_get_data_taxonomy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_get_data_taxonomy" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_get_data_taxonomy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_get_data_taxonomy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12323,8 +12342,9 @@ def test_create_data_attribute_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12470,22 +12490,23 @@ def test_create_data_attribute_binding_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_create_data_attribute_binding", - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_create_data_attribute_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "pre_create_data_attribute_binding", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_create_data_attribute_binding", + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_create_data_attribute_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "pre_create_data_attribute_binding", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12542,8 +12563,9 @@ def test_update_data_attribute_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12693,22 +12715,23 @@ def test_update_data_attribute_binding_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_update_data_attribute_binding", - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_update_data_attribute_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "pre_update_data_attribute_binding", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_update_data_attribute_binding", + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_update_data_attribute_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "pre_update_data_attribute_binding", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12763,8 +12786,9 @@ def test_delete_data_attribute_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12823,22 +12847,23 @@ def test_delete_data_attribute_binding_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_delete_data_attribute_binding", - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_delete_data_attribute_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "pre_delete_data_attribute_binding", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_delete_data_attribute_binding", + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_delete_data_attribute_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "pre_delete_data_attribute_binding", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12891,8 +12916,9 @@ def test_list_data_attribute_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12957,20 +12983,22 @@ def test_list_data_attribute_bindings_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_list_data_attribute_bindings", - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_list_data_attribute_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "pre_list_data_attribute_bindings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_list_data_attribute_bindings", + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_list_data_attribute_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "pre_list_data_attribute_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13030,8 +13058,9 @@ def test_get_data_attribute_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13107,18 +13136,22 @@ def test_get_data_attribute_binding_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_get_data_attribute_binding" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_get_data_attribute_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_get_data_attribute_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_get_data_attribute_binding", + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_get_data_attribute_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "pre_get_data_attribute_binding", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13175,8 +13208,9 @@ def test_create_data_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13320,20 +13354,21 @@ def test_create_data_attribute_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_create_data_attribute" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_create_data_attribute_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_create_data_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_create_data_attribute" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_create_data_attribute_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_create_data_attribute" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13390,8 +13425,9 @@ def test_update_data_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13537,20 +13573,21 @@ def test_update_data_attribute_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_update_data_attribute" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_update_data_attribute_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_update_data_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_update_data_attribute" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_update_data_attribute_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_update_data_attribute" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13605,8 +13642,9 @@ def test_delete_data_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13665,20 +13703,21 @@ def test_delete_data_attribute_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_delete_data_attribute" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_delete_data_attribute_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_delete_data_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_delete_data_attribute" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_delete_data_attribute_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_delete_data_attribute" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13733,8 +13772,9 @@ def test_list_data_attributes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13801,18 +13841,20 @@ def test_list_data_attributes_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_list_data_attributes" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_list_data_attributes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_list_data_attributes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_list_data_attributes" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_list_data_attributes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_list_data_attributes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13872,8 +13914,9 @@ def test_get_data_attribute_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13950,18 +13993,20 @@ def test_get_data_attribute_rest_interceptors(null_interceptor): ) client = DataTaxonomyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "post_get_data_attribute" - ) as post, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, - "post_get_data_attribute_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataTaxonomyServiceRestInterceptor, "pre_get_data_attribute" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "post_get_data_attribute" + ) as post, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, + "post_get_data_attribute_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataTaxonomyServiceRestInterceptor, "pre_get_data_attribute" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14016,8 +14061,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14076,8 +14122,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14138,8 +14185,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14200,8 +14248,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14262,8 +14311,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14324,8 +14374,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14805,11 +14856,14 @@ def test_data_taxonomy_service_base_transport(): def test_data_taxonomy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.data_taxonomy_service.transports.DataTaxonomyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.data_taxonomy_service.transports.DataTaxonomyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataTaxonomyServiceTransport( @@ -14826,9 +14880,12 @@ def test_data_taxonomy_service_base_transport_with_credentials_file(): def test_data_taxonomy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.data_taxonomy_service.transports.DataTaxonomyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.data_taxonomy_service.transports.DataTaxonomyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataTaxonomyServiceTransport() @@ -14900,11 +14957,12 @@ def test_data_taxonomy_service_transport_auth_gdch_credentials(transport_class): def test_data_taxonomy_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -15606,6 +15664,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataTaxonomyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataTaxonomyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataTaxonomyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15745,6 +15835,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataTaxonomyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataTaxonomyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataTaxonomyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15890,6 +16012,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataTaxonomyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataTaxonomyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataTaxonomyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16035,6 +16191,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataTaxonomyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataTaxonomyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataTaxonomyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16180,6 +16370,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataTaxonomyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataTaxonomyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataTaxonomyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16323,6 +16547,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataTaxonomyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataTaxonomyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataTaxonomyServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_dataplex_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_dataplex_service.py index b3e948cce3a1..e7e57e27990c 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_dataplex_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_dataplex_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataplexServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( DataplexServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataplexServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1319,11 +1324,13 @@ def test_dataplex_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -23093,8 +23100,9 @@ def test_create_lake_rest_bad_request(request_type=service.CreateLakeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23241,19 +23249,20 @@ def test_create_lake_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_lake" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_lake_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_create_lake" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_lake" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_lake_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_create_lake" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23304,8 +23313,9 @@ def test_update_lake_rest_bad_request(request_type=service.UpdateLakeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23454,19 +23464,20 @@ def test_update_lake_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_lake" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_lake_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_update_lake" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_lake" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_lake_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_update_lake" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23515,8 +23526,9 @@ def test_delete_lake_rest_bad_request(request_type=service.DeleteLakeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23573,19 +23585,20 @@ def test_delete_lake_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_lake" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_lake_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_delete_lake" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_lake" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_lake_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_delete_lake" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23634,8 +23647,9 @@ def test_list_lakes_rest_bad_request(request_type=service.ListLakesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23700,17 +23714,19 @@ def test_list_lakes_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_lakes" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_lakes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_lakes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_lakes" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_lakes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_lakes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23759,8 +23775,9 @@ def test_get_lake_rest_bad_request(request_type=service.GetLakeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23833,17 +23850,19 @@ def test_get_lake_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_lake" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_lake_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_get_lake" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_lake" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_lake_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_get_lake" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23894,8 +23913,9 @@ def test_list_lake_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23958,18 +23978,20 @@ def test_list_lake_actions_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_lake_actions" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_list_lake_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_lake_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_lake_actions" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_list_lake_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_lake_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24020,8 +24042,9 @@ def test_create_zone_rest_bad_request(request_type=service.CreateZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24178,19 +24201,20 @@ def test_create_zone_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_zone" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_create_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_zone" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_zone_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_create_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24243,8 +24267,9 @@ def test_update_zone_rest_bad_request(request_type=service.UpdateZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24405,19 +24430,20 @@ def test_update_zone_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_zone" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_update_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_zone" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_zone_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_update_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24468,8 +24494,9 @@ def test_delete_zone_rest_bad_request(request_type=service.DeleteZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24528,19 +24555,20 @@ def test_delete_zone_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_zone" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_delete_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_zone" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_zone_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_delete_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24589,8 +24617,9 @@ def test_list_zones_rest_bad_request(request_type=service.ListZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24653,17 +24682,19 @@ def test_list_zones_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_zones" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_zones_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_zones" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_zones" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_zones_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_zones" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24714,8 +24745,9 @@ def test_get_zone_rest_bad_request(request_type=service.GetZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24790,17 +24822,19 @@ def test_get_zone_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_zone" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_get_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_zone" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_zone_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_get_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24853,8 +24887,9 @@ def test_list_zone_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24919,18 +24954,20 @@ def test_list_zone_actions_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_zone_actions" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_list_zone_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_zone_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_zone_actions" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_list_zone_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_zone_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24983,8 +25020,9 @@ def test_create_asset_rest_bad_request(request_type=service.CreateAssetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25157,19 +25195,20 @@ def test_create_asset_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_asset" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_asset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_create_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_asset" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_asset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_create_asset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25222,8 +25261,9 @@ def test_update_asset_rest_bad_request(request_type=service.UpdateAssetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25398,19 +25438,20 @@ def test_update_asset_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_asset" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_asset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_update_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_asset" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_asset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_update_asset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25461,8 +25502,9 @@ def test_delete_asset_rest_bad_request(request_type=service.DeleteAssetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25521,19 +25563,20 @@ def test_delete_asset_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_asset" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_asset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_delete_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_asset" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_asset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_delete_asset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25584,8 +25627,9 @@ def test_list_assets_rest_bad_request(request_type=service.ListAssetsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25650,17 +25694,19 @@ def test_list_assets_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_assets" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_assets" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25711,8 +25757,9 @@ def test_get_asset_rest_bad_request(request_type=service.GetAssetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25785,17 +25832,19 @@ def test_get_asset_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_asset" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_asset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_get_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_asset" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_asset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_get_asset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25848,8 +25897,9 @@ def test_list_asset_actions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25914,18 +25964,20 @@ def test_list_asset_actions_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_asset_actions" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_list_asset_actions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_asset_actions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_asset_actions" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_list_asset_actions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_asset_actions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25978,8 +26030,9 @@ def test_create_task_rest_bad_request(request_type=service.CreateTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26176,19 +26229,20 @@ def test_create_task_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_task" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_create_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_task" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_create_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26241,8 +26295,9 @@ def test_update_task_rest_bad_request(request_type=service.UpdateTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26443,19 +26498,20 @@ def test_update_task_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_task" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_update_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_task" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_update_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26506,8 +26562,9 @@ def test_delete_task_rest_bad_request(request_type=service.DeleteTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26566,19 +26623,20 @@ def test_delete_task_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_task" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_delete_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_task" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_delete_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26627,8 +26685,9 @@ def test_list_tasks_rest_bad_request(request_type=service.ListTasksRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26693,17 +26752,19 @@ def test_list_tasks_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_tasks" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_tasks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_tasks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_tasks" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_tasks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_tasks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26754,8 +26815,9 @@ def test_get_task_rest_bad_request(request_type=service.GetTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26828,17 +26890,19 @@ def test_get_task_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_task" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_get_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_task" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_get_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26889,8 +26953,9 @@ def test_list_jobs_rest_bad_request(request_type=service.ListJobsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26955,17 +27020,19 @@ def test_list_jobs_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_jobs" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_jobs" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_jobs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27016,8 +27083,9 @@ def test_run_task_rest_bad_request(request_type=service.RunTaskRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27079,17 +27147,19 @@ def test_run_task_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_run_task" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_run_task_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_run_task" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_run_task" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_run_task_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_run_task" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27140,8 +27210,9 @@ def test_get_job_rest_bad_request(request_type=service.GetJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27220,17 +27291,19 @@ def test_get_job_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_job" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_get_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_job" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_get_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27281,8 +27354,9 @@ def test_cancel_job_rest_bad_request(request_type=service.CancelJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27341,13 +27415,13 @@ def test_cancel_job_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_cancel_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_cancel_job" + ) as pre, + ): pre.assert_not_called() pb_message = service.CancelJobRequest.pb(service.CancelJobRequest()) transcode.return_value = { @@ -27390,8 +27464,9 @@ def test_create_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27544,20 +27619,21 @@ def test_create_environment_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_create_environment" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_create_environment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_create_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_create_environment" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_create_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_create_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27614,8 +27690,9 @@ def test_update_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27772,20 +27849,21 @@ def test_update_environment_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_update_environment" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_update_environment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_update_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_update_environment" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_update_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_update_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27840,8 +27918,9 @@ def test_delete_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27900,20 +27979,21 @@ def test_delete_environment_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_delete_environment" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_delete_environment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_delete_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_delete_environment" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_delete_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_delete_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27966,8 +28046,9 @@ def test_list_environments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28030,18 +28111,20 @@ def test_list_environments_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_environments" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, - "post_list_environments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_environments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_environments" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_list_environments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_environments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28096,8 +28179,9 @@ def test_get_environment_rest_bad_request(request_type=service.GetEnvironmentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28170,17 +28254,20 @@ def test_get_environment_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_environment" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_get_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_get_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_get_environment" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_get_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_get_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28231,8 +28318,9 @@ def test_list_sessions_rest_bad_request(request_type=service.ListSessionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28297,17 +28385,20 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = DataplexServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.DataplexServiceRestInterceptor, "post_list_sessions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataplexServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.DataplexServiceRestInterceptor, + "post_list_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataplexServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28360,8 +28451,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28420,8 +28512,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28482,8 +28575,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28544,8 +28638,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28606,8 +28701,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28668,8 +28764,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -29511,11 +29608,14 @@ def test_dataplex_service_base_transport(): def test_dataplex_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.dataplex_service.transports.DataplexServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.dataplex_service.transports.DataplexServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataplexServiceTransport( @@ -29532,9 +29632,12 @@ def test_dataplex_service_base_transport_with_credentials_file(): def test_dataplex_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.dataplex_service.transports.DataplexServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.dataplex_service.transports.DataplexServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataplexServiceTransport() @@ -29606,11 +29709,12 @@ def test_dataplex_service_transport_auth_gdch_credentials(transport_class): def test_dataplex_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -30525,6 +30629,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataplexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataplexServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataplexServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30664,6 +30800,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataplexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataplexServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataplexServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30809,6 +30977,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataplexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataplexServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataplexServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30954,6 +31156,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataplexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataplexServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataplexServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31099,6 +31335,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataplexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataplexServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataplexServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -31240,6 +31510,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataplexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataplexServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataplexServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_metadata_service.py b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_metadata_service.py index bdce2895e091..16fae487194a 100644 --- a/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_metadata_service.py +++ b/packages/google-cloud-dataplex/tests/unit/gapic/dataplex_v1/test_metadata_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetadataServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): assert ( MetadataServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetadataServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1312,11 +1317,13 @@ def test_metadata_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7056,8 +7063,9 @@ def test_create_entity_rest_bad_request(request_type=metadata_.CreateEntityReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7259,17 +7267,20 @@ def test_create_entity_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_create_entity" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_create_entity_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_create_entity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_create_entity" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, + "post_create_entity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_create_entity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7322,8 +7333,9 @@ def test_update_entity_rest_bad_request(request_type=metadata_.UpdateEntityReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7527,17 +7539,20 @@ def test_update_entity_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_update_entity" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_update_entity_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_update_entity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_update_entity" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, + "post_update_entity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_update_entity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7588,8 +7603,9 @@ def test_delete_entity_rest_bad_request(request_type=metadata_.DeleteEntityReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7648,13 +7664,13 @@ def test_delete_entity_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_delete_entity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_delete_entity" + ) as pre, + ): pre.assert_not_called() pb_message = metadata_.DeleteEntityRequest.pb(metadata_.DeleteEntityRequest()) transcode.return_value = { @@ -7697,8 +7713,9 @@ def test_get_entity_rest_bad_request(request_type=metadata_.GetEntityRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7785,17 +7802,19 @@ def test_get_entity_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_get_entity" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_get_entity_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_get_entity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_get_entity" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_get_entity_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_get_entity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7846,8 +7865,9 @@ def test_list_entities_rest_bad_request(request_type=metadata_.ListEntitiesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7912,17 +7932,20 @@ def test_list_entities_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_list_entities" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_list_entities_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_list_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_list_entities" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, + "post_list_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_list_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7977,8 +8000,9 @@ def test_create_partition_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8122,17 +8146,20 @@ def test_create_partition_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_create_partition" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_create_partition_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_create_partition" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_create_partition" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, + "post_create_partition_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_create_partition" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8187,8 +8214,9 @@ def test_delete_partition_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8247,13 +8275,13 @@ def test_delete_partition_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_delete_partition" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_delete_partition" + ) as pre, + ): pre.assert_not_called() pb_message = metadata_.DeletePartitionRequest.pb( metadata_.DeletePartitionRequest() @@ -8298,8 +8326,9 @@ def test_get_partition_rest_bad_request(request_type=metadata_.GetPartitionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8370,17 +8399,20 @@ def test_get_partition_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_get_partition" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_get_partition_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_get_partition" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_get_partition" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, + "post_get_partition_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_get_partition" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8431,8 +8463,9 @@ def test_list_partitions_rest_bad_request(request_type=metadata_.ListPartitionsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8497,17 +8530,20 @@ def test_list_partitions_rest_interceptors(null_interceptor): ) client = MetadataServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_list_partitions" - ) as post, mock.patch.object( - transports.MetadataServiceRestInterceptor, "post_list_partitions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MetadataServiceRestInterceptor, "pre_list_partitions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "post_list_partitions" + ) as post, + mock.patch.object( + transports.MetadataServiceRestInterceptor, + "post_list_partitions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MetadataServiceRestInterceptor, "pre_list_partitions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8562,8 +8598,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8622,8 +8659,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8684,8 +8722,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8746,8 +8785,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8808,8 +8848,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8870,8 +8911,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9173,11 +9215,14 @@ def test_metadata_service_base_transport(): def test_metadata_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataplex_v1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataplex_v1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetadataServiceTransport( @@ -9194,9 +9239,12 @@ def test_metadata_service_base_transport_with_credentials_file(): def test_metadata_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataplex_v1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataplex_v1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetadataServiceTransport() @@ -9268,11 +9316,12 @@ def test_metadata_service_transport_auth_gdch_credentials(transport_class): def test_metadata_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9933,6 +9982,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10072,6 +10153,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10217,6 +10330,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10362,6 +10509,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10507,6 +10688,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10648,6 +10863,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py index a29e46b99143..076260b15183 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> DataprocMetastoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2656,7 +2656,7 @@ async def sample_alter_metadata_resource_location(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2682,8 +2682,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2692,7 +2696,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2700,7 +2704,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2711,7 +2715,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2737,8 +2741,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2747,7 +2755,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2755,7 +2763,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2766,7 +2774,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2796,8 +2804,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2806,7 +2818,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2814,7 +2826,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2822,7 +2834,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2851,8 +2863,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2861,7 +2877,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2869,7 +2885,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2877,7 +2893,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2969,8 +2985,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2979,7 +2999,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2987,7 +3009,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2998,7 +3020,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3091,8 +3113,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3101,7 +3127,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3109,7 +3137,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3120,7 +3148,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3151,8 +3179,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3163,7 +3195,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3171,7 +3205,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3182,7 +3216,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3208,8 +3242,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3218,7 +3256,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3226,7 +3264,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3237,7 +3275,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3263,8 +3301,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3273,7 +3315,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3281,7 +3323,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py index ad573ac2f224..9610df9b95be 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py @@ -143,7 +143,7 @@ class DataprocMetastoreClient(metaclass=DataprocMetastoreClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -151,7 +151,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -161,6 +161,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -557,7 +561,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -654,7 +658,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -754,7 +758,7 @@ def __init__( self._universe_domain = DataprocMetastoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3131,7 +3135,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3157,8 +3161,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3167,7 +3175,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3176,7 +3184,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3190,7 +3198,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3216,8 +3224,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3226,7 +3238,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3235,7 +3247,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3249,7 +3261,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3279,8 +3291,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3289,7 +3305,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3297,7 +3313,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3305,7 +3321,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3334,8 +3350,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3344,7 +3364,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3352,7 +3372,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3360,7 +3380,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3452,8 +3472,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3462,7 +3486,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3471,7 +3497,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3485,7 +3511,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3578,8 +3604,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3588,7 +3618,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3597,7 +3629,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3611,7 +3643,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3642,8 +3674,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3652,7 +3688,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3661,7 +3699,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3675,7 +3713,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3701,8 +3739,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3711,7 +3753,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3720,7 +3762,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3734,7 +3776,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3760,8 +3802,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3770,7 +3816,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3779,7 +3825,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/README.rst b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/README.rst index 1b6900a36bc0..2229a9da48af 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/README.rst +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataprocMetastoreTransport` is the ABC for all transports. -- public child `DataprocMetastoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataprocMetastoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataprocMetastoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataprocMetastoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataprocMetastoreTransport`` is the ABC for all transports. + +- public child ``DataprocMetastoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataprocMetastoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataprocMetastoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataprocMetastoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py index ec4040312c44..c3419c878b6e 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py index e11ed360b33f..a80d00b41709 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -210,6 +210,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py index 469baa28fbb4..d5c54fc13f3a 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -261,6 +261,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py index 058bd6179165..a7bb550dbb8e 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py @@ -1376,6 +1376,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataprocMetastoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py index 2308f9ea1c45..04c664f5dfb5 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> DataprocMetastoreFederationTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1028,7 +1028,7 @@ async def sample_delete_federation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1054,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1068,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1072,7 +1076,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1083,7 +1087,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1109,8 +1113,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1119,7 +1127,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1127,7 +1135,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1138,7 +1146,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1168,8 +1176,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1178,7 +1190,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1186,7 +1198,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1194,7 +1206,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1223,8 +1235,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1233,7 +1249,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1241,7 +1257,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1249,7 +1265,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1341,8 +1357,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1351,7 +1371,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1359,7 +1381,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1370,7 +1392,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1463,8 +1485,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1473,7 +1499,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1481,7 +1509,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1492,7 +1520,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1523,8 +1551,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1535,7 +1567,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1543,7 +1577,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1554,7 +1588,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1580,8 +1614,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1590,7 +1628,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1598,7 +1636,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1609,7 +1647,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1635,8 +1673,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1645,7 +1687,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1653,7 +1695,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py index 1c8bf8948a7c..1f7b59008733 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py @@ -141,7 +141,7 @@ class DataprocMetastoreFederationClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -149,7 +149,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -159,6 +159,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = DataprocMetastoreFederationClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1453,7 +1457,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1479,8 +1483,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1489,7 +1497,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1498,7 +1506,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1512,7 +1520,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1538,8 +1546,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1548,7 +1560,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1557,7 +1569,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1571,7 +1583,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1601,8 +1613,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1611,7 +1627,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1619,7 +1635,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1627,7 +1643,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1656,8 +1672,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1666,7 +1686,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1674,7 +1694,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1682,7 +1702,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1774,8 +1794,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1784,7 +1808,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1793,7 +1819,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1807,7 +1833,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1900,8 +1926,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1910,7 +1940,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1919,7 +1951,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1933,7 +1965,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1964,8 +1996,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1974,7 +2010,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1983,7 +2021,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1997,7 +2035,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2023,8 +2061,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2033,7 +2075,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2042,7 +2084,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2056,7 +2098,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2082,8 +2124,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2092,7 +2138,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2101,7 +2147,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/README.rst b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/README.rst index 8357671575ad..79344594c8e1 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/README.rst +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataprocMetastoreFederationTransport` is the ABC for all transports. -- public child `DataprocMetastoreFederationGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataprocMetastoreFederationGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataprocMetastoreFederationRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataprocMetastoreFederationRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataprocMetastoreFederationTransport`` is the ABC for all transports. + +- public child ``DataprocMetastoreFederationGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataprocMetastoreFederationGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataprocMetastoreFederationRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataprocMetastoreFederationRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py index 8acf823c7ea4..010ae0d70e04 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py index 71c700946e24..8e5ce9a60573 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -204,6 +204,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py index 45dcc82eac70..bbf1b52a559d 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -257,6 +257,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py index b205bd4c8e79..adb8d148102e 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py @@ -675,6 +675,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataprocMetastoreFederationRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py index 44fe6fca8ddf..082136daaf72 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py @@ -231,7 +231,7 @@ def transport(self) -> DataprocMetastoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2744,7 +2744,7 @@ async def sample_alter_metadata_resource_location(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2770,8 +2770,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2780,7 +2784,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2788,7 +2792,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2799,7 +2803,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2825,8 +2829,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2835,7 +2843,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2843,7 +2851,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2854,7 +2862,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2884,8 +2892,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2894,7 +2906,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2902,7 +2914,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2910,7 +2922,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2939,8 +2951,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2949,7 +2965,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2957,7 +2973,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2965,7 +2981,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3057,8 +3073,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3067,7 +3087,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3075,7 +3097,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3086,7 +3108,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3179,8 +3201,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3189,7 +3215,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3197,7 +3225,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3208,7 +3236,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3239,8 +3267,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3251,7 +3283,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3259,7 +3293,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3270,7 +3304,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3296,8 +3330,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3306,7 +3344,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3314,7 +3352,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3325,7 +3363,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3351,8 +3389,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3361,7 +3403,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3369,7 +3411,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py index 7f0c18145aaf..8bd6f722af30 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py @@ -143,7 +143,7 @@ class DataprocMetastoreClient(metaclass=DataprocMetastoreClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -151,7 +151,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -161,6 +161,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -579,7 +583,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -676,7 +680,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -776,7 +780,7 @@ def __init__( self._universe_domain = DataprocMetastoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3237,7 +3241,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3263,8 +3267,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3273,7 +3281,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3282,7 +3290,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3296,7 +3304,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3322,8 +3330,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3332,7 +3344,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3341,7 +3353,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3355,7 +3367,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3385,8 +3397,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3395,7 +3411,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3403,7 +3419,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3411,7 +3427,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3440,8 +3456,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3450,7 +3470,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3458,7 +3478,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3466,7 +3486,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3558,8 +3578,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3568,7 +3592,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3577,7 +3603,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3591,7 +3617,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3684,8 +3710,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3694,7 +3724,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3703,7 +3735,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3717,7 +3749,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3748,8 +3780,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3758,7 +3794,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3767,7 +3805,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3781,7 +3819,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3807,8 +3845,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3817,7 +3859,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3826,7 +3868,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3840,7 +3882,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3866,8 +3908,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3876,7 +3922,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3885,7 +3931,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/README.rst b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/README.rst index 1b6900a36bc0..2229a9da48af 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/README.rst +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataprocMetastoreTransport` is the ABC for all transports. -- public child `DataprocMetastoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataprocMetastoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataprocMetastoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataprocMetastoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataprocMetastoreTransport`` is the ABC for all transports. + +- public child ``DataprocMetastoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataprocMetastoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataprocMetastoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataprocMetastoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py index 32c9dfcf3ab0..706f64b3c0d2 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py index 3368cd2f40a9..f302d431971c 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -210,6 +210,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py index 7a0962a9e16a..d8015b3603bb 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -261,6 +261,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py index 134dda44ebc4..d49b7c2bbc08 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py @@ -1434,6 +1434,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataprocMetastoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py index 415f85a4ca0f..3f431f001a11 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> DataprocMetastoreFederationTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1028,7 +1028,7 @@ async def sample_delete_federation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1054,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1068,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1072,7 +1076,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1083,7 +1087,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1109,8 +1113,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1119,7 +1127,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1127,7 +1135,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1138,7 +1146,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1168,8 +1176,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1178,7 +1190,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1186,7 +1198,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1194,7 +1206,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1223,8 +1235,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1233,7 +1249,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1241,7 +1257,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1249,7 +1265,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1341,8 +1357,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1351,7 +1371,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1359,7 +1381,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1370,7 +1392,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1463,8 +1485,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1473,7 +1499,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1481,7 +1509,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1492,7 +1520,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1523,8 +1551,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1535,7 +1567,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1543,7 +1577,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1554,7 +1588,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1580,8 +1614,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1590,7 +1628,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1598,7 +1636,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1609,7 +1647,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1635,8 +1673,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1645,7 +1687,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1653,7 +1695,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py index 40b6991c83b4..917596ac9ec3 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py @@ -141,7 +141,7 @@ class DataprocMetastoreFederationClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -149,7 +149,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -159,6 +159,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = DataprocMetastoreFederationClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1453,7 +1457,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1479,8 +1483,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1489,7 +1497,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1498,7 +1506,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1512,7 +1520,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1538,8 +1546,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1548,7 +1560,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1557,7 +1569,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1571,7 +1583,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1601,8 +1613,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1611,7 +1627,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1619,7 +1635,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1627,7 +1643,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1656,8 +1672,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1666,7 +1686,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1674,7 +1694,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1682,7 +1702,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1774,8 +1794,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1784,7 +1808,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1793,7 +1819,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1807,7 +1833,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1900,8 +1926,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1910,7 +1940,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1919,7 +1951,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1933,7 +1965,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1964,8 +1996,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1974,7 +2010,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1983,7 +2021,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1997,7 +2035,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2023,8 +2061,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2033,7 +2075,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2042,7 +2084,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2056,7 +2098,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2082,8 +2124,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2092,7 +2138,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2101,7 +2147,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/README.rst b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/README.rst index 8357671575ad..79344594c8e1 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/README.rst +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataprocMetastoreFederationTransport` is the ABC for all transports. -- public child `DataprocMetastoreFederationGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataprocMetastoreFederationGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataprocMetastoreFederationRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataprocMetastoreFederationRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataprocMetastoreFederationTransport`` is the ABC for all transports. + +- public child ``DataprocMetastoreFederationGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataprocMetastoreFederationGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataprocMetastoreFederationRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataprocMetastoreFederationRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py index e29a3dbb262a..b1fd953a5e05 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py index 29f61cb992fc..4560e3371b7d 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -204,6 +204,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py index 788f2983ef59..1b1552b62154 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -257,6 +257,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py index 36d9e1d163dd..f1c0a0a0bf9d 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py @@ -675,6 +675,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataprocMetastoreFederationRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py index c1d35dbf42a8..791bec543a91 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py @@ -231,7 +231,7 @@ def transport(self) -> DataprocMetastoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2744,7 +2744,7 @@ async def sample_alter_metadata_resource_location(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2770,8 +2770,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2780,7 +2784,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2788,7 +2792,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2799,7 +2803,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2825,8 +2829,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2835,7 +2843,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2843,7 +2851,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2854,7 +2862,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2884,8 +2892,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2894,7 +2906,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2902,7 +2914,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2910,7 +2922,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2939,8 +2951,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2949,7 +2965,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2957,7 +2973,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2965,7 +2981,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3057,8 +3073,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3067,7 +3087,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3075,7 +3097,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3086,7 +3108,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3179,8 +3201,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3189,7 +3215,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3197,7 +3225,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3208,7 +3236,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3239,8 +3267,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3251,7 +3283,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3259,7 +3293,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3270,7 +3304,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3296,8 +3330,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3306,7 +3344,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3314,7 +3352,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3325,7 +3363,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3351,8 +3389,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3361,7 +3403,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3369,7 +3411,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py index aa629ac22e3d..e3100ba48ed4 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py @@ -143,7 +143,7 @@ class DataprocMetastoreClient(metaclass=DataprocMetastoreClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -151,7 +151,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -161,6 +161,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -579,7 +583,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -676,7 +680,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -776,7 +780,7 @@ def __init__( self._universe_domain = DataprocMetastoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3237,7 +3241,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3263,8 +3267,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3273,7 +3281,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3282,7 +3290,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3296,7 +3304,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3322,8 +3330,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3332,7 +3344,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3341,7 +3353,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3355,7 +3367,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3385,8 +3397,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3395,7 +3411,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3403,7 +3419,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3411,7 +3427,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3440,8 +3456,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3450,7 +3470,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3458,7 +3478,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3466,7 +3486,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3558,8 +3578,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3568,7 +3592,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3577,7 +3603,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3591,7 +3617,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3684,8 +3710,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3694,7 +3724,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3703,7 +3735,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3717,7 +3749,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3748,8 +3780,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3758,7 +3794,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3767,7 +3805,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3781,7 +3819,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3807,8 +3845,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3817,7 +3859,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3826,7 +3868,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3840,7 +3882,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3866,8 +3908,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3876,7 +3922,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3885,7 +3931,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/README.rst b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/README.rst index 1b6900a36bc0..2229a9da48af 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/README.rst +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataprocMetastoreTransport` is the ABC for all transports. -- public child `DataprocMetastoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataprocMetastoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataprocMetastoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataprocMetastoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataprocMetastoreTransport`` is the ABC for all transports. + +- public child ``DataprocMetastoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataprocMetastoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataprocMetastoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataprocMetastoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py index a206821ff5c2..2b55ebb5635f 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py index 379d926ae92b..7514e5d8fb28 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -210,6 +210,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py index 1fb268343233..98ad5d0ef6cb 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -261,6 +261,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py index e900dfbb5a77..19d018888ede 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py @@ -1434,6 +1434,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataprocMetastoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py index 1f623442b6f4..87f751deb4bd 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> DataprocMetastoreFederationTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1028,7 +1028,7 @@ async def sample_delete_federation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1054,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1068,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1072,7 +1076,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1083,7 +1087,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1109,8 +1113,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1119,7 +1127,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1127,7 +1135,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1138,7 +1146,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1168,8 +1176,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1178,7 +1190,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1186,7 +1198,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1194,7 +1206,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1223,8 +1235,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1233,7 +1249,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1241,7 +1257,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1249,7 +1265,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1341,8 +1357,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1351,7 +1371,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1359,7 +1381,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1370,7 +1392,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1463,8 +1485,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1473,7 +1499,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1481,7 +1509,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1492,7 +1520,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1523,8 +1551,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1535,7 +1567,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1543,7 +1577,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1554,7 +1588,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1580,8 +1614,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1590,7 +1628,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1598,7 +1636,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1609,7 +1647,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1635,8 +1673,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1645,7 +1687,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1653,7 +1695,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py index 7cb7620ef4fc..1cb678c5b9f6 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py @@ -141,7 +141,7 @@ class DataprocMetastoreFederationClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -149,7 +149,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -159,6 +159,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = DataprocMetastoreFederationClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1453,7 +1457,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1479,8 +1483,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1489,7 +1497,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1498,7 +1506,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1512,7 +1520,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1538,8 +1546,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1548,7 +1560,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1557,7 +1569,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1571,7 +1583,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1601,8 +1613,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1611,7 +1627,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1619,7 +1635,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1627,7 +1643,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1656,8 +1672,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1666,7 +1686,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1674,7 +1694,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1682,7 +1702,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1774,8 +1794,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1784,7 +1808,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1793,7 +1819,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1807,7 +1833,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1900,8 +1926,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1910,7 +1940,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1919,7 +1951,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1933,7 +1965,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1964,8 +1996,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1974,7 +2010,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1983,7 +2021,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1997,7 +2035,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2023,8 +2061,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2033,7 +2075,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2042,7 +2084,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2056,7 +2098,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2082,8 +2124,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2092,7 +2138,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2101,7 +2147,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/README.rst b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/README.rst index 8357671575ad..79344594c8e1 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/README.rst +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataprocMetastoreFederationTransport` is the ABC for all transports. -- public child `DataprocMetastoreFederationGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataprocMetastoreFederationGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataprocMetastoreFederationRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataprocMetastoreFederationRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataprocMetastoreFederationTransport`` is the ABC for all transports. + +- public child ``DataprocMetastoreFederationGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataprocMetastoreFederationGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataprocMetastoreFederationRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataprocMetastoreFederationRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py index 36c51953666a..b3bd570277f2 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py index 7dbbc57367ff..299c8e19886c 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -204,6 +204,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py index e9cc5edaba42..9117c5de3a59 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -257,6 +257,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py index 6223af7e6dba..9f589c3e61f5 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py @@ -675,6 +675,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataprocMetastoreFederationRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc-metastore/noxfile.py b/packages/google-cloud-dataproc-metastore/noxfile.py index e1d9a2786e61..7716b985c626 100644 --- a/packages/google-cloud-dataproc-metastore/noxfile.py +++ b/packages/google-cloud-dataproc-metastore/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dataproc-metastore/setup.py b/packages/google-cloud-dataproc-metastore/setup.py index 8fcf4f5be8d5..009790f78b95 100644 --- a/packages/google-cloud-dataproc-metastore/setup.py +++ b/packages/google-cloud-dataproc-metastore/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dataproc-metastore/testing/constraints-3.7.txt b/packages/google-cloud-dataproc-metastore/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-dataproc-metastore/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataproc-metastore/testing/constraints-3.8.txt b/packages/google-cloud-dataproc-metastore/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-dataproc-metastore/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-dataproc-metastore/testing/constraints-3.9.txt b/packages/google-cloud-dataproc-metastore/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-dataproc-metastore/testing/constraints-3.9.txt +++ b/packages/google-cloud-dataproc-metastore/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py index 5f5888fb3b1c..800a8c82923f 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataprocMetastoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataprocMetastoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataprocMetastoreClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1335,11 +1340,13 @@ def test_dataproc_metastore_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12413,8 +12420,9 @@ def test_list_services_rest_bad_request(request_type=metastore.ListServicesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12479,17 +12487,20 @@ def test_list_services_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_services" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_services" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_services_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_services" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12540,8 +12551,9 @@ def test_get_service_rest_bad_request(request_type=metastore.GetServiceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12624,17 +12636,20 @@ def test_get_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_get_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12683,8 +12698,9 @@ def test_create_service_rest_bad_request(request_type=metastore.CreateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12869,19 +12885,21 @@ def test_create_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12932,8 +12950,9 @@ def test_update_service_rest_bad_request(request_type=metastore.UpdateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13120,19 +13139,21 @@ def test_update_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_update_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_update_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_update_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_update_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13181,8 +13202,9 @@ def test_delete_service_rest_bad_request(request_type=metastore.DeleteServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13239,19 +13261,21 @@ def test_delete_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_delete_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_delete_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_delete_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_delete_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13302,8 +13326,9 @@ def test_list_metadata_imports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13368,18 +13393,20 @@ def test_list_metadata_imports_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_metadata_imports" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_list_metadata_imports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_metadata_imports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_metadata_imports" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_metadata_imports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_metadata_imports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13439,8 +13466,9 @@ def test_get_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13509,18 +13537,20 @@ def test_get_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_get_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_get_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13573,8 +13603,9 @@ def test_create_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13712,20 +13743,21 @@ def test_create_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_create_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13782,8 +13814,9 @@ def test_update_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13925,20 +13958,21 @@ def test_update_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_update_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_update_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_update_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_update_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_update_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13989,8 +14023,9 @@ def test_export_metadata_rest_bad_request(request_type=metastore.ExportMetadataR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14047,20 +14082,21 @@ def test_export_metadata_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_export_metadata" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_export_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_export_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_export_metadata" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_export_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_export_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14111,8 +14147,9 @@ def test_restore_service_rest_bad_request(request_type=metastore.RestoreServiceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14169,20 +14206,21 @@ def test_restore_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_restore_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_restore_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_restore_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_restore_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_restore_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_restore_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14233,8 +14271,9 @@ def test_list_backups_rest_bad_request(request_type=metastore.ListBackupsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14299,17 +14338,20 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_backups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14362,8 +14404,9 @@ def test_get_backup_rest_bad_request(request_type=metastore.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14434,17 +14477,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14493,8 +14538,9 @@ def test_create_backup_rest_bad_request(request_type=metastore.CreateBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14690,19 +14736,21 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14753,8 +14801,9 @@ def test_delete_backup_rest_bad_request(request_type=metastore.DeleteBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14813,19 +14862,21 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_delete_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14874,8 +14925,9 @@ def test_query_metadata_rest_bad_request(request_type=metastore.QueryMetadataReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14932,19 +14984,21 @@ def test_query_metadata_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_query_metadata" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_query_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_query_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_query_metadata" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_query_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_query_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14995,8 +15049,9 @@ def test_move_table_to_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15053,20 +15108,21 @@ def test_move_table_to_database_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_move_table_to_database" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_move_table_to_database_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_move_table_to_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_move_table_to_database" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_move_table_to_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_move_table_to_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15119,8 +15175,9 @@ def test_alter_metadata_resource_location_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15177,22 +15234,23 @@ def test_alter_metadata_resource_location_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_alter_metadata_resource_location", - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_alter_metadata_resource_location_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "pre_alter_metadata_resource_location", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_alter_metadata_resource_location", + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_alter_metadata_resource_location_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "pre_alter_metadata_resource_location", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15245,8 +15303,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15305,8 +15364,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15367,8 +15427,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15429,8 +15490,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15491,8 +15553,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15553,8 +15616,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15615,8 +15679,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15677,8 +15742,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15739,8 +15805,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16268,11 +16335,14 @@ def test_dataproc_metastore_base_transport(): def test_dataproc_metastore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.metastore_v1.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.metastore_v1.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreTransport( @@ -16289,9 +16359,12 @@ def test_dataproc_metastore_base_transport_with_credentials_file(): def test_dataproc_metastore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.metastore_v1.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.metastore_v1.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreTransport() @@ -16363,11 +16436,12 @@ def test_dataproc_metastore_transport_auth_gdch_credentials(transport_class): def test_dataproc_metastore_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -17124,6 +17198,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17263,6 +17369,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17408,6 +17546,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17553,6 +17725,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17698,6 +17904,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17839,6 +18079,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18003,6 +18277,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataprocMetastoreClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18170,6 +18479,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataprocMetastoreClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18347,6 +18691,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataprocMetastoreClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py index 95a47674c454..c41e4a8ffaeb 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataprocMetastoreFederationClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataprocMetastoreFederationClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataprocMetastoreFederationClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1398,11 +1403,13 @@ def test_dataproc_metastore_federation_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4800,8 +4807,9 @@ def test_list_federations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,18 +4874,22 @@ def test_list_federations_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_list_federations" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_list_federations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_list_federations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_list_federations", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_list_federations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_list_federations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4935,8 +4947,9 @@ def test_get_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5009,18 +5022,20 @@ def test_get_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_get_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_get_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_get_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, "post_get_federation" + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_get_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, "pre_get_federation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5075,8 +5090,9 @@ def test_create_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5212,20 +5228,23 @@ def test_create_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_create_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_create_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_create_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_create_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_create_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_create_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5280,8 +5299,9 @@ def test_update_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5419,20 +5439,23 @@ def test_update_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_update_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_update_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_update_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_update_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_update_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_update_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5485,8 +5508,9 @@ def test_delete_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5543,20 +5567,23 @@ def test_delete_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_delete_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_delete_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_delete_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_delete_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_delete_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_delete_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5609,8 +5636,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5669,8 +5697,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5731,8 +5760,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5793,8 +5823,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5855,8 +5886,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5917,8 +5949,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5979,8 +6012,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6041,8 +6075,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6103,8 +6138,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6353,11 +6389,14 @@ def test_dataproc_metastore_federation_base_transport(): def test_dataproc_metastore_federation_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.metastore_v1.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.metastore_v1.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreFederationTransport( @@ -6374,9 +6413,12 @@ def test_dataproc_metastore_federation_base_transport_with_credentials_file(): def test_dataproc_metastore_federation_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.metastore_v1.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.metastore_v1.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreFederationTransport() @@ -6453,11 +6495,12 @@ def test_dataproc_metastore_federation_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7076,6 +7119,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7215,6 +7290,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7360,6 +7467,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7505,6 +7646,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7650,6 +7825,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7795,6 +8004,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7959,6 +8202,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataprocMetastoreFederationClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8126,6 +8404,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataprocMetastoreFederationClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8303,6 +8616,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataprocMetastoreFederationClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py index bea03a50eed7..508664488400 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataprocMetastoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataprocMetastoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataprocMetastoreClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1335,11 +1340,13 @@ def test_dataproc_metastore_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12845,8 +12852,9 @@ def test_list_services_rest_bad_request(request_type=metastore.ListServicesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12911,17 +12919,20 @@ def test_list_services_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_services" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_services" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_services_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_services" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12972,8 +12983,9 @@ def test_get_service_rest_bad_request(request_type=metastore.GetServiceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13056,17 +13068,20 @@ def test_get_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_get_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13115,8 +13130,9 @@ def test_create_service_rest_bad_request(request_type=metastore.CreateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13306,19 +13322,21 @@ def test_create_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13369,8 +13387,9 @@ def test_update_service_rest_bad_request(request_type=metastore.UpdateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13562,19 +13581,21 @@ def test_update_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_update_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_update_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_update_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_update_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13623,8 +13644,9 @@ def test_delete_service_rest_bad_request(request_type=metastore.DeleteServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13681,19 +13703,21 @@ def test_delete_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_delete_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_delete_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_delete_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_delete_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13744,8 +13768,9 @@ def test_list_metadata_imports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13810,18 +13835,20 @@ def test_list_metadata_imports_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_metadata_imports" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_list_metadata_imports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_metadata_imports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_metadata_imports" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_metadata_imports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_metadata_imports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13881,8 +13908,9 @@ def test_get_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13951,18 +13979,20 @@ def test_get_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_get_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_get_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14015,8 +14045,9 @@ def test_create_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14154,20 +14185,21 @@ def test_create_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_create_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14224,8 +14256,9 @@ def test_update_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14367,20 +14400,21 @@ def test_update_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_update_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_update_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_update_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_update_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_update_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14431,8 +14465,9 @@ def test_export_metadata_rest_bad_request(request_type=metastore.ExportMetadataR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14489,20 +14524,21 @@ def test_export_metadata_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_export_metadata" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_export_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_export_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_export_metadata" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_export_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_export_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14553,8 +14589,9 @@ def test_restore_service_rest_bad_request(request_type=metastore.RestoreServiceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14611,20 +14648,21 @@ def test_restore_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_restore_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_restore_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_restore_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_restore_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_restore_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_restore_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14675,8 +14713,9 @@ def test_list_backups_rest_bad_request(request_type=metastore.ListBackupsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14741,17 +14780,20 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_backups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14804,8 +14846,9 @@ def test_get_backup_rest_bad_request(request_type=metastore.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14876,17 +14919,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14935,8 +14980,9 @@ def test_create_backup_rest_bad_request(request_type=metastore.CreateBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15137,19 +15183,21 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15200,8 +15248,9 @@ def test_delete_backup_rest_bad_request(request_type=metastore.DeleteBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15260,19 +15309,21 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_delete_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15325,8 +15376,9 @@ def test_remove_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15391,18 +15443,20 @@ def test_remove_iam_policy_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_remove_iam_policy" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_remove_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_remove_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_remove_iam_policy" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_remove_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_remove_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15455,8 +15509,9 @@ def test_query_metadata_rest_bad_request(request_type=metastore.QueryMetadataReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15513,19 +15568,21 @@ def test_query_metadata_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_query_metadata" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_query_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_query_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_query_metadata" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_query_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_query_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15576,8 +15633,9 @@ def test_move_table_to_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15634,20 +15692,21 @@ def test_move_table_to_database_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_move_table_to_database" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_move_table_to_database_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_move_table_to_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_move_table_to_database" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_move_table_to_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_move_table_to_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15700,8 +15759,9 @@ def test_alter_metadata_resource_location_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15758,22 +15818,23 @@ def test_alter_metadata_resource_location_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_alter_metadata_resource_location", - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_alter_metadata_resource_location_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "pre_alter_metadata_resource_location", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_alter_metadata_resource_location", + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_alter_metadata_resource_location_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "pre_alter_metadata_resource_location", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15826,8 +15887,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15886,8 +15948,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15948,8 +16011,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16010,8 +16074,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16072,8 +16137,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16134,8 +16200,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16196,8 +16263,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16258,8 +16326,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16320,8 +16389,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16872,11 +16942,14 @@ def test_dataproc_metastore_base_transport(): def test_dataproc_metastore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.metastore_v1alpha.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.metastore_v1alpha.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreTransport( @@ -16893,9 +16966,12 @@ def test_dataproc_metastore_base_transport_with_credentials_file(): def test_dataproc_metastore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.metastore_v1alpha.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.metastore_v1alpha.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreTransport() @@ -16967,11 +17043,12 @@ def test_dataproc_metastore_transport_auth_gdch_credentials(transport_class): def test_dataproc_metastore_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -17757,6 +17834,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17896,6 +18005,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18041,6 +18182,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18186,6 +18361,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18331,6 +18540,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18472,6 +18715,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18636,6 +18913,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataprocMetastoreClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18803,6 +19115,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataprocMetastoreClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18980,6 +19327,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataprocMetastoreClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py index d3042e3d22a5..2bd84185a407 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataprocMetastoreFederationClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataprocMetastoreFederationClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataprocMetastoreFederationClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1398,11 +1403,13 @@ def test_dataproc_metastore_federation_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4800,8 +4807,9 @@ def test_list_federations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,18 +4874,22 @@ def test_list_federations_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_list_federations" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_list_federations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_list_federations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_list_federations", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_list_federations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_list_federations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4935,8 +4947,9 @@ def test_get_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5009,18 +5022,20 @@ def test_get_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_get_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_get_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_get_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, "post_get_federation" + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_get_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, "pre_get_federation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5075,8 +5090,9 @@ def test_create_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5212,20 +5228,23 @@ def test_create_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_create_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_create_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_create_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_create_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_create_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_create_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5280,8 +5299,9 @@ def test_update_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5419,20 +5439,23 @@ def test_update_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_update_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_update_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_update_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_update_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_update_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_update_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5485,8 +5508,9 @@ def test_delete_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5543,20 +5567,23 @@ def test_delete_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_delete_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_delete_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_delete_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_delete_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_delete_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_delete_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5609,8 +5636,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5669,8 +5697,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5731,8 +5760,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5793,8 +5823,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5855,8 +5886,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5917,8 +5949,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5979,8 +6012,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6041,8 +6075,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6103,8 +6138,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6353,11 +6389,14 @@ def test_dataproc_metastore_federation_base_transport(): def test_dataproc_metastore_federation_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.metastore_v1alpha.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.metastore_v1alpha.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreFederationTransport( @@ -6374,9 +6413,12 @@ def test_dataproc_metastore_federation_base_transport_with_credentials_file(): def test_dataproc_metastore_federation_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.metastore_v1alpha.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.metastore_v1alpha.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreFederationTransport() @@ -6453,11 +6495,12 @@ def test_dataproc_metastore_federation_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7076,6 +7119,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7215,6 +7290,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7360,6 +7467,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7505,6 +7646,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7650,6 +7825,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7795,6 +8004,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7959,6 +8202,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataprocMetastoreFederationClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8126,6 +8404,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataprocMetastoreFederationClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8303,6 +8616,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataprocMetastoreFederationClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py index 6084f6095fd8..b1505647c5fb 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataprocMetastoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataprocMetastoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataprocMetastoreClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1335,11 +1340,13 @@ def test_dataproc_metastore_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12845,8 +12852,9 @@ def test_list_services_rest_bad_request(request_type=metastore.ListServicesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12911,17 +12919,20 @@ def test_list_services_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_services" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_services_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_services" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_services" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_services_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_services" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12972,8 +12983,9 @@ def test_get_service_rest_bad_request(request_type=metastore.GetServiceRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13056,17 +13068,20 @@ def test_get_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_get_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13115,8 +13130,9 @@ def test_create_service_rest_bad_request(request_type=metastore.CreateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13306,19 +13322,21 @@ def test_create_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13369,8 +13387,9 @@ def test_update_service_rest_bad_request(request_type=metastore.UpdateServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13562,19 +13581,21 @@ def test_update_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_update_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_update_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_update_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_update_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13623,8 +13644,9 @@ def test_delete_service_rest_bad_request(request_type=metastore.DeleteServiceReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13681,19 +13703,21 @@ def test_delete_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_service_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_delete_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_delete_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_delete_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_delete_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13744,8 +13768,9 @@ def test_list_metadata_imports_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13810,18 +13835,20 @@ def test_list_metadata_imports_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_metadata_imports" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_list_metadata_imports_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_metadata_imports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_metadata_imports" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_metadata_imports_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_metadata_imports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13881,8 +13908,9 @@ def test_get_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13951,18 +13979,20 @@ def test_get_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_get_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_get_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14015,8 +14045,9 @@ def test_create_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14154,20 +14185,21 @@ def test_create_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_create_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14224,8 +14256,9 @@ def test_update_metadata_import_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14367,20 +14400,21 @@ def test_update_metadata_import_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_update_metadata_import" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_update_metadata_import_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_update_metadata_import" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_update_metadata_import" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_update_metadata_import_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_update_metadata_import" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14431,8 +14465,9 @@ def test_export_metadata_rest_bad_request(request_type=metastore.ExportMetadataR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14489,20 +14524,21 @@ def test_export_metadata_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_export_metadata" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_export_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_export_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_export_metadata" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_export_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_export_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14553,8 +14589,9 @@ def test_restore_service_rest_bad_request(request_type=metastore.RestoreServiceR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14611,20 +14648,21 @@ def test_restore_service_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_restore_service" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_restore_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_restore_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_restore_service" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_restore_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_restore_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14675,8 +14713,9 @@ def test_list_backups_rest_bad_request(request_type=metastore.ListBackupsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14741,17 +14780,20 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_list_backups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14804,8 +14846,9 @@ def test_get_backup_rest_bad_request(request_type=metastore.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14876,17 +14919,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14935,8 +14980,9 @@ def test_create_backup_rest_bad_request(request_type=metastore.CreateBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15137,19 +15183,21 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_create_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15200,8 +15248,9 @@ def test_delete_backup_rest_bad_request(request_type=metastore.DeleteBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15260,19 +15309,21 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_delete_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15325,8 +15376,9 @@ def test_remove_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15391,18 +15443,20 @@ def test_remove_iam_policy_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_remove_iam_policy" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_remove_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_remove_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_remove_iam_policy" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_remove_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_remove_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15455,8 +15509,9 @@ def test_query_metadata_rest_bad_request(request_type=metastore.QueryMetadataReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15513,19 +15568,21 @@ def test_query_metadata_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_query_metadata" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_query_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_query_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_query_metadata" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_query_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_query_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15576,8 +15633,9 @@ def test_move_table_to_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15634,20 +15692,21 @@ def test_move_table_to_database_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "post_move_table_to_database" - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_move_table_to_database_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, "pre_move_table_to_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "post_move_table_to_database" + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_move_table_to_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, "pre_move_table_to_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15700,8 +15759,9 @@ def test_alter_metadata_resource_location_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15758,22 +15818,23 @@ def test_alter_metadata_resource_location_rest_interceptors(null_interceptor): ) client = DataprocMetastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_alter_metadata_resource_location", - ) as post, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "post_alter_metadata_resource_location_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreRestInterceptor, - "pre_alter_metadata_resource_location", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_alter_metadata_resource_location", + ) as post, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "post_alter_metadata_resource_location_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreRestInterceptor, + "pre_alter_metadata_resource_location", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15826,8 +15887,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15886,8 +15948,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15948,8 +16011,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16010,8 +16074,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16072,8 +16137,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16134,8 +16200,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16196,8 +16263,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16258,8 +16326,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16320,8 +16389,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16872,11 +16942,14 @@ def test_dataproc_metastore_base_transport(): def test_dataproc_metastore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.metastore_v1beta.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.metastore_v1beta.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreTransport( @@ -16893,9 +16966,12 @@ def test_dataproc_metastore_base_transport_with_credentials_file(): def test_dataproc_metastore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.metastore_v1beta.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.metastore_v1beta.services.dataproc_metastore.transports.DataprocMetastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreTransport() @@ -16967,11 +17043,12 @@ def test_dataproc_metastore_transport_auth_gdch_credentials(transport_class): def test_dataproc_metastore_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -17757,6 +17834,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17896,6 +18005,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18041,6 +18182,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18186,6 +18361,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18331,6 +18540,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18472,6 +18715,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18636,6 +18913,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataprocMetastoreClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18803,6 +19115,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataprocMetastoreClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18980,6 +19327,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataprocMetastoreClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataprocMetastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py index f3231f05d097..5def842b4c21 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataprocMetastoreFederationClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataprocMetastoreFederationClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataprocMetastoreFederationClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1398,11 +1403,13 @@ def test_dataproc_metastore_federation_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4800,8 +4807,9 @@ def test_list_federations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,18 +4874,22 @@ def test_list_federations_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_list_federations" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_list_federations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_list_federations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_list_federations", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_list_federations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_list_federations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4935,8 +4947,9 @@ def test_get_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5009,18 +5022,20 @@ def test_get_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_get_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_get_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_get_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, "post_get_federation" + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_get_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, "pre_get_federation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5075,8 +5090,9 @@ def test_create_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5212,20 +5228,23 @@ def test_create_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_create_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_create_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_create_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_create_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_create_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_create_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5280,8 +5299,9 @@ def test_update_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5419,20 +5439,23 @@ def test_update_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_update_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_update_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_update_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_update_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_update_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_update_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5485,8 +5508,9 @@ def test_delete_federation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5543,20 +5567,23 @@ def test_delete_federation_rest_interceptors(null_interceptor): ) client = DataprocMetastoreFederationClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "post_delete_federation" - ) as post, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, - "post_delete_federation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataprocMetastoreFederationRestInterceptor, "pre_delete_federation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_delete_federation", + ) as post, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "post_delete_federation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataprocMetastoreFederationRestInterceptor, + "pre_delete_federation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5609,8 +5636,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5669,8 +5697,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5731,8 +5760,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5793,8 +5823,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5855,8 +5886,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5917,8 +5949,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5979,8 +6012,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6041,8 +6075,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6103,8 +6138,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6353,11 +6389,14 @@ def test_dataproc_metastore_federation_base_transport(): def test_dataproc_metastore_federation_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.metastore_v1beta.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.metastore_v1beta.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreFederationTransport( @@ -6374,9 +6413,12 @@ def test_dataproc_metastore_federation_base_transport_with_credentials_file(): def test_dataproc_metastore_federation_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.metastore_v1beta.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.metastore_v1beta.services.dataproc_metastore_federation.transports.DataprocMetastoreFederationTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataprocMetastoreFederationTransport() @@ -6453,11 +6495,12 @@ def test_dataproc_metastore_federation_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7076,6 +7119,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7215,6 +7290,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7360,6 +7467,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7505,6 +7646,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7650,6 +7825,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7795,6 +8004,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7959,6 +8202,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataprocMetastoreFederationClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8126,6 +8404,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataprocMetastoreFederationClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8303,6 +8616,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataprocMetastoreFederationClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/async_client.py index b38c74c73790..bf82a11fc54e 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> AutoscalingPolicyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -958,7 +958,7 @@ async def sample_delete_autoscaling_policy(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -984,8 +984,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -994,7 +998,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1002,7 +1006,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1013,7 +1017,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,8 +1043,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1049,7 +1057,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1057,7 +1065,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1068,7 +1076,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1098,8 +1106,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1108,7 +1120,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1116,7 +1128,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1136,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1153,8 +1165,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,7 +1179,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1171,7 +1187,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1179,7 +1195,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1271,8 +1287,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1281,7 +1301,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1289,7 +1311,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1300,7 +1322,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1393,8 +1415,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,7 +1429,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1411,7 +1439,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1422,7 +1450,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1453,8 +1481,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1465,7 +1497,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1473,7 +1507,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/client.py index 97c91cd6c697..316764f3d150 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/client.py @@ -117,7 +117,7 @@ class AutoscalingPolicyServiceClient(metaclass=AutoscalingPolicyServiceClientMet """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = AutoscalingPolicyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1385,7 +1389,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1411,8 +1415,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1421,7 +1429,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1430,7 +1438,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1444,7 +1452,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1470,8 +1478,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1480,7 +1492,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1489,7 +1501,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1503,7 +1515,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1533,8 +1545,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1543,7 +1559,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1551,7 +1567,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1559,7 +1575,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1588,8 +1604,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1598,7 +1618,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1606,7 +1626,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1614,7 +1634,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1706,8 +1726,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1716,7 +1740,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1725,7 +1751,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1739,7 +1765,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1832,8 +1858,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1842,7 +1872,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1851,7 +1883,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1865,7 +1897,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1896,8 +1928,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1906,7 +1942,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1915,7 +1953,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/README.rst index d9124e38937c..837ae91b176c 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutoscalingPolicyServiceTransport` is the ABC for all transports. -- public child `AutoscalingPolicyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutoscalingPolicyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutoscalingPolicyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutoscalingPolicyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutoscalingPolicyServiceTransport`` is the ABC for all transports. + +- public child ``AutoscalingPolicyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutoscalingPolicyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutoscalingPolicyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutoscalingPolicyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/base.py index 209a98a0c209..da5aa427e9db 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc.py index f64ce3ed126f..743b18ac2643 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc_asyncio.py index 81c0a9a31789..c1861e9a339f 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/rest.py index c8a42fe6e30c..a85254892c58 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/autoscaling_policy_service/transports/rest.py @@ -576,6 +576,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutoscalingPolicyServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/async_client.py index 8f5656126b44..2ad11f55a770 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> BatchControllerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -800,7 +800,7 @@ async def sample_delete_batch(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -826,8 +826,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -836,7 +840,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -844,7 +848,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -855,7 +859,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -881,8 +885,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -891,7 +899,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -899,7 +907,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -910,7 +918,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -940,8 +948,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -950,7 +962,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -958,7 +970,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -966,7 +978,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -995,8 +1007,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1005,7 +1021,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1013,7 +1029,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1021,7 +1037,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1113,8 +1129,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1123,7 +1143,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1131,7 +1153,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1142,7 +1164,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1235,8 +1257,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1245,7 +1271,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1253,7 +1281,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1264,7 +1292,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1295,8 +1323,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1307,7 +1339,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1315,7 +1349,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/client.py index 293f8dc2b2e1..25136e60f249 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/client.py @@ -120,7 +120,7 @@ class BatchControllerClient(metaclass=BatchControllerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = BatchControllerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1251,7 +1255,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1277,8 +1281,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1287,7 +1295,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1296,7 +1304,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1310,7 +1318,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1336,8 +1344,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1346,7 +1358,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1355,7 +1367,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1369,7 +1381,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1399,8 +1411,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1409,7 +1425,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1417,7 +1433,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1425,7 +1441,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1454,8 +1470,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1464,7 +1484,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1472,7 +1492,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1480,7 +1500,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1572,8 +1592,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1582,7 +1606,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1591,7 +1617,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1605,7 +1631,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1698,8 +1724,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1708,7 +1738,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1717,7 +1749,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1731,7 +1763,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1762,8 +1794,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1772,7 +1808,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1781,7 +1819,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/README.rst index c993561f2056..d49b2474fde1 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BatchControllerTransport` is the ABC for all transports. -- public child `BatchControllerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BatchControllerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBatchControllerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BatchControllerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BatchControllerTransport`` is the ABC for all transports. + +- public child ``BatchControllerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BatchControllerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBatchControllerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BatchControllerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/base.py index bab0fe070ea6..2c487fbcf49c 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc.py index d46b0378ff4a..e714f7bccdbe 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc_asyncio.py index 4d4756ce21b7..012d3dcf0a64 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/rest.py index 3eb2db76c28f..68e723afc866 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/batch_controller/transports/rest.py @@ -494,6 +494,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BatchControllerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/async_client.py index bc9deb78586a..456eeb3bdc68 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> ClusterControllerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1566,7 +1566,7 @@ async def sample_diagnose_cluster(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1592,8 +1592,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1602,7 +1606,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1610,7 +1614,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1621,7 +1625,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1647,8 +1651,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1657,7 +1665,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1665,7 +1673,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1676,7 +1684,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1706,8 +1714,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1716,7 +1728,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1724,7 +1736,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1732,7 +1744,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1761,8 +1773,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1771,7 +1787,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1779,7 +1795,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1787,7 +1803,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1879,8 +1895,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1889,7 +1909,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1897,7 +1919,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1908,7 +1930,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2001,8 +2023,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2011,7 +2037,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2019,7 +2047,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2030,7 +2058,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2061,8 +2089,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2073,7 +2105,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2081,7 +2115,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/client.py index f00990a7ea7a..07b96181577f 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/client.py @@ -121,7 +121,7 @@ class ClusterControllerClient(metaclass=ClusterControllerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -516,7 +520,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -613,7 +617,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -713,7 +717,7 @@ def __init__( self._universe_domain = ClusterControllerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2052,7 +2056,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2078,8 +2082,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2088,7 +2096,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2097,7 +2105,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2111,7 +2119,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2137,8 +2145,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2147,7 +2159,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2156,7 +2168,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2170,7 +2182,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2200,8 +2212,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2210,7 +2226,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2218,7 +2234,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2226,7 +2242,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2255,8 +2271,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2265,7 +2285,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2273,7 +2293,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2281,7 +2301,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2373,8 +2393,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2383,7 +2407,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2392,7 +2418,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2406,7 +2432,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2499,8 +2525,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2509,7 +2539,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2518,7 +2550,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2532,7 +2564,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2563,8 +2595,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2573,7 +2609,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2582,7 +2620,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/README.rst index a0c994abbba7..cfd6ff5cf659 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ClusterControllerTransport` is the ABC for all transports. -- public child `ClusterControllerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ClusterControllerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseClusterControllerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ClusterControllerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ClusterControllerTransport`` is the ABC for all transports. + +- public child ``ClusterControllerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ClusterControllerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseClusterControllerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ClusterControllerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/base.py index ec03bad70895..77b82c696fee 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc.py index 64a30601a5f3..88054ab5f3d1 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc_asyncio.py index 9e4733d575be..bd05cae7a48a 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/rest.py index 0c6834a10c58..04d22e7725cf 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/cluster_controller/transports/rest.py @@ -751,6 +751,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ClusterControllerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/async_client.py index 286811bce3e5..3b27252e4bdc 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> JobControllerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1257,7 +1257,7 @@ async def sample_delete_job(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1283,8 +1283,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1293,7 +1297,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1301,7 +1305,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1312,7 +1316,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1338,8 +1342,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1348,7 +1356,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1356,7 +1364,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1367,7 +1375,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1397,8 +1405,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1407,7 +1419,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1415,7 +1427,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1423,7 +1435,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1452,8 +1464,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1462,7 +1478,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1470,7 +1486,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1478,7 +1494,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1570,8 +1586,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1580,7 +1600,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1588,7 +1610,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1599,7 +1621,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1692,8 +1714,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1702,7 +1728,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1710,7 +1738,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1721,7 +1749,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1752,8 +1780,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1764,7 +1796,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1772,7 +1806,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/client.py index fd43ec386976..6147e63cf7ec 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/client.py @@ -117,7 +117,7 @@ class JobControllerClient(metaclass=JobControllerClientMeta): """The JobController provides methods to manage jobs.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -420,7 +424,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -517,7 +521,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = JobControllerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1662,7 +1666,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1688,8 +1692,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1698,7 +1706,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1707,7 +1715,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1721,7 +1729,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1747,8 +1755,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1757,7 +1769,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1766,7 +1778,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1780,7 +1792,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1810,8 +1822,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1820,7 +1836,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1828,7 +1844,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1836,7 +1852,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1865,8 +1881,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1875,7 +1895,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1883,7 +1903,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1891,7 +1911,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1983,8 +2003,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1993,7 +2017,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2002,7 +2028,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2016,7 +2042,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2109,8 +2135,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2119,7 +2149,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2128,7 +2160,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2142,7 +2174,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2173,8 +2205,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2183,7 +2219,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2192,7 +2230,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/README.rst index 9459085b1d74..20c720f897f4 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`JobControllerTransport` is the ABC for all transports. -- public child `JobControllerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `JobControllerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseJobControllerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `JobControllerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``JobControllerTransport`` is the ABC for all transports. + +- public child ``JobControllerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``JobControllerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseJobControllerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``JobControllerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/base.py index 3ddcfb4850c2..7550f09feb76 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc.py index bfac2b7c7f0d..02c219b430d9 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc_asyncio.py index d2fe5a986122..70b5c8c39fb7 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/rest.py index 28837ad04cd3..ebd002a88d29 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/job_controller/transports/rest.py @@ -641,6 +641,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[JobControllerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/async_client.py index a635e2174397..e79904115742 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> NodeGroupControllerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -727,7 +727,7 @@ async def sample_get_node_group(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -753,8 +753,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -763,7 +767,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -771,7 +775,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -782,7 +786,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -808,8 +812,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -818,7 +826,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -826,7 +834,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -837,7 +845,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -867,8 +875,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -877,7 +889,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -885,7 +897,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -893,7 +905,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -922,8 +934,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -932,7 +948,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -940,7 +956,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -948,7 +964,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1040,8 +1056,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1050,7 +1070,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1058,7 +1080,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1069,7 +1091,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1162,8 +1184,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1172,7 +1198,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1180,7 +1208,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1191,7 +1219,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1222,8 +1250,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1234,7 +1266,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1242,7 +1276,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/client.py index cd7d690d53bd..989aa9c6f8ee 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/client.py @@ -118,7 +118,7 @@ class NodeGroupControllerClient(metaclass=NodeGroupControllerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -445,7 +449,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -542,7 +546,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -642,7 +646,7 @@ def __init__( self._universe_domain = NodeGroupControllerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1160,7 +1164,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1186,8 +1190,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1196,7 +1204,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1205,7 +1213,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1219,7 +1227,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1245,8 +1253,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1255,7 +1267,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1264,7 +1276,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1278,7 +1290,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1320,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1334,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1326,7 +1342,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1334,7 +1350,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1363,8 +1379,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1393,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1381,7 +1401,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1389,7 +1409,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1481,8 +1501,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1491,7 +1515,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1500,7 +1526,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1514,7 +1540,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1607,8 +1633,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1617,7 +1647,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1626,7 +1658,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1640,7 +1672,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1671,8 +1703,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1681,7 +1717,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1690,7 +1728,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/README.rst index f02a2c466b93..aa2f950d58c7 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NodeGroupControllerTransport` is the ABC for all transports. -- public child `NodeGroupControllerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NodeGroupControllerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNodeGroupControllerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NodeGroupControllerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NodeGroupControllerTransport`` is the ABC for all transports. + +- public child ``NodeGroupControllerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NodeGroupControllerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNodeGroupControllerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NodeGroupControllerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/base.py index ba560f36221d..a01651e0a233 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc.py index 5b735ef655df..c82e9edfbb7f 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc_asyncio.py index 4da891bcba64..04c63ea7066b 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/rest.py index d24c7fdfe199..9a37137c5858 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/node_group_controller/transports/rest.py @@ -485,6 +485,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NodeGroupControllerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/async_client.py index 7cb4f2961c61..4ece180672fd 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> SessionControllerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -958,7 +958,7 @@ async def sample_delete_session(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -984,8 +984,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -994,7 +998,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1002,7 +1006,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1013,7 +1017,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,8 +1043,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1049,7 +1057,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1057,7 +1065,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1068,7 +1076,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1098,8 +1106,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1108,7 +1120,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1116,7 +1128,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1136,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1153,8 +1165,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,7 +1179,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1171,7 +1187,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1179,7 +1195,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1271,8 +1287,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1281,7 +1301,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1289,7 +1311,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1300,7 +1322,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1393,8 +1415,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,7 +1429,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1411,7 +1439,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1422,7 +1450,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1453,8 +1481,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1465,7 +1497,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1473,7 +1507,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/client.py index 114ba09c73f6..7fb537cd727a 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/client.py @@ -120,7 +120,7 @@ class SessionControllerClient(metaclass=SessionControllerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -489,7 +493,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -586,7 +590,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -686,7 +690,7 @@ def __init__( self._universe_domain = SessionControllerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1425,7 +1429,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1451,8 +1455,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1461,7 +1469,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1470,7 +1478,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1484,7 +1492,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1510,8 +1518,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1520,7 +1532,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1529,7 +1541,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1543,7 +1555,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1573,8 +1585,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1583,7 +1599,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1591,7 +1607,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1599,7 +1615,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1628,8 +1644,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1638,7 +1658,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1646,7 +1666,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1654,7 +1674,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1746,8 +1766,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1756,7 +1780,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1765,7 +1791,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1779,7 +1805,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1872,8 +1898,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1882,7 +1912,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1891,7 +1923,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1905,7 +1937,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1936,8 +1968,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1946,7 +1982,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1955,7 +1993,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/README.rst index dc76e058e152..a26d301205a8 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionControllerTransport` is the ABC for all transports. -- public child `SessionControllerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionControllerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionControllerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionControllerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionControllerTransport`` is the ABC for all transports. + +- public child ``SessionControllerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionControllerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionControllerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionControllerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/base.py index 8464b2b0016c..95113134c101 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc.py index 19fa7481ad09..3ec1715ee54f 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc_asyncio.py index d91b1ad87df9..788015b559b3 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/rest.py index 01acd2e02443..216c28dd0cea 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_controller/transports/rest.py @@ -589,6 +589,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionControllerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/async_client.py index ea53880778f3..6c7414c4ab87 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/async_client.py @@ -214,7 +214,7 @@ def transport(self) -> SessionTemplateControllerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -916,7 +916,7 @@ async def sample_delete_session_template(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -942,8 +942,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -952,7 +956,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -960,7 +964,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -971,7 +975,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -997,8 +1001,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1007,7 +1015,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1015,7 +1023,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1026,7 +1034,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1056,8 +1064,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1066,7 +1078,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1074,7 +1086,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1082,7 +1094,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1111,8 +1123,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1121,7 +1137,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1129,7 +1145,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1137,7 +1153,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1229,8 +1245,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1239,7 +1259,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1247,7 +1269,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1258,7 +1280,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1351,8 +1373,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1361,7 +1387,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1369,7 +1397,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1380,7 +1408,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1411,8 +1439,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1423,7 +1455,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1431,7 +1465,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/client.py index c65fad323248..d6eb7ccd2354 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/client.py @@ -118,7 +118,7 @@ class SessionTemplateControllerClient(metaclass=SessionTemplateControllerClientM """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -666,7 +670,7 @@ def __init__( self._universe_domain = SessionTemplateControllerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1351,7 +1355,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1377,8 +1381,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1387,7 +1395,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1396,7 +1404,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1410,7 +1418,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1436,8 +1444,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1446,7 +1458,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1455,7 +1467,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1469,7 +1481,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1499,8 +1511,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1509,7 +1525,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1517,7 +1533,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1525,7 +1541,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1554,8 +1570,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1564,7 +1584,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1572,7 +1592,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1580,7 +1600,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1672,8 +1692,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1682,7 +1706,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1691,7 +1717,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1705,7 +1731,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1798,8 +1824,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1808,7 +1838,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1817,7 +1849,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1831,7 +1863,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1862,8 +1894,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1872,7 +1908,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1881,7 +1919,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/README.rst index a874b2228f5d..89ce826ad768 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionTemplateControllerTransport` is the ABC for all transports. -- public child `SessionTemplateControllerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionTemplateControllerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionTemplateControllerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionTemplateControllerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionTemplateControllerTransport`` is the ABC for all transports. + +- public child ``SessionTemplateControllerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionTemplateControllerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionTemplateControllerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionTemplateControllerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/base.py index be40468e8349..c6ca686413da 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc.py index dd732bc9c908..36e5d59fa332 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc_asyncio.py index b363c48ab3c9..953a702e3a67 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/rest.py index 0e6a9fc74019..f5626888726a 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/session_template_controller/transports/rest.py @@ -578,6 +578,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionTemplateControllerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/async_client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/async_client.py index 130ae19b4c57..cbfc26509e72 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/async_client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/async_client.py @@ -222,7 +222,7 @@ def transport(self) -> WorkflowTemplateServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1356,7 +1356,7 @@ async def sample_delete_workflow_template(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1382,8 +1382,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1392,7 +1396,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1400,7 +1404,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1411,7 +1415,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1437,8 +1441,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1447,7 +1455,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1455,7 +1463,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1466,7 +1474,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1496,8 +1504,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1506,7 +1518,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1514,7 +1526,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1522,7 +1534,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1551,8 +1563,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1561,7 +1577,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1569,7 +1585,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1577,7 +1593,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1669,8 +1685,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1679,7 +1699,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1687,7 +1709,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1698,7 +1720,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1791,8 +1813,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1801,7 +1827,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1809,7 +1837,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1820,7 +1848,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1851,8 +1879,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1863,7 +1895,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1871,7 +1905,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/client.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/client.py index 61d5f6062145..5362630f79fb 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/client.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/client.py @@ -122,7 +122,7 @@ class WorkflowTemplateServiceClient(metaclass=WorkflowTemplateServiceClientMeta) """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -517,7 +521,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -616,7 +620,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -718,7 +722,7 @@ def __init__( self._universe_domain = WorkflowTemplateServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1832,7 +1836,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1858,8 +1862,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1868,7 +1876,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1877,7 +1885,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1891,7 +1899,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1917,8 +1925,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1927,7 +1939,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1936,7 +1948,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1950,7 +1962,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1980,8 +1992,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1990,7 +2006,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1998,7 +2014,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2006,7 +2022,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2035,8 +2051,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2045,7 +2065,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2053,7 +2073,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2061,7 +2081,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2153,8 +2173,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2163,7 +2187,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2172,7 +2198,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2186,7 +2212,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2279,8 +2305,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2289,7 +2319,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2298,7 +2330,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2312,7 +2344,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2343,8 +2375,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2353,7 +2389,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2362,7 +2400,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/README.rst b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/README.rst index 2e3ec5f74bd5..bc6a6bd04877 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/README.rst +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WorkflowTemplateServiceTransport` is the ABC for all transports. -- public child `WorkflowTemplateServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WorkflowTemplateServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWorkflowTemplateServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WorkflowTemplateServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WorkflowTemplateServiceTransport`` is the ABC for all transports. + +- public child ``WorkflowTemplateServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WorkflowTemplateServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWorkflowTemplateServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WorkflowTemplateServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/base.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/base.py index 97ff1f77dc54..ec40a9a05bc5 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/base.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc.py index ee7804ed1e23..432dfeea7dfe 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc_asyncio.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc_asyncio.py index cc42e937965e..5001f57a15c5 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/rest.py b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/rest.py index d784c5f5c4ff..3c3bd9557e75 100644 --- a/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/rest.py +++ b/packages/google-cloud-dataproc/google/cloud/dataproc_v1/services/workflow_template_service/transports/rest.py @@ -690,6 +690,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WorkflowTemplateServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dataproc/noxfile.py b/packages/google-cloud-dataproc/noxfile.py index 9d282092f1af..ee341407bdd8 100644 --- a/packages/google-cloud-dataproc/noxfile.py +++ b/packages/google-cloud-dataproc/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dataproc/setup.py b/packages/google-cloud-dataproc/setup.py index 9fd3beb5c5e7..71f22b5c4406 100644 --- a/packages/google-cloud-dataproc/setup.py +++ b/packages/google-cloud-dataproc/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dataproc/testing/constraints-3.7.txt b/packages/google-cloud-dataproc/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-dataproc/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataproc/testing/constraints-3.8.txt b/packages/google-cloud-dataproc/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-dataproc/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-dataproc/testing/constraints-3.9.txt b/packages/google-cloud-dataproc/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-dataproc/testing/constraints-3.9.txt +++ b/packages/google-cloud-dataproc/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_autoscaling_policy_service.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_autoscaling_policy_service.py index 060ebf63e227..0a22622cc9e7 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_autoscaling_policy_service.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_autoscaling_policy_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutoscalingPolicyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): AutoscalingPolicyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AutoscalingPolicyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1359,11 +1364,13 @@ def test_autoscaling_policy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4756,8 +4763,9 @@ def test_create_autoscaling_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4914,20 +4922,22 @@ def test_create_autoscaling_policy_rest_interceptors(null_interceptor): ) client = AutoscalingPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_create_autoscaling_policy", - ) as post, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_create_autoscaling_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "pre_create_autoscaling_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_create_autoscaling_policy", + ) as post, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_create_autoscaling_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "pre_create_autoscaling_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4989,8 +4999,9 @@ def test_update_autoscaling_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5151,20 +5162,22 @@ def test_update_autoscaling_policy_rest_interceptors(null_interceptor): ) client = AutoscalingPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_update_autoscaling_policy", - ) as post, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_update_autoscaling_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "pre_update_autoscaling_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_update_autoscaling_policy", + ) as post, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_update_autoscaling_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "pre_update_autoscaling_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5224,8 +5237,9 @@ def test_get_autoscaling_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5297,19 +5311,22 @@ def test_get_autoscaling_policy_rest_interceptors(null_interceptor): ) client = AutoscalingPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_get_autoscaling_policy", - ) as post, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_get_autoscaling_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, "pre_get_autoscaling_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_get_autoscaling_policy", + ) as post, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_get_autoscaling_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "pre_get_autoscaling_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5367,8 +5384,9 @@ def test_list_autoscaling_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5433,20 +5451,22 @@ def test_list_autoscaling_policies_rest_interceptors(null_interceptor): ) client = AutoscalingPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_list_autoscaling_policies", - ) as post, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "post_list_autoscaling_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "pre_list_autoscaling_policies", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_list_autoscaling_policies", + ) as post, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "post_list_autoscaling_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "pre_list_autoscaling_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5506,8 +5526,9 @@ def test_delete_autoscaling_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5566,14 +5587,14 @@ def test_delete_autoscaling_policy_rest_interceptors(null_interceptor): ) client = AutoscalingPolicyServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutoscalingPolicyServiceRestInterceptor, - "pre_delete_autoscaling_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutoscalingPolicyServiceRestInterceptor, + "pre_delete_autoscaling_policy", + ) as pre, + ): pre.assert_not_called() pb_message = autoscaling_policies.DeleteAutoscalingPolicyRequest.pb( autoscaling_policies.DeleteAutoscalingPolicyRequest() @@ -5620,8 +5641,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5682,8 +5704,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5744,8 +5767,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5806,8 +5830,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5868,8 +5893,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5930,8 +5956,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5992,8 +6019,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6222,11 +6250,14 @@ def test_autoscaling_policy_service_base_transport(): def test_autoscaling_policy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.autoscaling_policy_service.transports.AutoscalingPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.autoscaling_policy_service.transports.AutoscalingPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoscalingPolicyServiceTransport( @@ -6243,9 +6274,12 @@ def test_autoscaling_policy_service_base_transport_with_credentials_file(): def test_autoscaling_policy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.autoscaling_policy_service.transports.AutoscalingPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.autoscaling_policy_service.transports.AutoscalingPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutoscalingPolicyServiceTransport() @@ -6319,11 +6353,12 @@ def test_autoscaling_policy_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6902,6 +6937,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AutoscalingPolicyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7041,6 +7108,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AutoscalingPolicyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7186,6 +7285,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AutoscalingPolicyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7331,6 +7464,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AutoscalingPolicyServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7495,6 +7662,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AutoscalingPolicyServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7662,6 +7864,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AutoscalingPolicyServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7839,6 +8076,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AutoscalingPolicyServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AutoscalingPolicyServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AutoscalingPolicyServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_batch_controller.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_batch_controller.py index d93e022a92da..d30ed1f7b37d 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_batch_controller.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_batch_controller.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BatchControllerClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): assert ( BatchControllerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BatchControllerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1316,11 +1321,13 @@ def test_batch_controller_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3995,8 +4002,9 @@ def test_create_batch_rest_bad_request(request_type=batches.CreateBatchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4210,19 +4218,20 @@ def test_create_batch_rest_interceptors(null_interceptor): ) client = BatchControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BatchControllerRestInterceptor, "post_create_batch" - ) as post, mock.patch.object( - transports.BatchControllerRestInterceptor, "post_create_batch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchControllerRestInterceptor, "pre_create_batch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BatchControllerRestInterceptor, "post_create_batch" + ) as post, + mock.patch.object( + transports.BatchControllerRestInterceptor, "post_create_batch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchControllerRestInterceptor, "pre_create_batch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4271,8 +4280,9 @@ def test_get_batch_rest_bad_request(request_type=batches.GetBatchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4345,17 +4355,19 @@ def test_get_batch_rest_interceptors(null_interceptor): ) client = BatchControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchControllerRestInterceptor, "post_get_batch" - ) as post, mock.patch.object( - transports.BatchControllerRestInterceptor, "post_get_batch_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchControllerRestInterceptor, "pre_get_batch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchControllerRestInterceptor, "post_get_batch" + ) as post, + mock.patch.object( + transports.BatchControllerRestInterceptor, "post_get_batch_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchControllerRestInterceptor, "pre_get_batch" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4404,8 +4416,9 @@ def test_list_batches_rest_bad_request(request_type=batches.ListBatchesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4470,17 +4483,19 @@ def test_list_batches_rest_interceptors(null_interceptor): ) client = BatchControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchControllerRestInterceptor, "post_list_batches" - ) as post, mock.patch.object( - transports.BatchControllerRestInterceptor, "post_list_batches_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BatchControllerRestInterceptor, "pre_list_batches" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchControllerRestInterceptor, "post_list_batches" + ) as post, + mock.patch.object( + transports.BatchControllerRestInterceptor, "post_list_batches_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BatchControllerRestInterceptor, "pre_list_batches" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4531,8 +4546,9 @@ def test_delete_batch_rest_bad_request(request_type=batches.DeleteBatchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4589,13 +4605,13 @@ def test_delete_batch_rest_interceptors(null_interceptor): ) client = BatchControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BatchControllerRestInterceptor, "pre_delete_batch" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BatchControllerRestInterceptor, "pre_delete_batch" + ) as pre, + ): pre.assert_not_called() pb_message = batches.DeleteBatchRequest.pb(batches.DeleteBatchRequest()) transcode.return_value = { @@ -4640,8 +4656,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4702,8 +4719,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4764,8 +4782,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4826,8 +4845,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4888,8 +4908,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4950,8 +4971,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5012,8 +5034,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5233,11 +5256,14 @@ def test_batch_controller_base_transport(): def test_batch_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.batch_controller.transports.BatchControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.batch_controller.transports.BatchControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BatchControllerTransport( @@ -5254,9 +5280,12 @@ def test_batch_controller_base_transport_with_credentials_file(): def test_batch_controller_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.batch_controller.transports.BatchControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.batch_controller.transports.BatchControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BatchControllerTransport() @@ -5328,11 +5357,12 @@ def test_batch_controller_transport_auth_gdch_credentials(transport_class): def test_batch_controller_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5964,6 +5994,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BatchControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6103,6 +6165,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BatchControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6248,6 +6342,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BatchControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6393,6 +6521,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BatchControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6557,6 +6719,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = BatchControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6724,6 +6921,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = BatchControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6901,6 +7133,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = BatchControllerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = BatchControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = BatchControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_cluster_controller.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_cluster_controller.py index 7fb3372e8790..0a2dac31711f 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_cluster_controller.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_cluster_controller.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ClusterControllerClient._get_default_mtls_endpoint(None) is None assert ( @@ -156,6 +157,10 @@ def test__get_default_mtls_endpoint(): ClusterControllerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ClusterControllerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1333,11 +1338,13 @@ def test_cluster_controller_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6327,8 +6334,9 @@ def test_create_cluster_rest_bad_request(request_type=clusters.CreateClusterRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6671,19 +6679,21 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_create_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6736,8 +6746,9 @@ def test_update_cluster_rest_bad_request(request_type=clusters.UpdateClusterRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7084,19 +7095,21 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_update_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7149,8 +7162,9 @@ def test_stop_cluster_rest_bad_request(request_type=clusters.StopClusterRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7211,19 +7225,21 @@ def test_stop_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_stop_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_stop_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_stop_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_stop_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_stop_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_stop_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7276,8 +7292,9 @@ def test_start_cluster_rest_bad_request(request_type=clusters.StartClusterReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7338,19 +7355,21 @@ def test_start_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_start_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_start_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_start_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_start_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_start_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_start_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7403,8 +7422,9 @@ def test_delete_cluster_rest_bad_request(request_type=clusters.DeleteClusterRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7465,19 +7485,21 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_delete_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7530,8 +7552,9 @@ def test_get_cluster_rest_bad_request(request_type=clusters.GetClusterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7602,17 +7625,20 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_get_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7661,8 +7687,9 @@ def test_list_clusters_rest_bad_request(request_type=clusters.ListClustersReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7725,17 +7752,20 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_list_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7792,8 +7822,9 @@ def test_diagnose_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7854,20 +7885,21 @@ def test_diagnose_cluster_rest_interceptors(null_interceptor): ) client = ClusterControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ClusterControllerRestInterceptor, "post_diagnose_cluster" - ) as post, mock.patch.object( - transports.ClusterControllerRestInterceptor, - "post_diagnose_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ClusterControllerRestInterceptor, "pre_diagnose_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ClusterControllerRestInterceptor, "post_diagnose_cluster" + ) as post, + mock.patch.object( + transports.ClusterControllerRestInterceptor, + "post_diagnose_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ClusterControllerRestInterceptor, "pre_diagnose_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7922,8 +7954,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7984,8 +8017,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8046,8 +8080,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8108,8 +8143,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8170,8 +8206,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8232,8 +8269,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8294,8 +8332,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8599,11 +8638,14 @@ def test_cluster_controller_base_transport(): def test_cluster_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.cluster_controller.transports.ClusterControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.cluster_controller.transports.ClusterControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClusterControllerTransport( @@ -8620,9 +8662,12 @@ def test_cluster_controller_base_transport_with_credentials_file(): def test_cluster_controller_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.cluster_controller.transports.ClusterControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.cluster_controller.transports.ClusterControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ClusterControllerTransport() @@ -8694,11 +8739,12 @@ def test_cluster_controller_transport_auth_gdch_credentials(transport_class): def test_cluster_controller_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9404,6 +9450,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ClusterControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9543,6 +9621,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ClusterControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9688,6 +9798,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ClusterControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9833,6 +9977,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ClusterControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9997,6 +10175,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = ClusterControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10164,6 +10377,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = ClusterControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10341,6 +10589,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = ClusterControllerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = ClusterControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = ClusterControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_job_controller.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_job_controller.py index 728852786520..cff6ab7bc9f2 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_job_controller.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_job_controller.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert JobControllerClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): assert ( JobControllerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + JobControllerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1288,11 +1293,13 @@ def test_job_controller_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5790,8 +5797,9 @@ def test_submit_job_rest_bad_request(request_type=jobs.SubmitJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5860,17 +5868,19 @@ def test_submit_job_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobControllerRestInterceptor, "post_submit_job" - ) as post, mock.patch.object( - transports.JobControllerRestInterceptor, "post_submit_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_submit_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_submit_job" + ) as post, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_submit_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_submit_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5919,8 +5929,9 @@ def test_submit_job_as_operation_rest_bad_request(request_type=jobs.SubmitJobReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5977,20 +5988,21 @@ def test_submit_job_as_operation_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.JobControllerRestInterceptor, "post_submit_job_as_operation" - ) as post, mock.patch.object( - transports.JobControllerRestInterceptor, - "post_submit_job_as_operation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_submit_job_as_operation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.JobControllerRestInterceptor, "post_submit_job_as_operation" + ) as post, + mock.patch.object( + transports.JobControllerRestInterceptor, + "post_submit_job_as_operation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_submit_job_as_operation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6039,8 +6051,9 @@ def test_get_job_rest_bad_request(request_type=jobs.GetJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6109,17 +6122,19 @@ def test_get_job_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobControllerRestInterceptor, "post_get_job" - ) as post, mock.patch.object( - transports.JobControllerRestInterceptor, "post_get_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_get_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_get_job" + ) as post, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_get_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_get_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6168,8 +6183,9 @@ def test_list_jobs_rest_bad_request(request_type=jobs.ListJobsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6234,17 +6250,19 @@ def test_list_jobs_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobControllerRestInterceptor, "post_list_jobs" - ) as post, mock.patch.object( - transports.JobControllerRestInterceptor, "post_list_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_list_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_list_jobs" + ) as post, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_list_jobs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_list_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6293,8 +6311,9 @@ def test_update_job_rest_bad_request(request_type=jobs.UpdateJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6550,17 +6569,19 @@ def test_update_job_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobControllerRestInterceptor, "post_update_job" - ) as post, mock.patch.object( - transports.JobControllerRestInterceptor, "post_update_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_update_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_update_job" + ) as post, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_update_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_update_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6609,8 +6630,9 @@ def test_cancel_job_rest_bad_request(request_type=jobs.CancelJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6679,17 +6701,19 @@ def test_cancel_job_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobControllerRestInterceptor, "post_cancel_job" - ) as post, mock.patch.object( - transports.JobControllerRestInterceptor, "post_cancel_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_cancel_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_cancel_job" + ) as post, + mock.patch.object( + transports.JobControllerRestInterceptor, "post_cancel_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_cancel_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6738,8 +6762,9 @@ def test_delete_job_rest_bad_request(request_type=jobs.DeleteJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6796,13 +6821,13 @@ def test_delete_job_rest_interceptors(null_interceptor): ) client = JobControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.JobControllerRestInterceptor, "pre_delete_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.JobControllerRestInterceptor, "pre_delete_job" + ) as pre, + ): pre.assert_not_called() pb_message = jobs.DeleteJobRequest.pb(jobs.DeleteJobRequest()) transcode.return_value = { @@ -6847,8 +6872,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6909,8 +6935,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6971,8 +6998,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7033,8 +7061,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7095,8 +7124,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7157,8 +7187,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7219,8 +7250,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7505,11 +7537,14 @@ def test_job_controller_base_transport(): def test_job_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.job_controller.transports.JobControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.job_controller.transports.JobControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.JobControllerTransport( @@ -7526,9 +7561,12 @@ def test_job_controller_base_transport_with_credentials_file(): def test_job_controller_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.job_controller.transports.JobControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.job_controller.transports.JobControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.JobControllerTransport() @@ -7600,11 +7638,12 @@ def test_job_controller_transport_auth_gdch_credentials(transport_class): def test_job_controller_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8191,6 +8230,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = JobControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8330,6 +8401,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = JobControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8475,6 +8578,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = JobControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8620,6 +8757,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = JobControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8784,6 +8955,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = JobControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8951,6 +9157,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = JobControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9128,6 +9369,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = JobControllerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = JobControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = JobControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_node_group_controller.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_node_group_controller.py index 0ab7764abe9f..015416e148df 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_node_group_controller.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_node_group_controller.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NodeGroupControllerClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): NodeGroupControllerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NodeGroupControllerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_node_group_controller_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3288,8 +3295,9 @@ def test_create_node_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3474,20 +3482,21 @@ def test_create_node_group_rest_interceptors(null_interceptor): ) client = NodeGroupControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NodeGroupControllerRestInterceptor, "post_create_node_group" - ) as post, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, - "post_create_node_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, "pre_create_node_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, "post_create_node_group" + ) as post, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, + "post_create_node_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, "pre_create_node_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3542,8 +3551,9 @@ def test_resize_node_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3602,20 +3612,21 @@ def test_resize_node_group_rest_interceptors(null_interceptor): ) client = NodeGroupControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NodeGroupControllerRestInterceptor, "post_resize_node_group" - ) as post, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, - "post_resize_node_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, "pre_resize_node_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, "post_resize_node_group" + ) as post, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, + "post_resize_node_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, "pre_resize_node_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3668,8 +3679,9 @@ def test_get_node_group_rest_bad_request(request_type=node_groups.GetNodeGroupRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3736,18 +3748,20 @@ def test_get_node_group_rest_interceptors(null_interceptor): ) client = NodeGroupControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, "post_get_node_group" - ) as post, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, - "post_get_node_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NodeGroupControllerRestInterceptor, "pre_get_node_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, "post_get_node_group" + ) as post, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, + "post_get_node_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NodeGroupControllerRestInterceptor, "pre_get_node_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3802,8 +3816,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3864,8 +3879,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3926,8 +3942,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3988,8 +4005,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4050,8 +4068,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4112,8 +4131,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4174,8 +4194,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4378,11 +4399,14 @@ def test_node_group_controller_base_transport(): def test_node_group_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.node_group_controller.transports.NodeGroupControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.node_group_controller.transports.NodeGroupControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeGroupControllerTransport( @@ -4399,9 +4423,12 @@ def test_node_group_controller_base_transport_with_credentials_file(): def test_node_group_controller_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.node_group_controller.transports.NodeGroupControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.node_group_controller.transports.NodeGroupControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NodeGroupControllerTransport() @@ -4473,11 +4500,12 @@ def test_node_group_controller_transport_auth_gdch_credentials(transport_class): def test_node_group_controller_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5087,6 +5115,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = NodeGroupControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5226,6 +5286,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = NodeGroupControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5371,6 +5463,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = NodeGroupControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5516,6 +5642,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = NodeGroupControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5680,6 +5840,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = NodeGroupControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5847,6 +6042,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = NodeGroupControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6024,6 +6254,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = NodeGroupControllerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = NodeGroupControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = NodeGroupControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_controller.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_controller.py index 0d4835c9f827..6fcfcf3b99d0 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_controller.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_controller.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionControllerClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): SessionControllerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionControllerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_session_controller_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4626,8 +4633,9 @@ def test_create_session_rest_bad_request(request_type=sessions.CreateSessionRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4817,19 +4825,21 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = SessionControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SessionControllerRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.SessionControllerRestInterceptor, "post_create_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionControllerRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SessionControllerRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.SessionControllerRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionControllerRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4878,8 +4888,9 @@ def test_get_session_rest_bad_request(request_type=sessions.GetSessionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4954,17 +4965,20 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = SessionControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionControllerRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.SessionControllerRestInterceptor, "post_get_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionControllerRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionControllerRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.SessionControllerRestInterceptor, + "post_get_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionControllerRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5013,8 +5027,9 @@ def test_list_sessions_rest_bad_request(request_type=sessions.ListSessionsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5077,17 +5092,20 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = SessionControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionControllerRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.SessionControllerRestInterceptor, "post_list_sessions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionControllerRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionControllerRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.SessionControllerRestInterceptor, + "post_list_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionControllerRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5140,8 +5158,9 @@ def test_terminate_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5198,20 +5217,21 @@ def test_terminate_session_rest_interceptors(null_interceptor): ) client = SessionControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SessionControllerRestInterceptor, "post_terminate_session" - ) as post, mock.patch.object( - transports.SessionControllerRestInterceptor, - "post_terminate_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionControllerRestInterceptor, "pre_terminate_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SessionControllerRestInterceptor, "post_terminate_session" + ) as post, + mock.patch.object( + transports.SessionControllerRestInterceptor, + "post_terminate_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionControllerRestInterceptor, "pre_terminate_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5262,8 +5282,9 @@ def test_delete_session_rest_bad_request(request_type=sessions.DeleteSessionRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5320,19 +5341,21 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = SessionControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SessionControllerRestInterceptor, "post_delete_session" - ) as post, mock.patch.object( - transports.SessionControllerRestInterceptor, "post_delete_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionControllerRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SessionControllerRestInterceptor, "post_delete_session" + ) as post, + mock.patch.object( + transports.SessionControllerRestInterceptor, + "post_delete_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionControllerRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5385,8 +5408,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5447,8 +5471,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5509,8 +5534,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5571,8 +5597,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5633,8 +5660,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5695,8 +5723,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5757,8 +5786,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6001,11 +6031,14 @@ def test_session_controller_base_transport(): def test_session_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.session_controller.transports.SessionControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.session_controller.transports.SessionControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionControllerTransport( @@ -6022,9 +6055,12 @@ def test_session_controller_base_transport_with_credentials_file(): def test_session_controller_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.session_controller.transports.SessionControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.session_controller.transports.SessionControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionControllerTransport() @@ -6096,11 +6132,12 @@ def test_session_controller_transport_auth_gdch_credentials(transport_class): def test_session_controller_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6763,6 +6800,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = SessionControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6902,6 +6971,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7047,6 +7148,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7192,6 +7327,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7356,6 +7525,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = SessionControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7523,6 +7727,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = SessionControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7700,6 +7939,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = SessionControllerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = SessionControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = SessionControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_template_controller.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_template_controller.py index b542ecfe0569..e27ee8189985 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_template_controller.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_session_template_controller.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionTemplateControllerClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): SessionTemplateControllerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionTemplateControllerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1367,11 +1372,13 @@ def test_session_template_controller_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4752,8 +4759,9 @@ def test_create_session_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4931,20 +4939,22 @@ def test_create_session_template_rest_interceptors(null_interceptor): ) client = SessionTemplateControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_create_session_template", - ) as post, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_create_session_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "pre_create_session_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_create_session_template", + ) as post, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_create_session_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "pre_create_session_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5003,8 +5013,9 @@ def test_update_session_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5186,20 +5197,22 @@ def test_update_session_template_rest_interceptors(null_interceptor): ) client = SessionTemplateControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_update_session_template", - ) as post, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_update_session_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "pre_update_session_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_update_session_template", + ) as post, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_update_session_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "pre_update_session_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5256,8 +5269,9 @@ def test_get_session_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5328,18 +5342,22 @@ def test_get_session_template_rest_interceptors(null_interceptor): ) client = SessionTemplateControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, "post_get_session_template" - ) as post, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_get_session_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, "pre_get_session_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_get_session_template", + ) as post, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_get_session_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "pre_get_session_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5394,8 +5412,9 @@ def test_list_session_templates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5458,20 +5477,22 @@ def test_list_session_templates_rest_interceptors(null_interceptor): ) client = SessionTemplateControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_list_session_templates", - ) as post, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "post_list_session_templates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "pre_list_session_templates", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_list_session_templates", + ) as post, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "post_list_session_templates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "pre_list_session_templates", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5531,8 +5552,9 @@ def test_delete_session_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5591,14 +5613,14 @@ def test_delete_session_template_rest_interceptors(null_interceptor): ) client = SessionTemplateControllerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionTemplateControllerRestInterceptor, - "pre_delete_session_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionTemplateControllerRestInterceptor, + "pre_delete_session_template", + ) as pre, + ): pre.assert_not_called() pb_message = session_templates.DeleteSessionTemplateRequest.pb( session_templates.DeleteSessionTemplateRequest() @@ -5645,8 +5667,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5707,8 +5730,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5769,8 +5793,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5831,8 +5856,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5893,8 +5919,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5955,8 +5982,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6017,8 +6045,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6247,11 +6276,14 @@ def test_session_template_controller_base_transport(): def test_session_template_controller_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.session_template_controller.transports.SessionTemplateControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.session_template_controller.transports.SessionTemplateControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionTemplateControllerTransport( @@ -6268,9 +6300,12 @@ def test_session_template_controller_base_transport_with_credentials_file(): def test_session_template_controller_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.session_template_controller.transports.SessionTemplateControllerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.session_template_controller.transports.SessionTemplateControllerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionTemplateControllerTransport() @@ -6344,11 +6379,12 @@ def test_session_template_controller_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6957,6 +6993,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = SessionTemplateControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7096,6 +7164,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionTemplateControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7241,6 +7341,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionTemplateControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7386,6 +7520,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionTemplateControllerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7550,6 +7718,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = SessionTemplateControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7717,6 +7920,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = SessionTemplateControllerClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7894,6 +8132,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = SessionTemplateControllerClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = SessionTemplateControllerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = SessionTemplateControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_workflow_template_service.py b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_workflow_template_service.py index d3140943aaf7..96a8e65f7cc7 100644 --- a/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_workflow_template_service.py +++ b/packages/google-cloud-dataproc/tests/unit/gapic/dataproc_v1/test_workflow_template_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WorkflowTemplateServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): WorkflowTemplateServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + WorkflowTemplateServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1359,11 +1364,13 @@ def test_workflow_template_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5945,8 +5952,9 @@ def test_create_workflow_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6385,20 +6393,22 @@ def test_create_workflow_template_rest_interceptors(null_interceptor): ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_create_workflow_template", - ) as post, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_create_workflow_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "pre_create_workflow_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_create_workflow_template", + ) as post, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_create_workflow_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_create_workflow_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6458,8 +6468,9 @@ def test_get_workflow_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6528,18 +6539,22 @@ def test_get_workflow_template_rest_interceptors(null_interceptor): ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, "post_get_workflow_template" - ) as post, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_get_workflow_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, "pre_get_workflow_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_get_workflow_template", + ) as post, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_get_workflow_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_get_workflow_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6599,8 +6614,9 @@ def test_instantiate_workflow_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6659,22 +6675,23 @@ def test_instantiate_workflow_template_rest_interceptors(null_interceptor): ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_instantiate_workflow_template", - ) as post, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_instantiate_workflow_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "pre_instantiate_workflow_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_instantiate_workflow_template", + ) as post, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_instantiate_workflow_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_instantiate_workflow_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6727,8 +6744,9 @@ def test_instantiate_inline_workflow_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7159,22 +7177,23 @@ def test_instantiate_inline_workflow_template_rest_interceptors(null_interceptor ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_instantiate_inline_workflow_template", - ) as post, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_instantiate_inline_workflow_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "pre_instantiate_inline_workflow_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_instantiate_inline_workflow_template", + ) as post, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_instantiate_inline_workflow_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_instantiate_inline_workflow_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7231,8 +7250,9 @@ def test_update_workflow_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7675,20 +7695,22 @@ def test_update_workflow_template_rest_interceptors(null_interceptor): ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_update_workflow_template", - ) as post, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_update_workflow_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "pre_update_workflow_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_update_workflow_template", + ) as post, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_update_workflow_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_update_workflow_template", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7746,8 +7768,9 @@ def test_list_workflow_templates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7812,19 +7835,22 @@ def test_list_workflow_templates_rest_interceptors(null_interceptor): ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_list_workflow_templates", - ) as post, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "post_list_workflow_templates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, "pre_list_workflow_templates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_list_workflow_templates", + ) as post, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "post_list_workflow_templates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_list_workflow_templates", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7884,8 +7910,9 @@ def test_delete_workflow_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7944,14 +7971,14 @@ def test_delete_workflow_template_rest_interceptors(null_interceptor): ) client = WorkflowTemplateServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WorkflowTemplateServiceRestInterceptor, - "pre_delete_workflow_template", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WorkflowTemplateServiceRestInterceptor, + "pre_delete_workflow_template", + ) as pre, + ): pre.assert_not_called() pb_message = workflow_templates.DeleteWorkflowTemplateRequest.pb( workflow_templates.DeleteWorkflowTemplateRequest() @@ -7998,8 +8025,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8060,8 +8088,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8122,8 +8151,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8184,8 +8214,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8246,8 +8277,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8308,8 +8340,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8370,8 +8403,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8668,11 +8702,14 @@ def test_workflow_template_service_base_transport(): def test_workflow_template_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dataproc_v1.services.workflow_template_service.transports.WorkflowTemplateServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dataproc_v1.services.workflow_template_service.transports.WorkflowTemplateServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowTemplateServiceTransport( @@ -8689,9 +8726,12 @@ def test_workflow_template_service_base_transport_with_credentials_file(): def test_workflow_template_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dataproc_v1.services.workflow_template_service.transports.WorkflowTemplateServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dataproc_v1.services.workflow_template_service.transports.WorkflowTemplateServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowTemplateServiceTransport() @@ -8765,11 +8805,12 @@ def test_workflow_template_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9476,6 +9517,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = WorkflowTemplateServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9615,6 +9688,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = WorkflowTemplateServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9760,6 +9865,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = WorkflowTemplateServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9905,6 +10044,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = WorkflowTemplateServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10069,6 +10242,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = WorkflowTemplateServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10236,6 +10444,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = WorkflowTemplateServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10413,6 +10656,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = WorkflowTemplateServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = WorkflowTemplateServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = WorkflowTemplateServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/async_client.py b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/async_client.py index 03c287fc3cd3..7b684f0e42db 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/async_client.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/async_client.py @@ -242,7 +242,7 @@ def transport(self) -> DatastoreAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1155,7 +1155,7 @@ async def sample_list_indexes(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1181,8 +1181,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1191,7 +1195,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1199,7 +1203,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1210,7 +1214,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1236,8 +1240,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1246,7 +1254,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1254,7 +1262,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1265,7 +1273,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1295,8 +1303,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1305,7 +1317,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1313,7 +1325,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1321,7 +1333,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1350,8 +1362,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1360,7 +1376,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1368,7 +1384,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/client.py b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/client.py index 7412794150ff..45015e3ff988 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/client.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/client.py @@ -168,7 +168,7 @@ class DatastoreAdminClient(metaclass=DatastoreAdminClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -176,7 +176,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -186,6 +186,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -471,7 +475,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = DatastoreAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1562,7 +1566,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1588,8 +1592,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1598,7 +1606,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1607,7 +1615,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1621,7 +1629,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1647,8 +1655,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1657,7 +1669,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1666,7 +1678,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1680,7 +1692,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1710,8 +1722,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1720,7 +1736,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1728,7 +1744,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1736,7 +1752,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1765,8 +1781,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1775,7 +1795,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1783,7 +1803,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/README.rst b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/README.rst index fe3ac4f18793..b8f2321a7b15 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/README.rst +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DatastoreAdminTransport` is the ABC for all transports. -- public child `DatastoreAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DatastoreAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDatastoreAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DatastoreAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DatastoreAdminTransport`` is the ABC for all transports. + +- public child ``DatastoreAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DatastoreAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDatastoreAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DatastoreAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/base.py b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/base.py index dabd68138dbf..a13810c04fe2 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/base.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc.py b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc.py index ae5f131d9a57..7f5529b8298a 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc_asyncio.py b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc_asyncio.py index c9cc0919e6d7..1ea79e34cec2 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -289,6 +289,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/rest.py b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/rest.py index febe8c60a838..6c3b6374cab0 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/rest.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_admin_v1/services/datastore_admin/transports/rest.py @@ -629,6 +629,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DatastoreAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/async_client.py b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/async_client.py index 6d01d7e531d0..e478a3ea72ee 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/async_client.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> DatastoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1292,7 +1292,7 @@ async def sample_reserve_ids(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1318,8 +1318,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1328,7 +1332,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1336,7 +1340,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1347,7 +1351,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1373,8 +1377,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1383,7 +1391,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1391,7 +1399,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1402,7 +1410,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1432,8 +1440,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1442,7 +1454,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1450,7 +1462,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1458,7 +1470,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1487,8 +1499,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1497,7 +1513,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1505,7 +1521,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/client.py b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/client.py index 10f2e7aef431..5115eed8f4ad 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/client.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/client.py @@ -124,7 +124,7 @@ class DatastoreClient(metaclass=DatastoreClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -427,7 +431,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -524,7 +528,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -620,7 +624,7 @@ def __init__( self._universe_domain = DatastoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1702,7 +1706,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1728,8 +1732,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1738,7 +1746,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1747,7 +1755,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1761,7 +1769,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1787,8 +1795,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1797,7 +1809,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1806,7 +1818,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1820,7 +1832,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1850,8 +1862,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1860,7 +1876,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1868,7 +1884,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1876,7 +1892,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1905,8 +1921,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1915,7 +1935,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1923,7 +1943,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/README.rst b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/README.rst index 77f9e34e5dea..7ba6fa034753 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/README.rst +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DatastoreTransport` is the ABC for all transports. -- public child `DatastoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DatastoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDatastoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DatastoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DatastoreTransport`` is the ABC for all transports. + +- public child ``DatastoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DatastoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDatastoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DatastoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/base.py b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/base.py index 7794fca76d73..ff53fb2addcc 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/base.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc.py b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc.py index 280eb45a0674..dc2f5e6a1754 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc_asyncio.py b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc_asyncio.py index f9a47846898b..644cd06b9ddb 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/rest.py b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/rest.py index ff4242b98754..f00e17aee4ec 100644 --- a/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/rest.py +++ b/packages/google-cloud-datastore/google/cloud/datastore_v1/services/datastore/transports/rest.py @@ -688,6 +688,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DatastoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-datastore/noxfile.py b/packages/google-cloud-datastore/noxfile.py index e35c17b97b4e..20f8cd7ba615 100644 --- a/packages/google-cloud-datastore/noxfile.py +++ b/packages/google-cloud-datastore/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,9 @@ def mypy(session): "mypy", "-p", "google", + # TODO(https://github.com/googleapis/google-cloud-python/issues/16083) + # "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +299,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -534,7 +539,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -629,7 +634,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-datastore/setup.py b/packages/google-cloud-datastore/setup.py index 04dc341f8129..e216119b2151 100644 --- a/packages/google-cloud-datastore/setup.py +++ b/packages/google-cloud-datastore/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -48,7 +48,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-datastore" @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-datastore/testing/constraints-3.7.txt b/packages/google-cloud-datastore/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-datastore/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-datastore/testing/constraints-3.8.txt b/packages/google-cloud-datastore/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-datastore/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-datastore/testing/constraints-3.9.txt b/packages/google-cloud-datastore/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-datastore/testing/constraints-3.9.txt +++ b/packages/google-cloud-datastore/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-datastore/tests/unit/gapic/datastore_admin_v1/test_datastore_admin.py b/packages/google-cloud-datastore/tests/unit/gapic/datastore_admin_v1/test_datastore_admin.py index 8a69c0863882..e67aa9f8ae15 100644 --- a/packages/google-cloud-datastore/tests/unit/gapic/datastore_admin_v1/test_datastore_admin.py +++ b/packages/google-cloud-datastore/tests/unit/gapic/datastore_admin_v1/test_datastore_admin.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DatastoreAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): assert ( DatastoreAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DatastoreAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1286,11 +1291,13 @@ def test_datastore_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4248,8 +4255,9 @@ def test_export_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4306,19 +4314,21 @@ def test_export_entities_rest_interceptors(null_interceptor): ) client = DatastoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_export_entities" - ) as post, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_export_entities_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "pre_export_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_export_entities" + ) as post, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, + "post_export_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "pre_export_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4371,8 +4381,9 @@ def test_import_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4429,19 +4440,21 @@ def test_import_entities_rest_interceptors(null_interceptor): ) client = DatastoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_import_entities" - ) as post, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_import_entities_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "pre_import_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_import_entities" + ) as post, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, + "post_import_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "pre_import_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4492,8 +4505,9 @@ def test_create_index_rest_bad_request(request_type=datastore_admin.CreateIndexR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4625,19 +4639,20 @@ def test_create_index_rest_interceptors(null_interceptor): ) client = DatastoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_create_index" - ) as post, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_create_index_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "pre_create_index" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_create_index" + ) as post, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_create_index_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "pre_create_index" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4688,8 +4703,9 @@ def test_delete_index_rest_bad_request(request_type=datastore_admin.DeleteIndexR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4746,19 +4762,20 @@ def test_delete_index_rest_interceptors(null_interceptor): ) client = DatastoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_delete_index" - ) as post, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_delete_index_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "pre_delete_index" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_delete_index" + ) as post, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_delete_index_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "pre_delete_index" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4809,8 +4826,9 @@ def test_get_index_rest_bad_request(request_type=datastore_admin.GetIndexRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4881,17 +4899,19 @@ def test_get_index_rest_interceptors(null_interceptor): ) client = DatastoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_get_index" - ) as post, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_get_index_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "pre_get_index" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_get_index" + ) as post, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_get_index_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "pre_get_index" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4942,8 +4962,9 @@ def test_list_indexes_rest_bad_request(request_type=datastore_admin.ListIndexesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5006,17 +5027,19 @@ def test_list_indexes_rest_interceptors(null_interceptor): ) client = DatastoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_list_indexes" - ) as post, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "post_list_indexes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreAdminRestInterceptor, "pre_list_indexes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_list_indexes" + ) as post, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "post_list_indexes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreAdminRestInterceptor, "pre_list_indexes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5076,8 +5099,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5138,8 +5162,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5200,8 +5225,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5260,8 +5286,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5520,11 +5547,14 @@ def test_datastore_admin_base_transport(): def test_datastore_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datastore_admin_v1.services.datastore_admin.transports.DatastoreAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datastore_admin_v1.services.datastore_admin.transports.DatastoreAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastoreAdminTransport( @@ -5544,9 +5574,12 @@ def test_datastore_admin_base_transport_with_credentials_file(): def test_datastore_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datastore_admin_v1.services.datastore_admin.transports.DatastoreAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datastore_admin_v1.services.datastore_admin.transports.DatastoreAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastoreAdminTransport() @@ -5624,11 +5657,12 @@ def test_datastore_admin_transport_auth_gdch_credentials(transport_class): def test_datastore_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6217,6 +6251,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DatastoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DatastoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DatastoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6356,6 +6422,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DatastoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DatastoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DatastoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6501,6 +6599,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DatastoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DatastoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DatastoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6646,6 +6778,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DatastoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DatastoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DatastoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datastore/tests/unit/gapic/datastore_v1/test_datastore.py b/packages/google-cloud-datastore/tests/unit/gapic/datastore_v1/test_datastore.py index 64f86ee7dd1f..10b737ec6dac 100644 --- a/packages/google-cloud-datastore/tests/unit/gapic/datastore_v1/test_datastore.py +++ b/packages/google-cloud-datastore/tests/unit/gapic/datastore_v1/test_datastore.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DatastoreClient._get_default_mtls_endpoint(None) is None assert DatastoreClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -145,6 +146,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DatastoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DatastoreClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1245,11 +1249,13 @@ def test_datastore_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6212,8 +6218,9 @@ def test_lookup_rest_bad_request(request_type=datastore.LookupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6274,17 +6281,15 @@ def test_lookup_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_lookup" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_lookup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_lookup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DatastoreRestInterceptor, "post_lookup") as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_lookup_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DatastoreRestInterceptor, "pre_lookup") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6333,8 +6338,9 @@ def test_run_query_rest_bad_request(request_type=datastore.RunQueryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6395,17 +6401,17 @@ def test_run_query_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_run_query" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_run_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_run_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_run_query" + ) as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_run_query_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DatastoreRestInterceptor, "pre_run_query") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6456,8 +6462,9 @@ def test_run_aggregation_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6518,17 +6525,20 @@ def test_run_aggregation_query_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_run_aggregation_query" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_run_aggregation_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_run_aggregation_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_run_aggregation_query" + ) as post, + mock.patch.object( + transports.DatastoreRestInterceptor, + "post_run_aggregation_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreRestInterceptor, "pre_run_aggregation_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6586,8 +6596,9 @@ def test_begin_transaction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6648,17 +6659,19 @@ def test_begin_transaction_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_begin_transaction" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_begin_transaction_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_begin_transaction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_begin_transaction" + ) as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_begin_transaction_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreRestInterceptor, "pre_begin_transaction" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6711,8 +6724,9 @@ def test_commit_rest_bad_request(request_type=datastore.CommitRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6773,17 +6787,15 @@ def test_commit_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_commit" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_commit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_commit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DatastoreRestInterceptor, "post_commit") as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_commit_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DatastoreRestInterceptor, "pre_commit") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6832,8 +6844,9 @@ def test_rollback_rest_bad_request(request_type=datastore.RollbackRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6891,17 +6904,15 @@ def test_rollback_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_rollback" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_rollback_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_rollback" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.DatastoreRestInterceptor, "post_rollback") as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_rollback_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DatastoreRestInterceptor, "pre_rollback") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6950,8 +6961,9 @@ def test_allocate_ids_rest_bad_request(request_type=datastore.AllocateIdsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7009,17 +7021,19 @@ def test_allocate_ids_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_allocate_ids" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_allocate_ids_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_allocate_ids" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_allocate_ids" + ) as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_allocate_ids_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreRestInterceptor, "pre_allocate_ids" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7070,8 +7084,9 @@ def test_reserve_ids_rest_bad_request(request_type=datastore.ReserveIdsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7129,17 +7144,19 @@ def test_reserve_ids_rest_interceptors(null_interceptor): ) client = DatastoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastoreRestInterceptor, "post_reserve_ids" - ) as post, mock.patch.object( - transports.DatastoreRestInterceptor, "post_reserve_ids_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastoreRestInterceptor, "pre_reserve_ids" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_reserve_ids" + ) as post, + mock.patch.object( + transports.DatastoreRestInterceptor, "post_reserve_ids_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastoreRestInterceptor, "pre_reserve_ids" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7194,8 +7211,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7256,8 +7274,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7318,8 +7337,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7378,8 +7398,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8038,11 +8059,14 @@ def test_datastore_base_transport(): def test_datastore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datastore_v1.services.datastore.transports.DatastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datastore_v1.services.datastore.transports.DatastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastoreTransport( @@ -8062,9 +8086,12 @@ def test_datastore_base_transport_with_credentials_file(): def test_datastore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datastore_v1.services.datastore.transports.DatastoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datastore_v1.services.datastore.transports.DatastoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastoreTransport() @@ -8142,11 +8169,12 @@ def test_datastore_transport_auth_gdch_credentials(transport_class): def test_datastore_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8696,6 +8724,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DatastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DatastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DatastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8835,6 +8895,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DatastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DatastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DatastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8980,6 +9072,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DatastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DatastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DatastoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9125,6 +9251,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DatastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DatastoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DatastoreClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/async_client.py b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/async_client.py index 1e8280a91cc2..600cc7725a60 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/async_client.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/async_client.py @@ -209,7 +209,7 @@ def transport(self) -> DatastreamTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3608,7 +3608,7 @@ async def sample_delete_route(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3634,8 +3634,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3644,7 +3648,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3652,7 +3656,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3663,7 +3667,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3689,8 +3693,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3699,7 +3707,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3707,7 +3715,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3718,7 +3726,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3748,8 +3756,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3758,7 +3770,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3766,7 +3778,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3774,7 +3786,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3803,8 +3815,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3813,7 +3829,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3821,7 +3837,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3829,7 +3845,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3855,8 +3871,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3865,7 +3885,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3873,7 +3893,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3884,7 +3904,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3910,8 +3930,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3920,7 +3944,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3928,7 +3952,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/client.py b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/client.py index 638b7a7337a4..aa1f7d85713d 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/client.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/client.py @@ -121,7 +121,7 @@ class DatastreamClient(metaclass=DatastreamClientMeta): """Datastream service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -579,7 +583,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -676,7 +680,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -772,7 +776,7 @@ def __init__( self._universe_domain = DatastreamClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4106,7 +4110,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4132,8 +4136,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4142,7 +4150,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4151,7 +4159,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4165,7 +4173,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4191,8 +4199,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4201,7 +4213,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4210,7 +4222,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4224,7 +4236,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4254,8 +4266,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4264,7 +4280,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4272,7 +4288,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4280,7 +4296,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4309,8 +4325,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4319,7 +4339,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4327,7 +4347,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4335,7 +4355,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4361,8 +4381,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4371,7 +4395,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4380,7 +4404,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4394,7 +4418,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4420,8 +4444,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4430,7 +4458,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4439,7 +4467,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/README.rst b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/README.rst index 54b7bf22552e..7ab404ec6e1b 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/README.rst +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DatastreamTransport` is the ABC for all transports. -- public child `DatastreamGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DatastreamGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDatastreamRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DatastreamRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DatastreamTransport`` is the ABC for all transports. + +- public child ``DatastreamGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DatastreamGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDatastreamRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DatastreamRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/base.py b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/base.py index 13e4b1f6bb53..bffd8d47faee 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/base.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc.py b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc.py index 490c5a211c09..3d1a82b88cdb 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py index f0be7c19bb40..ee23b77aee1c 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/rest.py b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/rest.py index 40fc992c999f..5b2418c5846f 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/rest.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1/services/datastream/transports/rest.py @@ -1766,6 +1766,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DatastreamRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/async_client.py b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/async_client.py index 6b012a074d3a..0eab3b2bf560 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/async_client.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> DatastreamTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/client.py b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/client.py index 98bc40cd152e..b576791f7d20 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/client.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/client.py @@ -115,7 +115,7 @@ class DatastreamClient(metaclass=DatastreamClientMeta): """Datastream service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -508,7 +512,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -605,7 +609,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -701,7 +705,7 @@ def __init__( self._universe_domain = DatastreamClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/README.rst b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/README.rst index 54b7bf22552e..7ab404ec6e1b 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/README.rst +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DatastreamTransport` is the ABC for all transports. -- public child `DatastreamGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DatastreamGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDatastreamRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DatastreamRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DatastreamTransport`` is the ABC for all transports. + +- public child ``DatastreamGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DatastreamGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDatastreamRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DatastreamRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py index cb5280b434c0..8c8fb768d8c7 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py index 1e4263b3c5cd..b578fe4f9625 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py index 79fbe2b8a46b..ba96df9cb958 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/rest.py b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/rest.py index fca0fb0776cb..901924e11588 100644 --- a/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/rest.py +++ b/packages/google-cloud-datastream/google/cloud/datastream_v1alpha1/services/datastream/transports/rest.py @@ -1325,6 +1325,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DatastreamRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-datastream/noxfile.py b/packages/google-cloud-datastream/noxfile.py index 1faf13b389c9..5a58bc21e0a7 100644 --- a/packages/google-cloud-datastream/noxfile.py +++ b/packages/google-cloud-datastream/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-datastream/setup.py b/packages/google-cloud-datastream/setup.py index ff029ef3f5c2..1075d2ddc5e2 100644 --- a/packages/google-cloud-datastream/setup.py +++ b/packages/google-cloud-datastream/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-datastream/testing/constraints-3.7.txt b/packages/google-cloud-datastream/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-datastream/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-datastream/testing/constraints-3.8.txt b/packages/google-cloud-datastream/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-datastream/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-datastream/testing/constraints-3.9.txt b/packages/google-cloud-datastream/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-datastream/testing/constraints-3.9.txt +++ b/packages/google-cloud-datastream/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1/test_datastream.py b/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1/test_datastream.py index 44eafa543b6a..db28b2311c53 100644 --- a/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1/test_datastream.py +++ b/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1/test_datastream.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DatastreamClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DatastreamClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DatastreamClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1254,11 +1258,13 @@ def test_datastream_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -17907,8 +17913,9 @@ def test_list_connection_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17973,18 +17980,20 @@ def test_list_connection_profiles_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_connection_profiles" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_list_connection_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_connection_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_connection_profiles" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_list_connection_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_connection_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18044,8 +18053,9 @@ def test_get_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18116,18 +18126,20 @@ def test_get_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_get_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_get_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18185,8 +18197,9 @@ def test_create_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18432,20 +18445,21 @@ def test_create_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_create_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_create_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18502,8 +18516,9 @@ def test_update_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18753,20 +18768,21 @@ def test_update_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_update_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_update_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_update_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_update_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_update_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_update_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18821,8 +18837,9 @@ def test_delete_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18881,20 +18898,21 @@ def test_delete_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_delete_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_delete_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18947,8 +18965,9 @@ def test_discover_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19008,18 +19027,20 @@ def test_discover_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_discover_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_discover_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_discover_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_discover_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_discover_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_discover_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19075,8 +19096,9 @@ def test_list_streams_rest_bad_request(request_type=datastream.ListStreamsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19141,17 +19163,19 @@ def test_list_streams_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_streams" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_streams_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_streams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_streams" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_streams_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_streams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19202,8 +19226,9 @@ def test_get_stream_rest_bad_request(request_type=datastream.GetStreamRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19279,17 +19304,19 @@ def test_get_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19340,8 +19367,9 @@ def test_create_stream_rest_bad_request(request_type=datastream.CreateStreamRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19697,19 +19725,20 @@ def test_create_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19760,8 +19789,9 @@ def test_update_stream_rest_bad_request(request_type=datastream.UpdateStreamRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20119,19 +20149,20 @@ def test_update_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_update_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_update_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_update_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_update_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_update_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_update_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20180,8 +20211,9 @@ def test_delete_stream_rest_bad_request(request_type=datastream.DeleteStreamRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20238,19 +20270,20 @@ def test_delete_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20299,8 +20332,9 @@ def test_run_stream_rest_bad_request(request_type=datastream.RunStreamRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20357,19 +20391,20 @@ def test_run_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_run_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_run_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_run_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_run_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_run_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_run_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20422,8 +20457,9 @@ def test_get_stream_object_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20490,17 +20526,19 @@ def test_get_stream_object_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_stream_object" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_stream_object_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_stream_object" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_stream_object" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_stream_object_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_stream_object" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20555,8 +20593,9 @@ def test_lookup_stream_object_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20621,17 +20660,20 @@ def test_lookup_stream_object_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_lookup_stream_object" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_lookup_stream_object_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_lookup_stream_object" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_lookup_stream_object" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_lookup_stream_object_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_lookup_stream_object" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20686,8 +20728,9 @@ def test_list_stream_objects_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20750,17 +20793,20 @@ def test_list_stream_objects_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_stream_objects" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_stream_objects_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_stream_objects" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_stream_objects" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_list_stream_objects_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_stream_objects" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20820,8 +20866,9 @@ def test_start_backfill_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20883,17 +20930,20 @@ def test_start_backfill_job_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_start_backfill_job" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_start_backfill_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_start_backfill_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_start_backfill_job" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_start_backfill_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_start_backfill_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20953,8 +21003,9 @@ def test_stop_backfill_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21016,17 +21067,19 @@ def test_stop_backfill_job_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_stop_backfill_job" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_stop_backfill_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_stop_backfill_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_stop_backfill_job" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_stop_backfill_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_stop_backfill_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21081,8 +21134,9 @@ def test_fetch_static_ips_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21147,17 +21201,19 @@ def test_fetch_static_ips_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_fetch_static_ips" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_fetch_static_ips_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_fetch_static_ips" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_fetch_static_ips" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_fetch_static_ips_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_fetch_static_ips" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21212,8 +21268,9 @@ def test_create_private_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21358,20 +21415,21 @@ def test_create_private_connection_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_private_connection" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_create_private_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_private_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_private_connection" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_create_private_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_private_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21426,8 +21484,9 @@ def test_get_private_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21500,18 +21559,20 @@ def test_get_private_connection_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_private_connection" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_get_private_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_private_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_private_connection" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_get_private_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_private_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21569,8 +21630,9 @@ def test_list_private_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21635,18 +21697,20 @@ def test_list_private_connections_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_private_connections" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_list_private_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_private_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_private_connections" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_list_private_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_private_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21706,8 +21770,9 @@ def test_delete_private_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21766,20 +21831,21 @@ def test_delete_private_connection_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_private_connection" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_delete_private_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_private_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_private_connection" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_delete_private_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_private_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21832,8 +21898,9 @@ def test_create_route_rest_bad_request(request_type=datastream.CreateRouteReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21968,19 +22035,20 @@ def test_create_route_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_route" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_route_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_route" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_route" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_route_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_route" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22031,8 +22099,9 @@ def test_get_route_rest_bad_request(request_type=datastream.GetRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22103,17 +22172,17 @@ def test_get_route_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_route" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_route_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_route" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_route" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_route_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DatastreamRestInterceptor, "pre_get_route") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22164,8 +22233,9 @@ def test_list_routes_rest_bad_request(request_type=datastream.ListRoutesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22232,17 +22302,19 @@ def test_list_routes_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_routes" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_routes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_routes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_routes" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_routes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_routes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22295,8 +22367,9 @@ def test_delete_route_rest_bad_request(request_type=datastream.DeleteRouteReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22355,19 +22428,20 @@ def test_delete_route_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_route" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_route_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_route" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_route" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_route_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_route" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22418,8 +22492,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22478,8 +22553,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22540,8 +22616,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22602,8 +22679,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22664,8 +22742,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22726,8 +22805,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23438,11 +23518,14 @@ def test_datastream_base_transport(): def test_datastream_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datastream_v1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datastream_v1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastreamTransport( @@ -23459,9 +23542,12 @@ def test_datastream_base_transport_with_credentials_file(): def test_datastream_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datastream_v1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datastream_v1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastreamTransport() @@ -23533,11 +23619,12 @@ def test_datastream_transport_auth_gdch_credentials(transport_class): def test_datastream_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -24363,6 +24450,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DatastreamAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24502,6 +24621,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DatastreamAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24647,6 +24798,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DatastreamAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24792,6 +24977,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DatastreamAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24937,6 +25156,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DatastreamAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25078,6 +25331,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DatastreamAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1alpha1/test_datastream.py b/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1alpha1/test_datastream.py index 53124688913b..8e2b34d8edd8 100644 --- a/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1alpha1/test_datastream.py +++ b/packages/google-cloud-datastream/tests/unit/gapic/datastream_v1alpha1/test_datastream.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DatastreamClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DatastreamClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DatastreamClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1248,11 +1252,13 @@ def test_datastream_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -14754,8 +14760,9 @@ def test_list_connection_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14820,18 +14827,20 @@ def test_list_connection_profiles_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_connection_profiles" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_list_connection_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_connection_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_connection_profiles" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_list_connection_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_connection_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14891,8 +14900,9 @@ def test_get_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14959,18 +14969,20 @@ def test_get_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_get_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_get_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15028,8 +15040,9 @@ def test_create_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15200,20 +15213,21 @@ def test_create_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_create_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_create_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15270,8 +15284,9 @@ def test_update_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15446,20 +15461,21 @@ def test_update_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_update_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_update_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_update_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_update_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_update_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_update_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15514,8 +15530,9 @@ def test_delete_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15574,20 +15591,21 @@ def test_delete_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_delete_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_delete_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15640,8 +15658,9 @@ def test_discover_connection_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15701,18 +15720,20 @@ def test_discover_connection_profile_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_discover_connection_profile" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_discover_connection_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_discover_connection_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_discover_connection_profile" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_discover_connection_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_discover_connection_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15768,8 +15789,9 @@ def test_list_streams_rest_bad_request(request_type=datastream.ListStreamsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15834,17 +15856,19 @@ def test_list_streams_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_streams" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_streams_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_streams" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_streams" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_streams_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_streams" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15895,8 +15919,9 @@ def test_get_stream_rest_bad_request(request_type=datastream.GetStreamRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15963,17 +15988,19 @@ def test_get_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16024,8 +16051,9 @@ def test_create_stream_rest_bad_request(request_type=datastream.CreateStreamRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16236,19 +16264,20 @@ def test_create_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16299,8 +16328,9 @@ def test_update_stream_rest_bad_request(request_type=datastream.UpdateStreamRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16513,19 +16543,20 @@ def test_update_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_update_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_update_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_update_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_update_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_update_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_update_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16574,8 +16605,9 @@ def test_delete_stream_rest_bad_request(request_type=datastream.DeleteStreamRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16632,19 +16664,20 @@ def test_delete_stream_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_stream" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_stream_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_stream" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_stream" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_stream_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_stream" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16693,8 +16726,9 @@ def test_fetch_errors_rest_bad_request(request_type=datastream.FetchErrorsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16751,19 +16785,20 @@ def test_fetch_errors_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_fetch_errors" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_fetch_errors_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_fetch_errors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_fetch_errors" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_fetch_errors_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_fetch_errors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16814,8 +16849,9 @@ def test_fetch_static_ips_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16880,17 +16916,19 @@ def test_fetch_static_ips_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_fetch_static_ips" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_fetch_static_ips_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_fetch_static_ips" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_fetch_static_ips" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_fetch_static_ips_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_fetch_static_ips" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16945,8 +16983,9 @@ def test_create_private_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17088,20 +17127,21 @@ def test_create_private_connection_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_private_connection" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_create_private_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_private_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_private_connection" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_create_private_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_private_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17156,8 +17196,9 @@ def test_get_private_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17226,18 +17267,20 @@ def test_get_private_connection_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_private_connection" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_get_private_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_private_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_private_connection" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_get_private_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_get_private_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17295,8 +17338,9 @@ def test_list_private_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17361,18 +17405,20 @@ def test_list_private_connections_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_private_connections" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_list_private_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_private_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_private_connections" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_list_private_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_private_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17432,8 +17478,9 @@ def test_delete_private_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17492,20 +17539,21 @@ def test_delete_private_connection_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_private_connection" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, - "post_delete_private_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_private_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_private_connection" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, + "post_delete_private_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_private_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17558,8 +17606,9 @@ def test_create_route_rest_bad_request(request_type=datastream.CreateRouteReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17694,19 +17743,20 @@ def test_create_route_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_route" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_create_route_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_create_route" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_route" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_create_route_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_create_route" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17757,8 +17807,9 @@ def test_get_route_rest_bad_request(request_type=datastream.GetRouteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17829,17 +17880,17 @@ def test_get_route_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_route" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_get_route_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_get_route" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_route" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_get_route_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DatastreamRestInterceptor, "pre_get_route") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17890,8 +17941,9 @@ def test_list_routes_rest_bad_request(request_type=datastream.ListRoutesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17958,17 +18010,19 @@ def test_list_routes_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_routes" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_list_routes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_list_routes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_routes" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_list_routes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_list_routes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18021,8 +18075,9 @@ def test_delete_route_rest_bad_request(request_type=datastream.DeleteRouteReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18081,19 +18136,20 @@ def test_delete_route_rest_interceptors(null_interceptor): ) client = DatastreamClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_route" - ) as post, mock.patch.object( - transports.DatastreamRestInterceptor, "post_delete_route_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DatastreamRestInterceptor, "pre_delete_route" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_route" + ) as post, + mock.patch.object( + transports.DatastreamRestInterceptor, "post_delete_route_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DatastreamRestInterceptor, "pre_delete_route" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18675,11 +18731,14 @@ def test_datastream_base_transport(): def test_datastream_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.datastream_v1alpha1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.datastream_v1alpha1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastreamTransport( @@ -18696,9 +18755,12 @@ def test_datastream_base_transport_with_credentials_file(): def test_datastream_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.datastream_v1alpha1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.datastream_v1alpha1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatastreamTransport() @@ -18770,11 +18832,12 @@ def test_datastream_transport_auth_gdch_credentials(transport_class): def test_datastream_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/async_client.py b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/async_client.py index c89859ad1b14..ebdec548dd01 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/async_client.py +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/async_client.py @@ -234,7 +234,7 @@ def transport(self) -> CloudDeployTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -6110,7 +6110,7 @@ async def sample_cancel_automation_run(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6136,8 +6136,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6146,7 +6150,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6154,7 +6158,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6165,7 +6169,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6191,8 +6195,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6201,7 +6209,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6209,7 +6217,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6220,7 +6228,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6250,8 +6258,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6260,7 +6272,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6268,7 +6280,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6276,7 +6288,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6305,8 +6317,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6315,7 +6331,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6323,7 +6339,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6331,7 +6347,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6423,8 +6439,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6433,7 +6453,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6441,7 +6463,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6452,7 +6474,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6545,8 +6567,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6555,7 +6581,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6563,7 +6591,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6574,7 +6602,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6605,8 +6633,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6617,7 +6649,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6625,7 +6659,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6636,7 +6670,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6662,8 +6696,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6672,7 +6710,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6680,7 +6718,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6691,7 +6729,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6717,8 +6755,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6727,7 +6769,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6735,7 +6777,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/client.py b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/client.py index d968ea46f4f5..403c05334013 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/client.py +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/client.py @@ -124,7 +124,7 @@ class CloudDeployClient(metaclass=CloudDeployClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -820,7 +824,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -917,7 +921,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1013,7 +1017,7 @@ def __init__( self._universe_domain = CloudDeployClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6758,7 +6762,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6784,8 +6788,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6794,7 +6802,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6803,7 +6811,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6817,7 +6825,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6843,8 +6851,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6853,7 +6865,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6862,7 +6874,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6876,7 +6888,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6906,8 +6918,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6916,7 +6932,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6924,7 +6940,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6932,7 +6948,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6961,8 +6977,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6971,7 +6991,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6979,7 +6999,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6987,7 +7007,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7079,8 +7099,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7089,7 +7113,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -7098,7 +7124,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7112,7 +7138,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7205,8 +7231,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7215,7 +7245,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -7224,7 +7256,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7238,7 +7270,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7269,8 +7301,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7279,7 +7315,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -7288,7 +7326,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7302,7 +7340,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7328,8 +7366,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7338,7 +7380,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7347,7 +7389,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7361,7 +7403,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7387,8 +7429,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7397,7 +7443,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7406,7 +7452,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/README.rst b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/README.rst index 4970072ce71a..0ffd8c5d1e75 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/README.rst +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudDeployTransport` is the ABC for all transports. -- public child `CloudDeployGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudDeployGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudDeployRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudDeployRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudDeployTransport`` is the ABC for all transports. + +- public child ``CloudDeployGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudDeployGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudDeployRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudDeployRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/base.py b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/base.py index 99a4a8bd2b1b..255df6a06511 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/base.py +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc.py b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc.py index 2161aa0933ce..090e62edabc0 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc.py +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc_asyncio.py b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc_asyncio.py index eb8be0f3cc37..f307068c4a66 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc_asyncio.py +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/rest.py b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/rest.py index bb575f017df2..8f7d7af4143f 100644 --- a/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/rest.py +++ b/packages/google-cloud-deploy/google/cloud/deploy_v1/services/cloud_deploy/transports/rest.py @@ -2910,6 +2910,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudDeployRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-deploy/noxfile.py b/packages/google-cloud-deploy/noxfile.py index 5d29279f6b92..8761e4341b78 100644 --- a/packages/google-cloud-deploy/noxfile.py +++ b/packages/google-cloud-deploy/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-deploy/setup.py b/packages/google-cloud-deploy/setup.py index a11666b460c7..5e0e8c99d11b 100644 --- a/packages/google-cloud-deploy/setup.py +++ b/packages/google-cloud-deploy/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-deploy/testing/constraints-3.7.txt b/packages/google-cloud-deploy/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-deploy/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-deploy/testing/constraints-3.8.txt b/packages/google-cloud-deploy/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-deploy/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-deploy/testing/constraints-3.9.txt b/packages/google-cloud-deploy/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-deploy/testing/constraints-3.9.txt +++ b/packages/google-cloud-deploy/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-deploy/tests/unit/gapic/deploy_v1/test_cloud_deploy.py b/packages/google-cloud-deploy/tests/unit/gapic/deploy_v1/test_cloud_deploy.py index b7c26bfdee73..708ba0f7b2ec 100644 --- a/packages/google-cloud-deploy/tests/unit/gapic/deploy_v1/test_cloud_deploy.py +++ b/packages/google-cloud-deploy/tests/unit/gapic/deploy_v1/test_cloud_deploy.py @@ -137,6 +137,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudDeployClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert CloudDeployClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + CloudDeployClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1261,11 +1265,13 @@ def test_cloud_deploy_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -30536,8 +30542,9 @@ def test_list_delivery_pipelines_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30602,18 +30609,20 @@ def test_list_delivery_pipelines_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_delivery_pipelines" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_list_delivery_pipelines_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_delivery_pipelines" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_delivery_pipelines" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_list_delivery_pipelines_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_delivery_pipelines" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30673,8 +30682,9 @@ def test_get_delivery_pipeline_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30747,18 +30757,20 @@ def test_get_delivery_pipeline_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_delivery_pipeline" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_get_delivery_pipeline_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_delivery_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_delivery_pipeline" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_get_delivery_pipeline_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_delivery_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30813,8 +30825,9 @@ def test_create_delivery_pipeline_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31049,20 +31062,21 @@ def test_create_delivery_pipeline_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_delivery_pipeline" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_create_delivery_pipeline_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_delivery_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_delivery_pipeline" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_create_delivery_pipeline_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_delivery_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31119,8 +31133,9 @@ def test_update_delivery_pipeline_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31359,20 +31374,21 @@ def test_update_delivery_pipeline_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_delivery_pipeline" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_update_delivery_pipeline_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_update_delivery_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_update_delivery_pipeline" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_update_delivery_pipeline_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_update_delivery_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31427,8 +31443,9 @@ def test_delete_delivery_pipeline_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31487,20 +31504,21 @@ def test_delete_delivery_pipeline_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_delivery_pipeline" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_delete_delivery_pipeline_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_delete_delivery_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_delete_delivery_pipeline" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_delete_delivery_pipeline_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_delete_delivery_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31551,8 +31569,9 @@ def test_list_targets_rest_bad_request(request_type=cloud_deploy.ListTargetsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31617,17 +31636,19 @@ def test_list_targets_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_targets" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_targets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_targets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_targets" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_targets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_targets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31684,8 +31705,9 @@ def test_rollback_target_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31747,17 +31769,19 @@ def test_rollback_target_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_rollback_target" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_rollback_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_rollback_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_rollback_target" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_rollback_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_rollback_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31813,8 +31837,9 @@ def test_get_target_rest_bad_request(request_type=cloud_deploy.GetTargetRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31887,17 +31912,19 @@ def test_get_target_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_target" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_target" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31946,8 +31973,9 @@ def test_create_target_rest_bad_request(request_type=cloud_deploy.CreateTargetRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32114,19 +32142,20 @@ def test_create_target_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_target" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_target" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32179,8 +32208,9 @@ def test_update_target_rest_bad_request(request_type=cloud_deploy.UpdateTargetRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32349,19 +32379,20 @@ def test_update_target_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_target" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_update_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_update_target" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_update_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_update_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32412,8 +32443,9 @@ def test_delete_target_rest_bad_request(request_type=cloud_deploy.DeleteTargetRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32470,19 +32502,20 @@ def test_delete_target_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_target" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_target_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_delete_target" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_delete_target" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_delete_target_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_delete_target" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32535,8 +32568,9 @@ def test_list_custom_target_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32601,18 +32635,20 @@ def test_list_custom_target_types_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_custom_target_types" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_list_custom_target_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_custom_target_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_custom_target_types" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_list_custom_target_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_custom_target_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32672,8 +32708,9 @@ def test_get_custom_target_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32746,18 +32783,20 @@ def test_get_custom_target_type_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_custom_target_type" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_get_custom_target_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_custom_target_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_custom_target_type" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_get_custom_target_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_custom_target_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32812,8 +32851,9 @@ def test_create_custom_target_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32973,20 +33013,21 @@ def test_create_custom_target_type_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_custom_target_type" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_create_custom_target_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_custom_target_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_custom_target_type" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_create_custom_target_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_custom_target_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33043,8 +33084,9 @@ def test_update_custom_target_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33208,20 +33250,21 @@ def test_update_custom_target_type_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_custom_target_type" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_update_custom_target_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_update_custom_target_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_update_custom_target_type" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_update_custom_target_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_update_custom_target_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33276,8 +33319,9 @@ def test_delete_custom_target_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33336,20 +33380,21 @@ def test_delete_custom_target_type_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_custom_target_type" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_delete_custom_target_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_delete_custom_target_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_delete_custom_target_type" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_delete_custom_target_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_delete_custom_target_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33402,8 +33447,9 @@ def test_list_releases_rest_bad_request(request_type=cloud_deploy.ListReleasesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33470,17 +33516,19 @@ def test_list_releases_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_releases" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_releases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_releases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_releases" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_releases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_releases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33535,8 +33583,9 @@ def test_get_release_rest_bad_request(request_type=cloud_deploy.GetReleaseReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33617,17 +33666,19 @@ def test_get_release_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_release" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_release" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_release_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33680,8 +33731,9 @@ def test_create_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34033,19 +34085,20 @@ def test_create_release_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_release" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_release" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_release_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34100,8 +34153,9 @@ def test_abandon_release_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34163,17 +34217,19 @@ def test_abandon_release_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_abandon_release" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_abandon_release_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_abandon_release" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_abandon_release" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_abandon_release_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_abandon_release" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34231,8 +34287,9 @@ def test_create_deploy_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34401,19 +34458,21 @@ def test_create_deploy_policy_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_deploy_policy" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_deploy_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_deploy_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_deploy_policy" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_create_deploy_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_deploy_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34470,8 +34529,9 @@ def test_update_deploy_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34644,19 +34704,21 @@ def test_update_deploy_policy_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_deploy_policy" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_deploy_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_update_deploy_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_update_deploy_policy" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_update_deploy_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_update_deploy_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34709,8 +34771,9 @@ def test_delete_deploy_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34767,19 +34830,21 @@ def test_delete_deploy_policy_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_deploy_policy" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_deploy_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_delete_deploy_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_delete_deploy_policy" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_delete_deploy_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_delete_deploy_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34832,8 +34897,9 @@ def test_list_deploy_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34898,17 +34964,20 @@ def test_list_deploy_policies_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_deploy_policies" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_deploy_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_deploy_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_deploy_policies" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_list_deploy_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_deploy_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34966,8 +35035,9 @@ def test_get_deploy_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35038,17 +35108,20 @@ def test_get_deploy_policy_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_deploy_policy" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_deploy_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_deploy_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_deploy_policy" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_get_deploy_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_deploy_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35103,8 +35176,9 @@ def test_approve_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35166,17 +35240,19 @@ def test_approve_rollout_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_approve_rollout" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_approve_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_approve_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_approve_rollout" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_approve_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_approve_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35236,8 +35312,9 @@ def test_advance_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35299,17 +35376,19 @@ def test_advance_rollout_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_advance_rollout" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_advance_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_advance_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_advance_rollout" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_advance_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_advance_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35369,8 +35448,9 @@ def test_cancel_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35432,17 +35512,19 @@ def test_cancel_rollout_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_cancel_rollout" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_cancel_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_cancel_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_cancel_rollout" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_cancel_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_cancel_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35497,8 +35579,9 @@ def test_list_rollouts_rest_bad_request(request_type=cloud_deploy.ListRolloutsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35565,17 +35648,19 @@ def test_list_rollouts_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_rollouts" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_rollouts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_rollouts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_rollouts" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_rollouts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_rollouts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35630,8 +35715,9 @@ def test_get_rollout_rest_bad_request(request_type=cloud_deploy.GetRolloutReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35725,17 +35811,19 @@ def test_get_rollout_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_rollout" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_rollout" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35788,8 +35876,9 @@ def test_create_rollout_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35993,19 +36082,20 @@ def test_create_rollout_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_rollout" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_rollout_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_rollout" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_rollout" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_rollout_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_rollout" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36058,8 +36148,9 @@ def test_ignore_job_rest_bad_request(request_type=cloud_deploy.IgnoreJobRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36121,17 +36212,19 @@ def test_ignore_job_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_ignore_job" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_ignore_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_ignore_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_ignore_job" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_ignore_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_ignore_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36184,8 +36277,9 @@ def test_retry_job_rest_bad_request(request_type=cloud_deploy.RetryJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36247,17 +36341,19 @@ def test_retry_job_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_retry_job" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_retry_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_retry_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_retry_job" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_retry_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_retry_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36310,8 +36406,9 @@ def test_list_job_runs_rest_bad_request(request_type=cloud_deploy.ListJobRunsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36378,17 +36475,19 @@ def test_list_job_runs_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_job_runs" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_job_runs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_job_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_job_runs" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_job_runs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_job_runs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36443,8 +36542,9 @@ def test_get_job_run_rest_bad_request(request_type=cloud_deploy.GetJobRunRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36519,17 +36619,19 @@ def test_get_job_run_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_job_run" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_job_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_job_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_job_run" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_job_run_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_job_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36582,8 +36684,9 @@ def test_terminate_job_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36645,17 +36748,20 @@ def test_terminate_job_run_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_terminate_job_run" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_terminate_job_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_terminate_job_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_terminate_job_run" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_terminate_job_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_terminate_job_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36711,8 +36817,9 @@ def test_get_config_rest_bad_request(request_type=cloud_deploy.GetConfigRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36777,17 +36884,19 @@ def test_get_config_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_config" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_config" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36840,8 +36949,9 @@ def test_create_automation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37038,19 +37148,21 @@ def test_create_automation_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_automation" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_create_automation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_create_automation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_create_automation" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_create_automation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_create_automation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37107,8 +37219,9 @@ def test_update_automation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37307,19 +37420,21 @@ def test_update_automation_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_automation" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_update_automation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_update_automation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_update_automation" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_update_automation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_update_automation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37374,8 +37489,9 @@ def test_delete_automation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37434,19 +37550,21 @@ def test_delete_automation_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_automation" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_delete_automation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_delete_automation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_delete_automation" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_delete_automation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_delete_automation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37501,8 +37619,9 @@ def test_get_automation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37577,17 +37696,19 @@ def test_get_automation_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_automation" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_automation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_automation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_automation" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_automation_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_automation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37642,8 +37763,9 @@ def test_list_automations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37710,17 +37832,19 @@ def test_list_automations_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_automations" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_automations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_automations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_automations" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_automations_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_automations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37780,8 +37904,9 @@ def test_get_automation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37860,17 +37985,20 @@ def test_get_automation_run_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_automation_run" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_get_automation_run_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_get_automation_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_get_automation_run" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_get_automation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_get_automation_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37925,8 +38053,9 @@ def test_list_automation_runs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37993,17 +38122,20 @@ def test_list_automation_runs_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_automation_runs" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_list_automation_runs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_list_automation_runs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_list_automation_runs" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_list_automation_runs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_list_automation_runs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38063,8 +38195,9 @@ def test_cancel_automation_run_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38126,18 +38259,20 @@ def test_cancel_automation_run_rest_interceptors(null_interceptor): ) client = CloudDeployClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudDeployRestInterceptor, "post_cancel_automation_run" - ) as post, mock.patch.object( - transports.CloudDeployRestInterceptor, - "post_cancel_automation_run_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudDeployRestInterceptor, "pre_cancel_automation_run" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudDeployRestInterceptor, "post_cancel_automation_run" + ) as post, + mock.patch.object( + transports.CloudDeployRestInterceptor, + "post_cancel_automation_run_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudDeployRestInterceptor, "pre_cancel_automation_run" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38195,8 +38330,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38255,8 +38391,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38318,8 +38455,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38383,8 +38521,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38448,8 +38587,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38512,8 +38652,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38574,8 +38715,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38636,8 +38778,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -38698,8 +38841,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39826,11 +39970,14 @@ def test_cloud_deploy_base_transport(): def test_cloud_deploy_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.deploy_v1.services.cloud_deploy.transports.CloudDeployTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.deploy_v1.services.cloud_deploy.transports.CloudDeployTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudDeployTransport( @@ -39847,9 +39994,12 @@ def test_cloud_deploy_base_transport_with_credentials_file(): def test_cloud_deploy_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.deploy_v1.services.cloud_deploy.transports.CloudDeployTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.deploy_v1.services.cloud_deploy.transports.CloudDeployTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudDeployTransport() @@ -39921,11 +40071,12 @@ def test_cloud_deploy_transport_auth_gdch_credentials(transport_class): def test_cloud_deploy_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -41105,6 +41256,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CloudDeployClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41244,6 +41427,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CloudDeployClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41389,6 +41604,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudDeployClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41534,6 +41783,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudDeployClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41679,6 +41962,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudDeployClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41820,6 +42137,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CloudDeployClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -41984,6 +42335,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = CloudDeployClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42151,6 +42537,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = CloudDeployClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42328,6 +42749,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = CloudDeployClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = CloudDeployAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = CloudDeployClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/async_client.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/async_client.py index e33286efdf64..c3e07c570ef9 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/async_client.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> DeveloperConnectTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3672,7 +3672,7 @@ async def sample_finish_o_auth(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3698,8 +3698,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3708,7 +3712,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3716,7 +3720,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3727,7 +3731,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3753,8 +3757,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3763,7 +3771,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3771,7 +3779,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3782,7 +3790,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3812,8 +3820,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3822,7 +3834,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3830,7 +3842,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3838,7 +3850,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3867,8 +3879,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3877,7 +3893,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3885,7 +3901,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3893,7 +3909,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3919,8 +3935,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3929,7 +3949,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3937,7 +3957,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3948,7 +3968,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3974,8 +3994,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3984,7 +4008,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3992,7 +4016,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/client.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/client.py index 74d30de7e51b..b0a13a06161c 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/client.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/client.py @@ -117,7 +117,7 @@ class DeveloperConnectClient(metaclass=DeveloperConnectClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -606,7 +610,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -703,7 +707,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -801,7 +805,7 @@ def __init__( self._universe_domain = DeveloperConnectClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4190,7 +4194,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4216,8 +4220,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4226,7 +4234,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4235,7 +4243,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4249,7 +4257,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4275,8 +4283,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4285,7 +4297,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4294,7 +4306,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4308,7 +4320,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4338,8 +4350,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4348,7 +4364,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4356,7 +4372,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4364,7 +4380,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4393,8 +4409,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4403,7 +4423,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4411,7 +4431,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4419,7 +4439,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4445,8 +4465,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4455,7 +4479,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4464,7 +4488,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4478,7 +4502,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4504,8 +4528,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4514,7 +4542,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4523,7 +4551,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/README.rst b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/README.rst index 1e49c63d4af1..c98b519fde8f 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/README.rst +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeveloperConnectTransport` is the ABC for all transports. -- public child `DeveloperConnectGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeveloperConnectGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeveloperConnectRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeveloperConnectRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeveloperConnectTransport`` is the ABC for all transports. + +- public child ``DeveloperConnectGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeveloperConnectGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeveloperConnectRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeveloperConnectRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/base.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/base.py index 0dc515aab994..ea19c99e4f9e 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/base.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc.py index 557ab40fe8d8..14f03e064227 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc_asyncio.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc_asyncio.py index c87ff83c1b2c..b3085ad4649a 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc_asyncio.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/rest.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/rest.py index 70afa744068a..639970b492ef 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/rest.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/developer_connect/transports/rest.py @@ -1802,6 +1802,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeveloperConnectRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/async_client.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/async_client.py index a377fbbb0d26..2b3b7e80f446 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/async_client.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> InsightsConfigServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1218,7 +1218,7 @@ async def sample_list_deployment_events(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1244,8 +1244,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1254,7 +1258,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1262,7 +1266,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1273,7 +1277,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1299,8 +1303,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1309,7 +1317,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1317,7 +1325,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1328,7 +1336,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1358,8 +1366,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1368,7 +1380,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1376,7 +1388,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1384,7 +1396,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1413,8 +1425,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1423,7 +1439,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1431,7 +1447,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1439,7 +1455,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1465,8 +1481,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1475,7 +1495,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1483,7 +1503,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1494,7 +1514,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1520,8 +1540,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1530,7 +1554,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1538,7 +1562,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/client.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/client.py index f00ddb44ba48..b756493d0d89 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/client.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/client.py @@ -130,7 +130,7 @@ class InsightsConfigServiceClient(metaclass=InsightsConfigServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -479,7 +483,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -578,7 +582,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -678,7 +682,7 @@ def __init__( self._universe_domain = InsightsConfigServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1654,7 +1658,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1680,8 +1684,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1690,7 +1698,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1699,7 +1707,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1713,7 +1721,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1739,8 +1747,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1749,7 +1761,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1758,7 +1770,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1772,7 +1784,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1802,8 +1814,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1812,7 +1828,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1820,7 +1836,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1828,7 +1844,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1857,8 +1873,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1867,7 +1887,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1875,7 +1895,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1883,7 +1903,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1909,8 +1929,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1919,7 +1943,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1928,7 +1952,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1942,7 +1966,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1968,8 +1992,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1978,7 +2006,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1987,7 +2015,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/README.rst b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/README.rst index 905b1cdd9a1b..817d6321bbc3 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/README.rst +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InsightsConfigServiceTransport` is the ABC for all transports. -- public child `InsightsConfigServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InsightsConfigServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInsightsConfigServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InsightsConfigServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InsightsConfigServiceTransport`` is the ABC for all transports. + +- public child ``InsightsConfigServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InsightsConfigServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInsightsConfigServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InsightsConfigServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/base.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/base.py index c25dee4d453b..d7ead3d2e03e 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/base.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc.py index 4a6fe6c05f3c..ebd23bd99a25 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -198,6 +198,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc_asyncio.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc_asyncio.py index 7c6c78bfc9cd..f39d09a48bab 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -249,6 +249,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/rest.py b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/rest.py index 64119b0fbf9f..303c3bba635f 100644 --- a/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/rest.py +++ b/packages/google-cloud-developerconnect/google/cloud/developerconnect_v1/services/insights_config_service/transports/rest.py @@ -712,6 +712,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[InsightsConfigServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-developerconnect/noxfile.py b/packages/google-cloud-developerconnect/noxfile.py index 27fe84222c24..defd2629f005 100644 --- a/packages/google-cloud-developerconnect/noxfile.py +++ b/packages/google-cloud-developerconnect/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-developerconnect/setup.py b/packages/google-cloud-developerconnect/setup.py index 2c266a70cf79..b2268b0f7d09 100644 --- a/packages/google-cloud-developerconnect/setup.py +++ b/packages/google-cloud-developerconnect/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-developerconnect" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-developerconnect/testing/constraints-3.7.txt b/packages/google-cloud-developerconnect/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-developerconnect/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-developerconnect/testing/constraints-3.8.txt b/packages/google-cloud-developerconnect/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-developerconnect/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-developerconnect/testing/constraints-3.9.txt b/packages/google-cloud-developerconnect/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-developerconnect/testing/constraints-3.9.txt +++ b/packages/google-cloud-developerconnect/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_developer_connect.py b/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_developer_connect.py index 4cccfcc9f394..637528f6c605 100644 --- a/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_developer_connect.py +++ b/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_developer_connect.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeveloperConnectClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): DeveloperConnectClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DeveloperConnectClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1319,11 +1324,13 @@ def test_developer_connect_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -18608,8 +18615,9 @@ def test_list_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18674,18 +18682,20 @@ def test_list_connections_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_list_connections" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_list_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_list_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_list_connections" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_list_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_list_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18743,8 +18753,9 @@ def test_get_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18815,17 +18826,20 @@ def test_get_connection_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_get_connection" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_get_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_get_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_get_connection" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_get_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_get_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18880,8 +18894,9 @@ def test_create_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19094,20 +19109,21 @@ def test_create_connection_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_create_connection" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_create_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_create_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_create_connection" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_create_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_create_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19162,8 +19178,9 @@ def test_update_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19378,20 +19395,21 @@ def test_update_connection_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_update_connection" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_update_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_update_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_update_connection" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_update_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_update_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19444,8 +19462,9 @@ def test_delete_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19502,20 +19521,21 @@ def test_delete_connection_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_connection" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_delete_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_delete_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_delete_connection" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_delete_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_delete_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19568,8 +19588,9 @@ def test_create_git_repository_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19709,20 +19730,22 @@ def test_create_git_repository_link_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_create_git_repository_link" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_create_git_repository_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_create_git_repository_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_create_git_repository_link", + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_create_git_repository_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_create_git_repository_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19777,8 +19800,9 @@ def test_delete_git_repository_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19837,20 +19861,22 @@ def test_delete_git_repository_link_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_git_repository_link" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_delete_git_repository_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_delete_git_repository_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_delete_git_repository_link", + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_delete_git_repository_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_delete_git_repository_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19903,8 +19929,9 @@ def test_list_git_repository_links_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19969,18 +19996,20 @@ def test_list_git_repository_links_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_list_git_repository_links" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_list_git_repository_links_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_list_git_repository_links" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_list_git_repository_links" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_list_git_repository_links_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_list_git_repository_links" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20040,8 +20069,9 @@ def test_get_git_repository_link_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20118,18 +20148,20 @@ def test_get_git_repository_link_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_get_git_repository_link" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_get_git_repository_link_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_get_git_repository_link" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_get_git_repository_link" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_get_git_repository_link_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_get_git_repository_link" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20189,8 +20221,9 @@ def test_fetch_read_write_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20257,18 +20290,20 @@ def test_fetch_read_write_token_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_read_write_token" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_fetch_read_write_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_fetch_read_write_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_fetch_read_write_token" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_read_write_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_fetch_read_write_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20328,8 +20363,9 @@ def test_fetch_read_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20396,18 +20432,20 @@ def test_fetch_read_token_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_read_token" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_fetch_read_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_fetch_read_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_fetch_read_token" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_read_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_fetch_read_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20467,8 +20505,9 @@ def test_fetch_linkable_git_repositories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20535,20 +20574,22 @@ def test_fetch_linkable_git_repositories_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_fetch_linkable_git_repositories", - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_fetch_linkable_git_repositories_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "pre_fetch_linkable_git_repositories", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_linkable_git_repositories", + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_linkable_git_repositories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "pre_fetch_linkable_git_repositories", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20608,8 +20649,9 @@ def test_fetch_git_hub_installations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20673,18 +20715,22 @@ def test_fetch_git_hub_installations_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_git_hub_installations" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_fetch_git_hub_installations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_fetch_git_hub_installations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_git_hub_installations", + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_git_hub_installations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "pre_fetch_git_hub_installations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20744,8 +20790,9 @@ def test_fetch_git_refs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20812,17 +20859,20 @@ def test_fetch_git_refs_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_git_refs" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_git_refs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_fetch_git_refs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_fetch_git_refs" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_git_refs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_fetch_git_refs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20880,8 +20930,9 @@ def test_list_account_connectors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20946,18 +20997,20 @@ def test_list_account_connectors_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_list_account_connectors" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_list_account_connectors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_list_account_connectors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_list_account_connectors" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_list_account_connectors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_list_account_connectors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21017,8 +21070,9 @@ def test_get_account_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21087,18 +21141,20 @@ def test_get_account_connector_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_get_account_connector" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_get_account_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_get_account_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_get_account_connector" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_get_account_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_get_account_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21153,8 +21209,9 @@ def test_create_account_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21293,20 +21350,21 @@ def test_create_account_connector_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_create_account_connector" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_create_account_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_create_account_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_create_account_connector" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_create_account_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_create_account_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21363,8 +21421,9 @@ def test_update_account_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21507,20 +21566,21 @@ def test_update_account_connector_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_update_account_connector" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_update_account_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_update_account_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_update_account_connector" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_update_account_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_update_account_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21575,8 +21635,9 @@ def test_delete_account_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21635,20 +21696,21 @@ def test_delete_account_connector_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_account_connector" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_delete_account_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_delete_account_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_delete_account_connector" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_delete_account_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_delete_account_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21703,8 +21765,9 @@ def test_fetch_access_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21771,18 +21834,20 @@ def test_fetch_access_token_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_access_token" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, - "post_fetch_access_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_fetch_access_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_fetch_access_token" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_fetch_access_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_fetch_access_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21840,8 +21905,9 @@ def test_list_users_rest_bad_request(request_type=developer_connect.ListUsersReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21908,17 +21974,19 @@ def test_list_users_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_list_users" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_list_users_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_list_users" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_list_users" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_list_users_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_list_users" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21976,8 +22044,9 @@ def test_delete_user_rest_bad_request(request_type=developer_connect.DeleteUserR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22036,19 +22105,20 @@ def test_delete_user_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_user" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_user_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_delete_user" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_delete_user" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_delete_user_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_delete_user" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22101,8 +22171,9 @@ def test_fetch_self_rest_bad_request(request_type=developer_connect.FetchSelfReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22169,17 +22240,19 @@ def test_fetch_self_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_self" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_fetch_self_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_fetch_self" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_fetch_self" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_fetch_self_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_fetch_self" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22232,8 +22305,9 @@ def test_delete_self_rest_bad_request(request_type=developer_connect.DeleteSelfR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22292,19 +22366,20 @@ def test_delete_self_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_self" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_delete_self_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_delete_self" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_delete_self" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_delete_self_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_delete_self" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22359,8 +22434,9 @@ def test_start_o_auth_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22436,17 +22512,20 @@ def test_start_o_auth_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_start_o_auth" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_start_o_auth_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_start_o_auth" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_start_o_auth" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_start_o_auth_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_start_o_auth" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22506,8 +22585,9 @@ def test_finish_o_auth_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22569,17 +22649,20 @@ def test_finish_o_auth_rest_interceptors(null_interceptor): ) client = DeveloperConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_finish_o_auth" - ) as post, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "post_finish_o_auth_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeveloperConnectRestInterceptor, "pre_finish_o_auth" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "post_finish_o_auth" + ) as post, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, + "post_finish_o_auth_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DeveloperConnectRestInterceptor, "pre_finish_o_auth" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22637,8 +22720,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22697,8 +22781,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22759,8 +22844,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22821,8 +22907,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22883,8 +22970,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22945,8 +23033,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -23659,11 +23748,14 @@ def test_developer_connect_base_transport(): def test_developer_connect_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.developerconnect_v1.services.developer_connect.transports.DeveloperConnectTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.developerconnect_v1.services.developer_connect.transports.DeveloperConnectTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeveloperConnectTransport( @@ -23680,9 +23772,12 @@ def test_developer_connect_base_transport_with_credentials_file(): def test_developer_connect_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.developerconnect_v1.services.developer_connect.transports.DeveloperConnectTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.developerconnect_v1.services.developer_connect.transports.DeveloperConnectTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeveloperConnectTransport() @@ -23754,11 +23849,12 @@ def test_developer_connect_transport_auth_gdch_credentials(transport_class): def test_developer_connect_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -24634,6 +24730,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DeveloperConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DeveloperConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DeveloperConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24773,6 +24901,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DeveloperConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DeveloperConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DeveloperConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24918,6 +25078,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DeveloperConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DeveloperConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DeveloperConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25063,6 +25257,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DeveloperConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DeveloperConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DeveloperConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25208,6 +25436,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DeveloperConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DeveloperConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DeveloperConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -25349,6 +25611,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DeveloperConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DeveloperConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DeveloperConnectClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_insights_config_service.py b/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_insights_config_service.py index 3080cd672d94..d4da08028790 100644 --- a/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_insights_config_service.py +++ b/packages/google-cloud-developerconnect/tests/unit/gapic/developerconnect_v1/test_insights_config_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert InsightsConfigServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): InsightsConfigServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + InsightsConfigServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1355,11 +1360,13 @@ def test_insights_config_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6139,8 +6146,9 @@ def test_list_insights_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6205,18 +6213,21 @@ def test_list_insights_configs_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_list_insights_configs" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_list_insights_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_list_insights_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_list_insights_configs", + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_list_insights_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, "pre_list_insights_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6274,8 +6285,9 @@ def test_create_insights_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6455,20 +6467,23 @@ def test_create_insights_config_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_create_insights_config" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_create_insights_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_create_insights_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_create_insights_config", + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_create_insights_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "pre_create_insights_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6523,8 +6538,9 @@ def test_get_insights_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6594,18 +6610,20 @@ def test_get_insights_config_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_get_insights_config" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_get_insights_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_get_insights_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, "post_get_insights_config" + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_get_insights_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, "pre_get_insights_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6664,8 +6682,9 @@ def test_update_insights_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6849,20 +6868,23 @@ def test_update_insights_config_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_update_insights_config" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_update_insights_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_update_insights_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_update_insights_config", + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_update_insights_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "pre_update_insights_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6917,8 +6939,9 @@ def test_delete_insights_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6977,20 +7000,23 @@ def test_delete_insights_config_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_delete_insights_config" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_delete_insights_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_delete_insights_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_delete_insights_config", + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_delete_insights_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "pre_delete_insights_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7045,8 +7071,9 @@ def test_get_deployment_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7115,18 +7142,20 @@ def test_get_deployment_event_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_get_deployment_event" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_get_deployment_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_get_deployment_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, "post_get_deployment_event" + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_get_deployment_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, "pre_get_deployment_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7183,8 +7212,9 @@ def test_list_deployment_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7249,18 +7279,22 @@ def test_list_deployment_events_rest_interceptors(null_interceptor): ) client = InsightsConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "post_list_deployment_events" - ) as post, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, - "post_list_deployment_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.InsightsConfigServiceRestInterceptor, "pre_list_deployment_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_list_deployment_events", + ) as post, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "post_list_deployment_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.InsightsConfigServiceRestInterceptor, + "pre_list_deployment_events", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7318,8 +7352,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7378,8 +7413,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7440,8 +7476,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7502,8 +7539,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7564,8 +7602,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7626,8 +7665,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7923,11 +7963,14 @@ def test_insights_config_service_base_transport(): def test_insights_config_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.developerconnect_v1.services.insights_config_service.transports.InsightsConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.developerconnect_v1.services.insights_config_service.transports.InsightsConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InsightsConfigServiceTransport( @@ -7944,9 +7987,12 @@ def test_insights_config_service_base_transport_with_credentials_file(): def test_insights_config_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.developerconnect_v1.services.insights_config_service.transports.InsightsConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.developerconnect_v1.services.insights_config_service.transports.InsightsConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InsightsConfigServiceTransport() @@ -8020,11 +8066,12 @@ def test_insights_config_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8674,6 +8721,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = InsightsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = InsightsConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = InsightsConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8813,6 +8892,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = InsightsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = InsightsConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = InsightsConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8958,6 +9069,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = InsightsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = InsightsConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = InsightsConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9103,6 +9248,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = InsightsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = InsightsConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = InsightsConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9248,6 +9427,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = InsightsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = InsightsConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = InsightsConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9391,6 +9604,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = InsightsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = InsightsConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = InsightsConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/async_client.py b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/async_client.py index 0b11f5f21450..8590f13544c1 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/async_client.py +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> DirectAccessServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/client.py b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/client.py index dad0087218a4..c59debb200e1 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/client.py +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/client.py @@ -126,7 +126,7 @@ class DirectAccessServiceClient(metaclass=DirectAccessServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -545,7 +549,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -645,7 +649,7 @@ def __init__( self._universe_domain = DirectAccessServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/README.rst b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/README.rst index 37f990af738c..376f1d3a6754 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/README.rst +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DirectAccessServiceTransport` is the ABC for all transports. -- public child `DirectAccessServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DirectAccessServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDirectAccessServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DirectAccessServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DirectAccessServiceTransport`` is the ABC for all transports. + +- public child ``DirectAccessServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DirectAccessServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDirectAccessServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DirectAccessServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/base.py b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/base.py index 0c1fc2113cd5..8b7c7e8fd12a 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/base.py +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc.py b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc.py index 0c23abc7fca7..aeb81099b6f8 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc.py +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc_asyncio.py b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc_asyncio.py index 78e8b79b1fd3..8ef88ad50b3e 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/rest.py b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/rest.py index e3089c97401b..453bbe0282a9 100644 --- a/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/rest.py +++ b/packages/google-cloud-devicestreaming/google/cloud/devicestreaming_v1/services/direct_access_service/transports/rest.py @@ -400,6 +400,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DirectAccessServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-devicestreaming/noxfile.py b/packages/google-cloud-devicestreaming/noxfile.py index 71c308c21197..bbad8eb6026e 100644 --- a/packages/google-cloud-devicestreaming/noxfile.py +++ b/packages/google-cloud-devicestreaming/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-devicestreaming/setup.py b/packages/google-cloud-devicestreaming/setup.py index f87794d89fc9..4a1b27e8c40f 100644 --- a/packages/google-cloud-devicestreaming/setup.py +++ b/packages/google-cloud-devicestreaming/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-devicestreaming" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-devicestreaming/testing/constraints-3.7.txt b/packages/google-cloud-devicestreaming/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-devicestreaming/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-devicestreaming/testing/constraints-3.8.txt b/packages/google-cloud-devicestreaming/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-devicestreaming/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-devicestreaming/testing/constraints-3.9.txt b/packages/google-cloud-devicestreaming/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-devicestreaming/testing/constraints-3.9.txt +++ b/packages/google-cloud-devicestreaming/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-devicestreaming/tests/unit/gapic/devicestreaming_v1/test_direct_access_service.py b/packages/google-cloud-devicestreaming/tests/unit/gapic/devicestreaming_v1/test_direct_access_service.py index 70aff890f92e..9492de10545c 100644 --- a/packages/google-cloud-devicestreaming/tests/unit/gapic/devicestreaming_v1/test_direct_access_service.py +++ b/packages/google-cloud-devicestreaming/tests/unit/gapic/devicestreaming_v1/test_direct_access_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DirectAccessServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): DirectAccessServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DirectAccessServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1343,11 +1348,13 @@ def test_direct_access_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4756,8 +4763,9 @@ def test_create_device_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4914,18 +4922,20 @@ def test_create_device_session_rest_interceptors(null_interceptor): ) client = DirectAccessServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "post_create_device_session" - ) as post, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, - "post_create_device_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "pre_create_device_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "post_create_device_session" + ) as post, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, + "post_create_device_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "pre_create_device_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4978,8 +4988,9 @@ def test_list_device_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5042,18 +5053,20 @@ def test_list_device_sessions_rest_interceptors(null_interceptor): ) client = DirectAccessServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "post_list_device_sessions" - ) as post, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, - "post_list_device_sessions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "pre_list_device_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "post_list_device_sessions" + ) as post, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, + "post_list_device_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "pre_list_device_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5108,8 +5121,9 @@ def test_get_device_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5176,18 +5190,20 @@ def test_get_device_session_rest_interceptors(null_interceptor): ) client = DirectAccessServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "post_get_device_session" - ) as post, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, - "post_get_device_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "pre_get_device_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "post_get_device_session" + ) as post, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, + "post_get_device_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "pre_get_device_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5240,8 +5256,9 @@ def test_cancel_device_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5298,13 +5315,13 @@ def test_cancel_device_session_rest_interceptors(null_interceptor): ) client = DirectAccessServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "pre_cancel_device_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "pre_cancel_device_session" + ) as pre, + ): pre.assert_not_called() pb_message = service.CancelDeviceSessionRequest.pb( service.CancelDeviceSessionRequest() @@ -5351,8 +5368,9 @@ def test_update_device_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5511,18 +5529,20 @@ def test_update_device_session_rest_interceptors(null_interceptor): ) client = DirectAccessServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "post_update_device_session" - ) as post, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, - "post_update_device_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DirectAccessServiceRestInterceptor, "pre_update_device_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "post_update_device_session" + ) as post, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, + "post_update_device_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DirectAccessServiceRestInterceptor, "pre_update_device_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5751,11 +5771,14 @@ def test_direct_access_service_base_transport(): def test_direct_access_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.devicestreaming_v1.services.direct_access_service.transports.DirectAccessServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.devicestreaming_v1.services.direct_access_service.transports.DirectAccessServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DirectAccessServiceTransport( @@ -5772,9 +5795,12 @@ def test_direct_access_service_base_transport_with_credentials_file(): def test_direct_access_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.devicestreaming_v1.services.direct_access_service.transports.DirectAccessServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.devicestreaming_v1.services.direct_access_service.transports.DirectAccessServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DirectAccessServiceTransport() @@ -5846,11 +5872,12 @@ def test_direct_access_service_transport_auth_gdch_credentials(transport_class): def test_direct_access_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/async_client.py index c07cccd45931..8b9bf63dc902 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/async_client.py @@ -222,7 +222,7 @@ def transport(self) -> AgentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1653,7 +1653,7 @@ async def sample_update_generative_settings(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1679,8 +1679,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1689,7 +1693,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1697,7 +1701,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1708,7 +1712,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1734,8 +1738,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1744,7 +1752,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1752,7 +1760,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1763,7 +1771,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1792,8 +1800,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1802,7 +1814,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1810,7 +1822,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1818,7 +1830,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1844,8 +1856,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1854,7 +1870,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1862,7 +1878,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1873,7 +1889,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1899,8 +1915,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1909,7 +1929,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1917,7 +1937,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/client.py index b9aab25d3a37..e1ba0857e1fe 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/client.py @@ -128,7 +128,7 @@ class AgentsClient(metaclass=AgentsClientMeta): """Service for managing [Agents][google.cloud.dialogflow.cx.v3.Agent].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -637,7 +641,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -734,7 +738,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -830,7 +834,7 @@ def __init__( self._universe_domain = AgentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2233,7 +2237,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2259,8 +2263,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2269,7 +2277,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2278,7 +2286,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2292,7 +2300,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2318,8 +2326,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2328,7 +2340,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2337,7 +2349,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2351,7 +2363,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2380,8 +2392,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2390,7 +2406,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2398,7 +2414,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2406,7 +2422,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2432,8 +2448,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2442,7 +2462,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2451,7 +2471,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2465,7 +2485,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2491,8 +2511,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2501,7 +2525,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2510,7 +2534,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/README.rst index 588acebd9fdd..0a289f4e53c3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AgentsTransport` is the ABC for all transports. -- public child `AgentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AgentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAgentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AgentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AgentsTransport`` is the ABC for all transports. + +- public child ``AgentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AgentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAgentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AgentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/base.py index 94c88041f574..b088f4f6d9db 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc.py index 77d18bb72f8b..e89e216b5cf2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc_asyncio.py index 492a770d696a..a6e8ac2bab73 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/rest.py index fba0b7ef8455..38b02e99b9c1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/agents/transports/rest.py @@ -834,6 +834,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AgentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/async_client.py index 954638a046e3..93a32453585c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> ChangelogsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -532,7 +532,7 @@ async def sample_get_changelog(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -558,8 +558,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -568,7 +572,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -576,7 +580,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -587,7 +591,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -613,8 +617,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -623,7 +631,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -631,7 +639,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -642,7 +650,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -671,8 +679,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -681,7 +693,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -689,7 +701,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -697,7 +709,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -723,8 +735,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -733,7 +749,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -741,7 +757,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -752,7 +768,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -778,8 +794,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -788,7 +808,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -796,7 +816,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/client.py index 631b4a61f702..fd4cb312bc75 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/client.py @@ -115,7 +115,7 @@ class ChangelogsClient(metaclass=ChangelogsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = ChangelogsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -974,7 +978,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1000,8 +1004,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1010,7 +1018,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1019,7 +1027,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1033,7 +1041,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1067,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1081,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1078,7 +1090,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1092,7 +1104,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1121,8 +1133,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1131,7 +1147,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1139,7 +1155,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1147,7 +1163,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1173,8 +1189,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1183,7 +1203,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1192,7 +1212,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1206,7 +1226,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1232,8 +1252,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1242,7 +1266,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1251,7 +1275,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/README.rst index e5dce24b7c7f..a624451fbe0c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ChangelogsTransport` is the ABC for all transports. -- public child `ChangelogsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ChangelogsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseChangelogsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ChangelogsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ChangelogsTransport`` is the ABC for all transports. + +- public child ``ChangelogsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ChangelogsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseChangelogsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ChangelogsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/base.py index 53206bc08cbb..bdfa0146c23f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc.py index e8174678815b..b5dda0903fb2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc_asyncio.py index 088e4b1d1eb3..1a97d97e7f78 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/rest.py index d7a8e158da3f..c69780d9b15b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/changelogs/transports/rest.py @@ -381,6 +381,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ChangelogsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/async_client.py index ddebd1f8dcfc..cdf114c578ed 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> DeploymentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -553,7 +553,7 @@ async def sample_get_deployment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -579,8 +579,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -589,7 +593,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -597,7 +601,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -608,7 +612,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -634,8 +638,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -644,7 +652,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -652,7 +660,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -663,7 +671,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -692,8 +700,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -702,7 +714,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -710,7 +722,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -718,7 +730,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -744,8 +756,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -754,7 +770,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -762,7 +778,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -773,7 +789,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -799,8 +815,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -809,7 +829,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -817,7 +837,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/client.py index e9d3598c34fd..8825828817bb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/client.py @@ -115,7 +115,7 @@ class DeploymentsClient(metaclass=DeploymentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -522,7 +526,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -619,7 +623,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -715,7 +719,7 @@ def __init__( self._universe_domain = DeploymentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1065,7 +1069,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,8 +1095,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1101,7 +1109,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1118,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1132,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1150,8 +1158,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1160,7 +1172,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1169,7 +1181,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1183,7 +1195,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1212,8 +1224,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1222,7 +1238,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1230,7 +1246,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1238,7 +1254,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1264,8 +1280,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1274,7 +1294,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1283,7 +1303,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1297,7 +1317,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,8 +1343,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1333,7 +1357,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1342,7 +1366,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/README.rst index 536d64972b5f..26f015c83ad5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeploymentsTransport` is the ABC for all transports. -- public child `DeploymentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeploymentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeploymentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeploymentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeploymentsTransport`` is the ABC for all transports. + +- public child ``DeploymentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeploymentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeploymentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeploymentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/base.py index 743ed6f1c38b..66cbdb4e3a95 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc.py index 9edb32fc68c2..8fe5e9e4c533 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc_asyncio.py index 2ed79d2f9415..b154bcb8da28 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/rest.py index d5cecf258fc9..da36cd1217f4 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/deployments/transports/rest.py @@ -385,6 +385,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeploymentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/async_client.py index 94b66691766d..2bbc7ddcfeb2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> EntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1199,7 +1199,7 @@ async def sample_import_entity_types(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1225,8 +1225,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1235,7 +1239,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1243,7 +1247,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1254,7 +1258,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1280,8 +1284,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1290,7 +1298,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1298,7 +1306,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1309,7 +1317,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1338,8 +1346,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1348,7 +1360,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1356,7 +1368,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1376,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1390,8 +1402,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1400,7 +1416,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1408,7 +1424,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1419,7 +1435,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1445,8 +1461,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1455,7 +1475,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1463,7 +1483,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/client.py index 544032bb44f9..cb78861911ce 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/client.py @@ -118,7 +118,7 @@ class EntityTypesClient(metaclass=EntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -445,7 +449,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -542,7 +546,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -638,7 +642,7 @@ def __init__( self._universe_domain = EntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1626,7 +1630,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1652,8 +1656,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1662,7 +1670,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1671,7 +1679,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1685,7 +1693,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1711,8 +1719,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1721,7 +1733,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1730,7 +1742,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1744,7 +1756,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1773,8 +1785,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1783,7 +1799,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1791,7 +1807,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1799,7 +1815,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1825,8 +1841,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1835,7 +1855,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1844,7 +1864,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1858,7 +1878,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1884,8 +1904,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1894,7 +1918,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1903,7 +1927,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/README.rst index b4d0b3fbe48a..8f527eecf449 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EntityTypesTransport` is the ABC for all transports. -- public child `EntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EntityTypesTransport`` is the ABC for all transports. + +- public child ``EntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/base.py index 987a9db06d96..cfc55c11369c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc.py index 72faf23bec22..71c2e921165f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc_asyncio.py index 081bbc261411..d6a555305980 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/rest.py index 0210957a0c8e..1a2150f80315 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/entity_types/transports/rest.py @@ -631,6 +631,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/async_client.py index a4c22541118c..74a5eb47845a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/async_client.py @@ -214,7 +214,7 @@ def transport(self) -> EnvironmentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1492,7 +1492,7 @@ async def sample_deploy_flow(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1518,8 +1518,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1528,7 +1532,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1536,7 +1540,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1547,7 +1551,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1573,8 +1577,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1583,7 +1591,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1591,7 +1599,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1602,7 +1610,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1631,8 +1639,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1641,7 +1653,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1649,7 +1661,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1657,7 +1669,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1683,8 +1695,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1693,7 +1709,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1701,7 +1717,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1712,7 +1728,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1738,8 +1754,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1748,7 +1768,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1756,7 +1776,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/client.py index 96b0ae805299..d20bb193e65b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/client.py @@ -120,7 +120,7 @@ class EnvironmentsClient(metaclass=EnvironmentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -619,7 +623,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -716,7 +720,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -812,7 +816,7 @@ def __init__( self._universe_domain = EnvironmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2067,7 +2071,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2093,8 +2097,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2103,7 +2111,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2112,7 +2120,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2126,7 +2134,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2152,8 +2160,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2162,7 +2174,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2171,7 +2183,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2185,7 +2197,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2214,8 +2226,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2224,7 +2240,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2232,7 +2248,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2240,7 +2256,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2266,8 +2282,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2276,7 +2296,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2285,7 +2305,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2299,7 +2319,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2325,8 +2345,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2335,7 +2359,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2344,7 +2368,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/README.rst index bce85d4987a6..47903acc874a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EnvironmentsTransport` is the ABC for all transports. -- public child `EnvironmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EnvironmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEnvironmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EnvironmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EnvironmentsTransport`` is the ABC for all transports. + +- public child ``EnvironmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EnvironmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEnvironmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EnvironmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/base.py index 8b910cdc4968..12680164e523 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc.py index b97583ce4310..82b17884e80a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc_asyncio.py index 5ce0489e34e6..643307fabd88 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/rest.py index 98f1890728ac..681e1e3769ff 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/environments/transports/rest.py @@ -749,6 +749,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EnvironmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/async_client.py index 2e6d6ae94022..663680f007c7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> ExamplesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -902,7 +902,7 @@ async def sample_update_example(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -928,8 +928,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -938,7 +942,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -946,7 +950,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -957,7 +961,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -983,8 +987,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -993,7 +1001,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1001,7 +1009,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1012,7 +1020,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1041,8 +1049,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1051,7 +1063,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1059,7 +1071,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1067,7 +1079,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1093,8 +1105,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1103,7 +1119,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1111,7 +1127,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1138,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1164,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1178,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1166,7 +1186,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/client.py index 1046636963fd..65f6e14a1545 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/client.py @@ -117,7 +117,7 @@ class ExamplesClient(metaclass=ExamplesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -518,7 +522,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -615,7 +619,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -711,7 +715,7 @@ def __init__( self._universe_domain = ExamplesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1405,7 +1409,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1431,8 +1435,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1441,7 +1449,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1450,7 +1458,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1464,7 +1472,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1490,8 +1498,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1500,7 +1512,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1509,7 +1521,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1523,7 +1535,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1552,8 +1564,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1562,7 +1578,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1570,7 +1586,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1578,7 +1594,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1604,8 +1620,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1614,7 +1634,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1623,7 +1643,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1637,7 +1657,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1663,8 +1683,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1673,7 +1697,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1682,7 +1706,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/README.rst index 0be06886f21c..7fc38879e6b3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ExamplesTransport` is the ABC for all transports. -- public child `ExamplesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ExamplesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseExamplesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ExamplesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ExamplesTransport`` is the ABC for all transports. + +- public child ``ExamplesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ExamplesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseExamplesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ExamplesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/base.py index 9f005358afbf..899f1d6e7e96 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc.py index f3b2957dd3d9..23d319a873af 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc_asyncio.py index b4785d153875..7defabae305f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/rest.py index f89ea829156e..2d1fc7b9692d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/examples/transports/rest.py @@ -507,6 +507,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ExamplesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/async_client.py index 821f44231910..4ca09cac74c6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> ExperimentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1130,7 +1130,7 @@ async def sample_stop_experiment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1156,8 +1156,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1166,7 +1170,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1174,7 +1178,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1185,7 +1189,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1211,8 +1215,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1221,7 +1229,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1229,7 +1237,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1240,7 +1248,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1269,8 +1277,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1279,7 +1291,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1287,7 +1299,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1295,7 +1307,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1321,8 +1333,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1331,7 +1347,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1339,7 +1355,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1350,7 +1366,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1376,8 +1392,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1386,7 +1406,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1394,7 +1414,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/client.py index 338eda572f15..d4efd93e4649 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/client.py @@ -118,7 +118,7 @@ class ExperimentsClient(metaclass=ExperimentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -473,7 +477,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -570,7 +574,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -666,7 +670,7 @@ def __init__( self._universe_domain = ExperimentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1581,7 +1585,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1607,8 +1611,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1617,7 +1625,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1626,7 +1634,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1640,7 +1648,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1666,8 +1674,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1676,7 +1688,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1685,7 +1697,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1699,7 +1711,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1728,8 +1740,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1738,7 +1754,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1746,7 +1762,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1754,7 +1770,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1780,8 +1796,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1790,7 +1810,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1799,7 +1819,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1813,7 +1833,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1839,8 +1859,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1849,7 +1873,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1858,7 +1882,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/README.rst index 64189d27fa1f..9191f8f78463 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ExperimentsTransport` is the ABC for all transports. -- public child `ExperimentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ExperimentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseExperimentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ExperimentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ExperimentsTransport`` is the ABC for all transports. + +- public child ``ExperimentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ExperimentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseExperimentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ExperimentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/base.py index 42b3036e30a8..be4a516b95e3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc.py index a070fcb76d84..3a1ed3844777 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc_asyncio.py index 68a50153c3ca..76ce1d31ceb3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/rest.py index 4eaa4b0f7ffd..4bf0780260f9 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/experiments/transports/rest.py @@ -629,6 +629,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ExperimentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/async_client.py index b8cd941dc6d0..2d231057b0e3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> FlowsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1552,7 +1552,7 @@ async def sample_export_flow(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1578,8 +1578,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1588,7 +1592,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1596,7 +1600,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1607,7 +1611,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1633,8 +1637,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1643,7 +1651,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1651,7 +1659,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1662,7 +1670,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1691,8 +1699,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1701,7 +1713,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1709,7 +1721,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1717,7 +1729,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1743,8 +1755,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1753,7 +1769,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1761,7 +1777,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1772,7 +1788,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1798,8 +1814,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1808,7 +1828,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1816,7 +1836,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/client.py index 004e0fc40bd8..c98bea887c55 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/client.py @@ -125,7 +125,7 @@ class FlowsClient(metaclass=FlowsClientMeta): """Service for managing [Flows][google.cloud.dialogflow.cx.v3.Flow].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -648,7 +652,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -745,7 +749,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -841,7 +845,7 @@ def __init__( self._universe_domain = FlowsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2157,7 +2161,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2183,8 +2187,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2193,7 +2201,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2202,7 +2210,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2216,7 +2224,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2242,8 +2250,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2252,7 +2264,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2261,7 +2273,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2275,7 +2287,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2304,8 +2316,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2314,7 +2330,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2322,7 +2338,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2330,7 +2346,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2356,8 +2372,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2366,7 +2386,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2375,7 +2395,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2389,7 +2409,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2415,8 +2435,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2425,7 +2449,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2434,7 +2458,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/README.rst index c5b58a2a2bac..3144150875be 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FlowsTransport` is the ABC for all transports. -- public child `FlowsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FlowsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFlowsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FlowsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FlowsTransport`` is the ABC for all transports. + +- public child ``FlowsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FlowsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFlowsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FlowsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/base.py index a81c06297556..0e4d21a1ae24 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc.py index 90ab9be654e8..b5334cf3abe4 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc_asyncio.py index 8f24ea95f159..e05c6f0aff75 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/rest.py index b1779ec7193a..293ba78c4f29 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/flows/transports/rest.py @@ -768,6 +768,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FlowsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/async_client.py index 622f120f148c..49d83e7ea58f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> GeneratorsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -895,7 +895,7 @@ async def sample_delete_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -921,8 +921,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -931,7 +935,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -939,7 +943,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -950,7 +954,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -976,8 +980,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -986,7 +994,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -994,7 +1002,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1005,7 +1013,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1034,8 +1042,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1044,7 +1056,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1052,7 +1064,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1060,7 +1072,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1086,8 +1098,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1096,7 +1112,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1104,7 +1120,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1115,7 +1131,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1141,8 +1157,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1151,7 +1171,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1159,7 +1179,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/client.py index f41c3ec83e82..adfeddca06dd 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/client.py @@ -116,7 +116,7 @@ class GeneratorsClient(metaclass=GeneratorsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = GeneratorsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1328,7 +1332,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1354,8 +1358,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1364,7 +1372,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1373,7 +1381,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1387,7 +1395,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1413,8 +1421,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1423,7 +1435,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1432,7 +1444,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1446,7 +1458,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1475,8 +1487,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1485,7 +1501,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1493,7 +1509,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1501,7 +1517,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1527,8 +1543,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1537,7 +1557,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1546,7 +1566,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1560,7 +1580,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1586,8 +1606,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1596,7 +1620,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1605,7 +1629,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/README.rst index c234b834ba8e..e218647a5ad5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeneratorsTransport` is the ABC for all transports. -- public child `GeneratorsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeneratorsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeneratorsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeneratorsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeneratorsTransport`` is the ABC for all transports. + +- public child ``GeneratorsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeneratorsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeneratorsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeneratorsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/base.py index 8476d0061327..13d8892fa6b2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc.py index 4a2e6efc6419..54c9b3effb33 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc_asyncio.py index e091aa6e6311..47f87091ce5b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/rest.py index 79fa7f13003d..ee0694c8af39 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/generators/transports/rest.py @@ -513,6 +513,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeneratorsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/async_client.py index 5a17c56c4578..abfcf8027680 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> IntentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1133,7 +1133,7 @@ async def sample_export_intents(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1159,8 +1159,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1169,7 +1173,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1177,7 +1181,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1188,7 +1192,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1214,8 +1218,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1224,7 +1232,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1232,7 +1240,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1243,7 +1251,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1280,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1294,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1290,7 +1302,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1298,7 +1310,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1324,8 +1336,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1334,7 +1350,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1342,7 +1358,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1353,7 +1369,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1379,8 +1395,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1389,7 +1409,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1397,7 +1417,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/client.py index 46b03517e279..2afdf362243d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/client.py @@ -118,7 +118,7 @@ class IntentsClient(metaclass=IntentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -469,7 +473,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -566,7 +570,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = IntentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1586,7 +1590,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1612,8 +1616,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1622,7 +1630,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1631,7 +1639,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1645,7 +1653,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1671,8 +1679,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1681,7 +1693,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1690,7 +1702,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1704,7 +1716,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1733,8 +1745,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1743,7 +1759,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1751,7 +1767,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1759,7 +1775,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1785,8 +1801,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1795,7 +1815,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1804,7 +1824,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1818,7 +1838,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1844,8 +1864,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1854,7 +1878,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1863,7 +1887,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/README.rst index 38d1ee740feb..9709e71cbb93 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IntentsTransport` is the ABC for all transports. -- public child `IntentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IntentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIntentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IntentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IntentsTransport`` is the ABC for all transports. + +- public child ``IntentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IntentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIntentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IntentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/base.py index ae0c822f2b64..9b01392f5a7c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc.py index 1dfe7fd1c37e..de6e4a075dcf 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc_asyncio.py index 48b99b5f1d5b..9950ba765d6e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/rest.py index c24477b46457..613fae5af8da 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/intents/transports/rest.py @@ -609,6 +609,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IntentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/async_client.py index 61ed1dd0a1a9..77e9becd9709 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> PagesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -962,7 +962,7 @@ async def sample_delete_page(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -988,8 +988,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -998,7 +1002,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1006,7 +1010,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1017,7 +1021,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1043,8 +1047,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1053,7 +1061,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1061,7 +1069,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1072,7 +1080,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1101,8 +1109,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1111,7 +1123,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1119,7 +1131,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1127,7 +1139,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1153,8 +1165,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,7 +1179,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1171,7 +1187,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1182,7 +1198,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1208,8 +1224,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1218,7 +1238,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1226,7 +1246,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/client.py index c2d25e68f0e6..a263f6daa377 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/client.py @@ -114,7 +114,7 @@ class PagesClient(metaclass=PagesClientMeta): """Service for managing [Pages][google.cloud.dialogflow.cx.v3.Page].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -637,7 +641,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -734,7 +738,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -830,7 +834,7 @@ def __init__( self._universe_domain = PagesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1579,7 +1583,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1605,8 +1609,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1615,7 +1623,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1624,7 +1632,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1638,7 +1646,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1664,8 +1672,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1674,7 +1686,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1683,7 +1695,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1697,7 +1709,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1726,8 +1738,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1736,7 +1752,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1744,7 +1760,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1752,7 +1768,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1778,8 +1794,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1788,7 +1808,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1797,7 +1817,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1811,7 +1831,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1837,8 +1857,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1847,7 +1871,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1856,7 +1880,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/README.rst index 56fb11300bd4..251ef5f867d4 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PagesTransport` is the ABC for all transports. -- public child `PagesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PagesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePagesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PagesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PagesTransport`` is the ABC for all transports. + +- public child ``PagesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PagesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePagesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PagesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/base.py index 8a2bc8fba0d7..84f6cc6b57e3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc.py index 7c41c9d8ef98..6ae460cadea3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc_asyncio.py index 18f5746584e2..35ff519e7867 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/rest.py index 889bd08712d2..540e8f5590c9 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/pages/transports/rest.py @@ -496,6 +496,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PagesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/async_client.py index 8f823c1d5820..f230d8189c2d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> PlaybooksTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1715,7 +1715,7 @@ async def sample_delete_playbook_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1741,8 +1741,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1751,7 +1755,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1759,7 +1763,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1770,7 +1774,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1796,8 +1800,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1806,7 +1814,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1814,7 +1822,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1825,7 +1833,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1854,8 +1862,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1864,7 +1876,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1872,7 +1884,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1880,7 +1892,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1906,8 +1918,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1916,7 +1932,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1924,7 +1940,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1935,7 +1951,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1961,8 +1977,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1971,7 +1991,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1979,7 +1999,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/client.py index 2b7d8832261d..51c33a622096 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/client.py @@ -126,7 +126,7 @@ class PlaybooksClient(metaclass=PlaybooksClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -601,7 +605,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -698,7 +702,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -794,7 +798,7 @@ def __init__( self._universe_domain = PlaybooksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2263,7 +2267,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2289,8 +2293,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2299,7 +2307,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2308,7 +2316,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2322,7 +2330,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2348,8 +2356,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2358,7 +2370,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2367,7 +2379,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2381,7 +2393,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2410,8 +2422,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2420,7 +2436,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2428,7 +2444,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2436,7 +2452,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2462,8 +2478,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2472,7 +2492,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2481,7 +2501,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2495,7 +2515,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2521,8 +2541,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2531,7 +2555,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2540,7 +2564,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/README.rst index 86cc8ac1f27f..e72d8621a949 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PlaybooksTransport` is the ABC for all transports. -- public child `PlaybooksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PlaybooksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePlaybooksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PlaybooksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PlaybooksTransport`` is the ABC for all transports. + +- public child ``PlaybooksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PlaybooksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePlaybooksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PlaybooksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/base.py index b2eab4acc75e..4f1fff2266f0 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc.py index a6366604502a..39468452a78a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc_asyncio.py index e9d20c4fecdd..bb718505cfb2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/rest.py index 0346cd2bed0f..82fb841c7153 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/playbooks/transports/rest.py @@ -861,6 +861,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PlaybooksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/async_client.py index a4c64ab4a061..45f6d7819793 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/async_client.py @@ -218,7 +218,7 @@ def transport(self) -> SecuritySettingsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -958,7 +958,7 @@ async def sample_delete_security_settings(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -984,8 +984,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -994,7 +998,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1002,7 +1006,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1013,7 +1017,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,8 +1043,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1049,7 +1057,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1057,7 +1065,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1068,7 +1076,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1097,8 +1105,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1107,7 +1119,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1115,7 +1127,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1123,7 +1135,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1149,8 +1161,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1159,7 +1175,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1167,7 +1183,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1178,7 +1194,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1204,8 +1220,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1214,7 +1234,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1222,7 +1242,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/client.py index 9b87a961ebbf..d5e98fef450a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/client.py @@ -116,7 +116,7 @@ class SecuritySettingsServiceClient(metaclass=SecuritySettingsServiceClientMeta) """Service for managing security settings for Dialogflow.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -485,7 +489,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -584,7 +588,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -686,7 +690,7 @@ def __init__( self._universe_domain = SecuritySettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1409,7 +1413,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1435,8 +1439,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1445,7 +1453,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1454,7 +1462,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1468,7 +1476,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1494,8 +1502,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1504,7 +1516,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1513,7 +1525,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1527,7 +1539,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1556,8 +1568,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1566,7 +1582,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1574,7 +1590,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1582,7 +1598,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1608,8 +1624,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1618,7 +1638,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1627,7 +1647,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1641,7 +1661,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1667,8 +1687,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1677,7 +1701,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1686,7 +1710,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/README.rst index 9c682790a84b..3f11dacd984d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SecuritySettingsServiceTransport` is the ABC for all transports. -- public child `SecuritySettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SecuritySettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSecuritySettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SecuritySettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SecuritySettingsServiceTransport`` is the ABC for all transports. + +- public child ``SecuritySettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SecuritySettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSecuritySettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SecuritySettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/base.py index bbd821d66e0f..33963e961a21 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc.py index 3c63df28735d..75bdf6435cde 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc_asyncio.py index a2985ad373ff..1dd6ecf10809 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/rest.py index 064b33984345..7d7291c26165 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/security_settings_service/transports/rest.py @@ -530,6 +530,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SecuritySettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/async_client.py index 9f3ef40b10d4..3aca1f9c8665 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SessionEntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -991,7 +991,7 @@ async def sample_delete_session_entity_type(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1017,8 +1017,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1027,7 +1031,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1035,7 +1039,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1046,7 +1050,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1072,8 +1076,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1082,7 +1090,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1090,7 +1098,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1101,7 +1109,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1130,8 +1138,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1140,7 +1152,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1148,7 +1160,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1156,7 +1168,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1182,8 +1194,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1192,7 +1208,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1200,7 +1216,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1211,7 +1227,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1237,8 +1253,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1247,7 +1267,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1255,7 +1275,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/client.py index 942449624303..c2be5ee753f3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/client.py @@ -118,7 +118,7 @@ class SessionEntityTypesClient(metaclass=SessionEntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -447,7 +451,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -544,7 +548,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = SessionEntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1426,7 +1430,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1452,8 +1456,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1462,7 +1470,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1471,7 +1479,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1485,7 +1493,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1511,8 +1519,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1521,7 +1533,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1530,7 +1542,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1544,7 +1556,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1573,8 +1585,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1583,7 +1599,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1591,7 +1607,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1599,7 +1615,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1625,8 +1641,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1635,7 +1655,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1644,7 +1664,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1658,7 +1678,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1684,8 +1704,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1694,7 +1718,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1703,7 +1727,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/README.rst index fa50039837f6..edbabf709074 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionEntityTypesTransport` is the ABC for all transports. -- public child `SessionEntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionEntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionEntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionEntityTypesTransport`` is the ABC for all transports. + +- public child ``SessionEntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionEntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionEntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/base.py index e9aa268639e9..b8807b4f30b3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc.py index 9f44bdb50d59..904c592996c2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc_asyncio.py index eeb0424838c7..0fda1c69b814 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/rest.py index 88122a082d30..9c3ed75fdd21 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/session_entity_types/transports/rest.py @@ -533,6 +533,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionEntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/async_client.py index 2ccb055f8b8f..a6e46633b9be 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> SessionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -946,7 +946,7 @@ async def sample_submit_answer_feedback(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -972,8 +972,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -982,7 +986,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -990,7 +994,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1001,7 +1005,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1031,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1045,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1053,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1056,7 +1064,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1085,8 +1093,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1095,7 +1107,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1103,7 +1115,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1111,7 +1123,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1137,8 +1149,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1147,7 +1163,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1155,7 +1171,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1166,7 +1182,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1192,8 +1208,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1202,7 +1222,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1210,7 +1230,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/client.py index e7a3cc1dab07..5203fa294188 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/client.py @@ -117,7 +117,7 @@ class SessionsClient(metaclass=SessionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -738,7 +742,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -835,7 +839,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -931,7 +935,7 @@ def __init__( self._universe_domain = SessionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1649,7 +1653,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1675,8 +1679,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1685,7 +1693,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1694,7 +1702,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1708,7 +1716,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1734,8 +1742,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1744,7 +1756,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1753,7 +1765,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1767,7 +1779,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1796,8 +1808,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1806,7 +1822,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1814,7 +1830,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1822,7 +1838,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1848,8 +1864,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1858,7 +1878,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1867,7 +1887,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1881,7 +1901,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1907,8 +1927,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1917,7 +1941,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1926,7 +1950,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/README.rst index ff5ae65346f4..bff74be61084 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionsTransport` is the ABC for all transports. -- public child `SessionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionsTransport`` is the ABC for all transports. + +- public child ``SessionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/base.py index cc4fa9bbd54d..a59bb27bb8df 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc.py index ebde39da383f..8d5e467574ad 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc_asyncio.py index 78eec4e382d2..d46b89ee2476 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/rest.py index 6aee02e55a50..3a46e1068b2d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/sessions/transports/rest.py @@ -547,6 +547,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/async_client.py index f6d6c6e47d2d..659a22cdb965 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> TestCasesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1688,7 +1688,7 @@ async def sample_get_test_case_result(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1714,8 +1714,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1724,7 +1728,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1732,7 +1736,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1743,7 +1747,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1769,8 +1773,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1779,7 +1787,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1787,7 +1795,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1798,7 +1806,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1827,8 +1835,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1837,7 +1849,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1845,7 +1857,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1853,7 +1865,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1879,8 +1891,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1889,7 +1905,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1897,7 +1913,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1908,7 +1924,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1934,8 +1950,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1944,7 +1964,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1952,7 +1972,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/client.py index da435ad4c385..a2e3fc9ed453 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/client.py @@ -120,7 +120,7 @@ class TestCasesClient(metaclass=TestCasesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -739,7 +743,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -836,7 +840,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -932,7 +936,7 @@ def __init__( self._universe_domain = TestCasesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2367,7 +2371,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2393,8 +2397,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2403,7 +2411,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2412,7 +2420,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2426,7 +2434,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2452,8 +2460,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2462,7 +2474,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2471,7 +2483,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2485,7 +2497,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2514,8 +2526,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2524,7 +2540,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2532,7 +2548,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2540,7 +2556,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2566,8 +2582,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2576,7 +2596,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2585,7 +2605,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2599,7 +2619,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2625,8 +2645,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2635,7 +2659,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2644,7 +2668,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/README.rst index 39094500a03e..0c88d81b48dc 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TestCasesTransport` is the ABC for all transports. -- public child `TestCasesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TestCasesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTestCasesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TestCasesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TestCasesTransport`` is the ABC for all transports. + +- public child ``TestCasesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TestCasesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTestCasesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TestCasesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/base.py index 7e8699a2957e..4c5d911f9915 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc.py index 0d3e72072a6a..2ffc0ce863cb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc_asyncio.py index 0f7fa802cf92..5b38203c6cbe 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/rest.py index 3db2670ed780..46eb6f16daf0 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/test_cases/transports/rest.py @@ -906,6 +906,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TestCasesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/async_client.py index db64aa322c05..1354612585d1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> ToolsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1480,7 +1480,7 @@ async def sample_restore_tool_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1506,8 +1506,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1516,7 +1520,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1524,7 +1528,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1535,7 +1539,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1561,8 +1565,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1571,7 +1579,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1579,7 +1587,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1590,7 +1598,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1619,8 +1627,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1629,7 +1641,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1637,7 +1649,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1645,7 +1657,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1671,8 +1683,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1681,7 +1697,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1689,7 +1705,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1700,7 +1716,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1726,8 +1742,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1736,7 +1756,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1744,7 +1764,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/client.py index 6d781b4181bd..04b4c00cce55 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/client.py @@ -115,7 +115,7 @@ class ToolsClient(metaclass=ToolsClientMeta): """Service for managing [Tools][google.cloud.dialogflow.cx.v3.Tool].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -514,7 +518,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -611,7 +615,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -707,7 +711,7 @@ def __init__( self._universe_domain = ToolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1970,7 +1974,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1996,8 +2000,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2006,7 +2014,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2015,7 +2023,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2029,7 +2037,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2055,8 +2063,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2065,7 +2077,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2074,7 +2086,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2088,7 +2100,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2117,8 +2129,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2127,7 +2143,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2135,7 +2151,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2143,7 +2159,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2169,8 +2185,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2179,7 +2199,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2188,7 +2208,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2202,7 +2222,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2228,8 +2248,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2238,7 +2262,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2247,7 +2271,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/README.rst index f7b77e1167bf..6a4417039c6e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ToolsTransport` is the ABC for all transports. -- public child `ToolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ToolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseToolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ToolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ToolsTransport`` is the ABC for all transports. + +- public child ``ToolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ToolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseToolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ToolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/base.py index f62b9bd3db32..e0fe33e2ff27 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc.py index ae15340fe7cf..65a980bb29c6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc_asyncio.py index e0ec6ee558c2..24220f10bd73 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/rest.py index 42057f0b1179..e57ce2c74b9e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/tools/transports/rest.py @@ -726,6 +726,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ToolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/async_client.py index 2aab6423c767..0d9e06ce8629 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> TransitionRouteGroupsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -984,7 +984,7 @@ async def sample_delete_transition_route_group(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1010,8 +1010,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1020,7 +1024,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1028,7 +1032,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1039,7 +1043,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1065,8 +1069,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1075,7 +1083,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1083,7 +1091,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1094,7 +1102,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1123,8 +1131,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1133,7 +1145,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1141,7 +1153,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1149,7 +1161,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1175,8 +1187,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1185,7 +1201,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1193,7 +1209,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1204,7 +1220,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1230,8 +1246,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1240,7 +1260,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1248,7 +1268,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/client.py index e16fbcdeb618..6ddd774ed09d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/client.py @@ -118,7 +118,7 @@ class TransitionRouteGroupsClient(metaclass=TransitionRouteGroupsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -593,7 +597,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -692,7 +696,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -792,7 +796,7 @@ def __init__( self._universe_domain = TransitionRouteGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1553,7 +1557,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1579,8 +1583,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1589,7 +1597,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1598,7 +1606,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1612,7 +1620,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1638,8 +1646,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1648,7 +1660,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1657,7 +1669,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1671,7 +1683,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1700,8 +1712,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1710,7 +1726,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1718,7 +1734,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1726,7 +1742,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1752,8 +1768,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1762,7 +1782,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1771,7 +1791,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1785,7 +1805,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1811,8 +1831,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1821,7 +1845,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1830,7 +1854,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/README.rst index 5c64183b283e..458c7753d75c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TransitionRouteGroupsTransport` is the ABC for all transports. -- public child `TransitionRouteGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TransitionRouteGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTransitionRouteGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TransitionRouteGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TransitionRouteGroupsTransport`` is the ABC for all transports. + +- public child ``TransitionRouteGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TransitionRouteGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTransitionRouteGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TransitionRouteGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/base.py index 02d5e10677b8..b8868fc2d13e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc.py index 9c9038076655..77309c4c5dc7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc_asyncio.py index 537f7ae66b9d..29f74d82096c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/rest.py index 841b040a5ef8..98bfb8819225 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/transition_route_groups/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TransitionRouteGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/async_client.py index b4ec25e963b3..250bbfa0ae9b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> VersionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1180,7 +1180,7 @@ async def sample_compare_versions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1206,8 +1206,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1216,7 +1220,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1224,7 +1228,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1235,7 +1239,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1261,8 +1265,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1271,7 +1279,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1279,7 +1287,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1290,7 +1298,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1319,8 +1327,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1329,7 +1341,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1337,7 +1349,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1345,7 +1357,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1371,8 +1383,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1381,7 +1397,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1389,7 +1405,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1400,7 +1416,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1426,8 +1442,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1436,7 +1456,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1444,7 +1464,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/client.py index a79a8435b407..379bf05f90f8 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/client.py @@ -121,7 +121,7 @@ class VersionsClient(metaclass=VersionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -450,7 +454,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = VersionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1611,7 +1615,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1637,8 +1641,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1647,7 +1655,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1656,7 +1664,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1670,7 +1678,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1696,8 +1704,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1706,7 +1718,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1715,7 +1727,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1729,7 +1741,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1758,8 +1770,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1768,7 +1784,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1776,7 +1792,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1784,7 +1800,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1810,8 +1826,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1820,7 +1840,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1829,7 +1849,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1843,7 +1863,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1869,8 +1889,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1879,7 +1903,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1888,7 +1912,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/README.rst index ac30fdf3d846..f820acfcbfa3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VersionsTransport` is the ABC for all transports. -- public child `VersionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VersionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVersionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VersionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VersionsTransport`` is the ABC for all transports. + +- public child ``VersionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VersionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVersionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VersionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/base.py index 5db4d1a0b08e..0fc75a1ed7b4 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc.py index 2a6cf92aa365..52cf936b56ba 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc_asyncio.py index daebfe08b83a..946be9e8d04b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/rest.py index d219921a0dca..9d218ce9e369 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/versions/transports/rest.py @@ -617,6 +617,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VersionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/async_client.py index 53ef48355e97..f11d93ff2cdf 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> WebhooksTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -901,7 +901,7 @@ async def sample_delete_webhook(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -927,8 +927,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -937,7 +941,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -945,7 +949,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -956,7 +960,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -982,8 +986,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -992,7 +1000,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1000,7 +1008,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1011,7 +1019,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1040,8 +1048,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1050,7 +1062,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1058,7 +1070,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1066,7 +1078,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1092,8 +1104,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1102,7 +1118,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1126,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1121,7 +1137,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1147,8 +1163,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1157,7 +1177,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1165,7 +1185,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/client.py index 1a7730bdb4aa..6896a44eafa6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/client.py @@ -117,7 +117,7 @@ class WebhooksClient(metaclass=WebhooksClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -490,7 +494,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -587,7 +591,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -683,7 +687,7 @@ def __init__( self._universe_domain = WebhooksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1378,7 +1382,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1404,8 +1408,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1414,7 +1422,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1423,7 +1431,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1437,7 +1445,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1463,8 +1471,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1473,7 +1485,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1482,7 +1494,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1496,7 +1508,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1525,8 +1537,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1535,7 +1551,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1543,7 +1559,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1551,7 +1567,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1577,8 +1593,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1587,7 +1607,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1596,7 +1616,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1610,7 +1630,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1636,8 +1656,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1646,7 +1670,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1655,7 +1679,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/README.rst index 57875ddfdecf..3ec765697728 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WebhooksTransport` is the ABC for all transports. -- public child `WebhooksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WebhooksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWebhooksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WebhooksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WebhooksTransport`` is the ABC for all transports. + +- public child ``WebhooksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WebhooksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWebhooksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WebhooksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/base.py index b695b1c354f2..0a210a1d8dcb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc.py index 93fe520edbfd..99ac45483165 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc_asyncio.py index f714a22134d4..5182474b9eef 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/rest.py index 67b5c24bdebf..134f558ad31b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3/services/webhooks/transports/rest.py @@ -507,6 +507,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WebhooksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/async_client.py index 60c38e416819..8d0c22f5ce54 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/async_client.py @@ -225,7 +225,7 @@ def transport(self) -> AgentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1656,7 +1656,7 @@ async def sample_update_generative_settings(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1682,8 +1682,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1692,7 +1696,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1700,7 +1704,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1711,7 +1715,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1737,8 +1741,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1747,7 +1755,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1755,7 +1763,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1766,7 +1774,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1795,8 +1803,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1805,7 +1817,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1813,7 +1825,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1821,7 +1833,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1847,8 +1859,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1857,7 +1873,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1865,7 +1881,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1876,7 +1892,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1902,8 +1918,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1912,7 +1932,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1920,7 +1940,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/client.py index ae097bdb12bf..59e87f4da3c8 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/client.py @@ -131,7 +131,7 @@ class AgentsClient(metaclass=AgentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -640,7 +644,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -737,7 +741,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -833,7 +837,7 @@ def __init__( self._universe_domain = AgentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2236,7 +2240,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2262,8 +2266,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2272,7 +2280,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2281,7 +2289,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2295,7 +2303,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2321,8 +2329,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2331,7 +2343,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2340,7 +2352,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2354,7 +2366,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2383,8 +2395,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2393,7 +2409,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2401,7 +2417,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2409,7 +2425,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2435,8 +2451,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2445,7 +2465,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2454,7 +2474,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2468,7 +2488,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2494,8 +2514,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2504,7 +2528,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2513,7 +2537,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/README.rst index 588acebd9fdd..0a289f4e53c3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AgentsTransport` is the ABC for all transports. -- public child `AgentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AgentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAgentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AgentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AgentsTransport`` is the ABC for all transports. + +- public child ``AgentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AgentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAgentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AgentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/base.py index 4c7f04e3d034..699c4ea41115 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc.py index ec900c7bacf9..b74444d1d834 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc_asyncio.py index fd7f77f553bd..4f4172c2bbbd 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/rest.py index cc7b59d5e92a..e90b139b3558 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/agents/transports/rest.py @@ -835,6 +835,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AgentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/async_client.py index 726a14e79c43..411f9ea8328c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> ChangelogsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -532,7 +532,7 @@ async def sample_get_changelog(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -558,8 +558,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -568,7 +572,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -576,7 +580,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -587,7 +591,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -613,8 +617,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -623,7 +631,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -631,7 +639,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -642,7 +650,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -671,8 +679,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -681,7 +693,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -689,7 +701,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -697,7 +709,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -723,8 +735,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -733,7 +749,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -741,7 +757,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -752,7 +768,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -778,8 +794,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -788,7 +808,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -796,7 +816,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/client.py index 749f25236117..4062f9a3870b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/client.py @@ -115,7 +115,7 @@ class ChangelogsClient(metaclass=ChangelogsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = ChangelogsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -974,7 +978,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1000,8 +1004,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1010,7 +1018,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1019,7 +1027,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1033,7 +1041,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1067,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1081,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1078,7 +1090,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1092,7 +1104,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1121,8 +1133,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1131,7 +1147,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1139,7 +1155,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1147,7 +1163,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1173,8 +1189,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1183,7 +1203,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1192,7 +1212,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1206,7 +1226,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1232,8 +1252,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1242,7 +1266,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1251,7 +1275,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/README.rst index e5dce24b7c7f..a624451fbe0c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ChangelogsTransport` is the ABC for all transports. -- public child `ChangelogsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ChangelogsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseChangelogsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ChangelogsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ChangelogsTransport`` is the ABC for all transports. + +- public child ``ChangelogsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ChangelogsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseChangelogsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ChangelogsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/base.py index 284acb40d404..b662657a7ca8 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc.py index 58e65fb1c0cf..c0b0fb063d24 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc_asyncio.py index d84040c1b6e1..34e8a8aa4ec2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/rest.py index 41c9b7a09cc3..4aa5d2da2411 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/changelogs/transports/rest.py @@ -381,6 +381,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ChangelogsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py index dd12a3598c88..045f3a23e8dd 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/async_client.py @@ -252,7 +252,7 @@ def transport(self) -> ConversationHistoryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -707,7 +707,7 @@ async def sample_delete_conversation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -733,8 +733,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -743,7 +747,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -751,7 +755,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -762,7 +766,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -788,8 +792,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -798,7 +806,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -806,7 +814,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -817,7 +825,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -846,8 +854,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -856,7 +868,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -864,7 +876,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -872,7 +884,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -898,8 +910,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -908,7 +924,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -916,7 +932,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -927,7 +943,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -953,8 +969,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -963,7 +983,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -971,7 +991,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py index 0174e06a84b2..04c1205a555f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/client.py @@ -120,7 +120,7 @@ class ConversationHistoryClient(metaclass=ConversationHistoryClientMeta): """Service for managing conversation history.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -885,7 +889,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -982,7 +986,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1082,7 +1086,7 @@ def __init__( self._universe_domain = ConversationHistoryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1526,7 +1530,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1552,8 +1556,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1562,7 +1570,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1571,7 +1579,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1585,7 +1593,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1611,8 +1619,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1621,7 +1633,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1630,7 +1642,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1644,7 +1656,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1673,8 +1685,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1683,7 +1699,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1691,7 +1707,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1699,7 +1715,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1725,8 +1741,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1735,7 +1755,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1744,7 +1764,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1758,7 +1778,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1784,8 +1804,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1794,7 +1818,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1803,7 +1827,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/README.rst index 4e8f6e6b3cd2..ad77b12a8fcf 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationHistoryTransport` is the ABC for all transports. -- public child `ConversationHistoryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationHistoryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationHistoryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationHistoryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationHistoryTransport`` is the ABC for all transports. + +- public child ``ConversationHistoryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationHistoryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationHistoryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationHistoryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/base.py index 655d95f123aa..25b41bb5a9e2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc.py index 7015cba83cb1..06fe6f932864 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc_asyncio.py index 166cda368432..1d966608dc29 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/rest.py index e89d89a092fb..9e6d474dc507 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/conversation_history/transports/rest.py @@ -409,6 +409,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationHistoryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/async_client.py index dfb2ee0ab294..a2c7875062c5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> DeploymentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -553,7 +553,7 @@ async def sample_get_deployment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -579,8 +579,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -589,7 +593,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -597,7 +601,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -608,7 +612,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -634,8 +638,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -644,7 +652,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -652,7 +660,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -663,7 +671,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -692,8 +700,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -702,7 +714,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -710,7 +722,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -718,7 +730,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -744,8 +756,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -754,7 +770,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -762,7 +778,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -773,7 +789,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -799,8 +815,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -809,7 +829,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -817,7 +837,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/client.py index 00040298dab9..c79d72ef7649 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/client.py @@ -115,7 +115,7 @@ class DeploymentsClient(metaclass=DeploymentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -522,7 +526,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -619,7 +623,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -715,7 +719,7 @@ def __init__( self._universe_domain = DeploymentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1065,7 +1069,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,8 +1095,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1101,7 +1109,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1118,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1132,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1150,8 +1158,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1160,7 +1172,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1169,7 +1181,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1183,7 +1195,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1212,8 +1224,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1222,7 +1238,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1230,7 +1246,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1238,7 +1254,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1264,8 +1280,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1274,7 +1294,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1283,7 +1303,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1297,7 +1317,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,8 +1343,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1333,7 +1357,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1342,7 +1366,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/README.rst index 536d64972b5f..26f015c83ad5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DeploymentsTransport` is the ABC for all transports. -- public child `DeploymentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DeploymentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDeploymentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DeploymentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DeploymentsTransport`` is the ABC for all transports. + +- public child ``DeploymentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DeploymentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDeploymentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DeploymentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/base.py index 5f70456d699d..6a3ba29be0ac 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc.py index 53cd18bd8be3..f7691c2c1683 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc_asyncio.py index 88c8ca6d17f3..31deadcfa781 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/rest.py index c3e7585dd41a..4861aa1b0d30 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/deployments/transports/rest.py @@ -385,6 +385,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DeploymentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/async_client.py index 9ce05acdb2c8..e35d2f23adb6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> EntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1195,7 +1195,7 @@ async def sample_import_entity_types(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1221,8 +1221,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1231,7 +1235,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1239,7 +1243,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1250,7 +1254,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1276,8 +1280,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1286,7 +1294,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1294,7 +1302,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1305,7 +1313,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1334,8 +1342,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1344,7 +1356,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1352,7 +1364,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1360,7 +1372,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1386,8 +1398,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1396,7 +1412,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1404,7 +1420,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1415,7 +1431,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1441,8 +1457,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1451,7 +1471,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1459,7 +1479,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/client.py index 13ac3ce1a3c8..c5d9abc6ccd1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/client.py @@ -118,7 +118,7 @@ class EntityTypesClient(metaclass=EntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -445,7 +449,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -542,7 +546,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -638,7 +642,7 @@ def __init__( self._universe_domain = EntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1622,7 +1626,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1648,8 +1652,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1658,7 +1666,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1667,7 +1675,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1681,7 +1689,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1707,8 +1715,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1717,7 +1729,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1726,7 +1738,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1740,7 +1752,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1769,8 +1781,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1779,7 +1795,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1787,7 +1803,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1795,7 +1811,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1821,8 +1837,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1831,7 +1851,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1840,7 +1860,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1854,7 +1874,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1880,8 +1900,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1890,7 +1914,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1899,7 +1923,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/README.rst index b4d0b3fbe48a..8f527eecf449 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EntityTypesTransport` is the ABC for all transports. -- public child `EntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EntityTypesTransport`` is the ABC for all transports. + +- public child ``EntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/base.py index 0a7c39b7ef71..10238fefad04 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc.py index acbe3cfab347..41b55ca9802e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc_asyncio.py index 406b6155cb88..cec4e551effd 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/rest.py index 814daa600d86..0f34dc6d8b78 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/entity_types/transports/rest.py @@ -631,6 +631,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py index d4094a13d170..025bb4622f6f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/async_client.py @@ -214,7 +214,7 @@ def transport(self) -> EnvironmentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1492,7 +1492,7 @@ async def sample_deploy_flow(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1518,8 +1518,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1528,7 +1532,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1536,7 +1540,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1547,7 +1551,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1573,8 +1577,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1583,7 +1591,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1591,7 +1599,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1602,7 +1610,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1631,8 +1639,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1641,7 +1653,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1649,7 +1661,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1657,7 +1669,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1683,8 +1695,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1693,7 +1709,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1701,7 +1717,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1712,7 +1728,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1738,8 +1754,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1748,7 +1768,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1756,7 +1776,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py index cac5e853ed7e..f0817e438a4b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/client.py @@ -120,7 +120,7 @@ class EnvironmentsClient(metaclass=EnvironmentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -619,7 +623,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -716,7 +720,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -812,7 +816,7 @@ def __init__( self._universe_domain = EnvironmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2067,7 +2071,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2093,8 +2097,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2103,7 +2111,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2112,7 +2120,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2126,7 +2134,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2152,8 +2160,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2162,7 +2174,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2171,7 +2183,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2185,7 +2197,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2214,8 +2226,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2224,7 +2240,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2232,7 +2248,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2240,7 +2256,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2266,8 +2282,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2276,7 +2296,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2285,7 +2305,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2299,7 +2319,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2325,8 +2345,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2335,7 +2359,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2344,7 +2368,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/README.rst index bce85d4987a6..47903acc874a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EnvironmentsTransport` is the ABC for all transports. -- public child `EnvironmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EnvironmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEnvironmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EnvironmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EnvironmentsTransport`` is the ABC for all transports. + +- public child ``EnvironmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EnvironmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEnvironmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EnvironmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py index 82a9bb90e814..b79cdffb6746 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py index 1edbd5509d2b..8f7a6f02e6af 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py index f26324d425fb..d2a6ea65d6f2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/rest.py index 4fcc78e68ec8..0b79d639c143 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/environments/transports/rest.py @@ -749,6 +749,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EnvironmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py index 1376a85c7c1d..670f2d8cddc4 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> ExamplesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -902,7 +902,7 @@ async def sample_update_example(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -928,8 +928,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -938,7 +942,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -946,7 +950,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -957,7 +961,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -983,8 +987,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -993,7 +1001,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1001,7 +1009,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1012,7 +1020,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1041,8 +1049,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1051,7 +1063,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1059,7 +1071,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1067,7 +1079,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1093,8 +1105,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1103,7 +1119,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1111,7 +1127,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1138,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1164,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1178,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1166,7 +1186,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py index 179bf565a430..5dd6b66bb6f6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/client.py @@ -117,7 +117,7 @@ class ExamplesClient(metaclass=ExamplesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -518,7 +522,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -615,7 +619,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -711,7 +715,7 @@ def __init__( self._universe_domain = ExamplesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1405,7 +1409,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1431,8 +1435,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1441,7 +1449,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1450,7 +1458,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1464,7 +1472,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1490,8 +1498,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1500,7 +1512,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1509,7 +1521,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1523,7 +1535,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1552,8 +1564,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1562,7 +1578,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1570,7 +1586,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1578,7 +1594,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1604,8 +1620,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1614,7 +1634,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1623,7 +1643,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1637,7 +1657,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1663,8 +1683,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1673,7 +1697,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1682,7 +1706,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/README.rst index 0be06886f21c..7fc38879e6b3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ExamplesTransport` is the ABC for all transports. -- public child `ExamplesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ExamplesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseExamplesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ExamplesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ExamplesTransport`` is the ABC for all transports. + +- public child ``ExamplesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ExamplesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseExamplesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ExamplesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/base.py index 5e3e8fc40c82..e0218061cbeb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc.py index ccadfe27856e..4b217f8ba95a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc_asyncio.py index bf45a919624c..623b464076b5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/rest.py index 1cc1095331a4..ca0be7b8e748 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/examples/transports/rest.py @@ -507,6 +507,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ExamplesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/async_client.py index b79ebec50cd4..5ba0409fc1a5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> ExperimentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1132,7 +1132,7 @@ async def sample_stop_experiment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1158,8 +1158,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1168,7 +1172,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1176,7 +1180,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1187,7 +1191,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1213,8 +1217,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1223,7 +1231,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1231,7 +1239,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1242,7 +1250,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1271,8 +1279,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1281,7 +1293,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1289,7 +1301,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1297,7 +1309,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,8 +1335,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1333,7 +1349,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1341,7 +1357,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1352,7 +1368,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1378,8 +1394,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1388,7 +1408,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1396,7 +1416,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/client.py index 595b11a45c25..a268e6a60bef 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/client.py @@ -118,7 +118,7 @@ class ExperimentsClient(metaclass=ExperimentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -473,7 +477,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -570,7 +574,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -666,7 +670,7 @@ def __init__( self._universe_domain = ExperimentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1583,7 +1587,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1609,8 +1613,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1619,7 +1627,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1628,7 +1636,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1642,7 +1650,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1668,8 +1676,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1678,7 +1690,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1687,7 +1699,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1701,7 +1713,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1730,8 +1742,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1740,7 +1756,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1748,7 +1764,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1756,7 +1772,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1782,8 +1798,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1792,7 +1812,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1801,7 +1821,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1815,7 +1835,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1841,8 +1861,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1851,7 +1875,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1860,7 +1884,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/README.rst index 64189d27fa1f..9191f8f78463 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ExperimentsTransport` is the ABC for all transports. -- public child `ExperimentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ExperimentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseExperimentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ExperimentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ExperimentsTransport`` is the ABC for all transports. + +- public child ``ExperimentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ExperimentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseExperimentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ExperimentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/base.py index 85b199dc68e6..dd212e9ef47e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc.py index 823e0b190ecb..2f134992581b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc_asyncio.py index 698cb834566e..4b0e9ff29346 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/rest.py index db3b051d3506..a6939fde4bfa 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/experiments/transports/rest.py @@ -629,6 +629,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ExperimentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py index f438f6366ebd..f0577cace223 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/async_client.py @@ -213,7 +213,7 @@ def transport(self) -> FlowsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1554,7 +1554,7 @@ async def sample_export_flow(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1580,8 +1580,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1590,7 +1594,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1598,7 +1602,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1609,7 +1613,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1635,8 +1639,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1645,7 +1653,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1653,7 +1661,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1664,7 +1672,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1693,8 +1701,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1703,7 +1715,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1711,7 +1723,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1719,7 +1731,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1745,8 +1757,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1755,7 +1771,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1763,7 +1779,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1774,7 +1790,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1800,8 +1816,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1810,7 +1830,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1818,7 +1838,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py index 3d3b2457cbb1..4da0fb0449d1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/client.py @@ -127,7 +127,7 @@ class FlowsClient(metaclass=FlowsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -650,7 +654,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -747,7 +751,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -843,7 +847,7 @@ def __init__( self._universe_domain = FlowsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2159,7 +2163,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2185,8 +2189,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2195,7 +2203,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2204,7 +2212,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2218,7 +2226,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2244,8 +2252,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2254,7 +2266,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2263,7 +2275,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2277,7 +2289,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2306,8 +2318,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2316,7 +2332,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2324,7 +2340,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2332,7 +2348,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2358,8 +2374,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2368,7 +2388,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2377,7 +2397,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2391,7 +2411,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2417,8 +2437,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2427,7 +2451,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2436,7 +2460,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/README.rst index c5b58a2a2bac..3144150875be 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FlowsTransport` is the ABC for all transports. -- public child `FlowsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FlowsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFlowsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FlowsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FlowsTransport`` is the ABC for all transports. + +- public child ``FlowsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FlowsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFlowsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FlowsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/base.py index 7ef8ccfe818c..28e8477ac8da 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc.py index 7851c68e0c11..0a31f3edc1a7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc_asyncio.py index d0deaa56fa12..6c559eb10a83 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/rest.py index f20356fe671f..7c17ea7b0faa 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/flows/transports/rest.py @@ -769,6 +769,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FlowsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/async_client.py index 45d5945d545c..818038970a06 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> GeneratorsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -895,7 +895,7 @@ async def sample_delete_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -921,8 +921,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -931,7 +935,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -939,7 +943,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -950,7 +954,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -976,8 +980,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -986,7 +994,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -994,7 +1002,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1005,7 +1013,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1034,8 +1042,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1044,7 +1056,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1052,7 +1064,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1060,7 +1072,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1086,8 +1098,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1096,7 +1112,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1104,7 +1120,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1115,7 +1131,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1141,8 +1157,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1151,7 +1171,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1159,7 +1179,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/client.py index 2e8a3d1b6526..08f1651c9311 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/client.py @@ -116,7 +116,7 @@ class GeneratorsClient(metaclass=GeneratorsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = GeneratorsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1328,7 +1332,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1354,8 +1358,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1364,7 +1372,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1373,7 +1381,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1387,7 +1395,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1413,8 +1421,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1423,7 +1435,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1432,7 +1444,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1446,7 +1458,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1475,8 +1487,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1485,7 +1501,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1493,7 +1509,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1501,7 +1517,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1527,8 +1543,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1537,7 +1557,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1546,7 +1566,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1560,7 +1580,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1586,8 +1606,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1596,7 +1620,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1605,7 +1629,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/README.rst index c234b834ba8e..e218647a5ad5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeneratorsTransport` is the ABC for all transports. -- public child `GeneratorsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeneratorsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeneratorsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeneratorsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeneratorsTransport`` is the ABC for all transports. + +- public child ``GeneratorsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeneratorsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeneratorsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeneratorsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/base.py index ba73dd8afb9f..d34bb10b5fa0 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc.py index 26387cbc2c68..8f85e902f503 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc_asyncio.py index 61a171191d41..3f7937873dc5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/rest.py index d3b3f2cfd582..4fcaa8fcdf03 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/generators/transports/rest.py @@ -513,6 +513,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeneratorsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/async_client.py index e508735c3e76..6348fd7f9a6e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> IntentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1133,7 +1133,7 @@ async def sample_export_intents(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1159,8 +1159,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1169,7 +1173,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1177,7 +1181,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1188,7 +1192,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1214,8 +1218,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1224,7 +1232,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1232,7 +1240,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1243,7 +1251,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1280,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1294,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1290,7 +1302,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1298,7 +1310,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1324,8 +1336,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1334,7 +1350,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1342,7 +1358,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1353,7 +1369,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1379,8 +1395,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1389,7 +1409,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1397,7 +1417,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/client.py index 3847450253b0..5e5a9be6a7ba 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/client.py @@ -118,7 +118,7 @@ class IntentsClient(metaclass=IntentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -469,7 +473,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -566,7 +570,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = IntentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1586,7 +1590,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1612,8 +1616,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1622,7 +1630,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1631,7 +1639,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1645,7 +1653,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1671,8 +1679,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1681,7 +1693,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1690,7 +1702,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1704,7 +1716,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1733,8 +1745,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1743,7 +1759,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1751,7 +1767,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1759,7 +1775,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1785,8 +1801,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1795,7 +1815,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1804,7 +1824,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1818,7 +1838,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1844,8 +1864,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1854,7 +1878,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1863,7 +1887,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/README.rst index 38d1ee740feb..9709e71cbb93 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IntentsTransport` is the ABC for all transports. -- public child `IntentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IntentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIntentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IntentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IntentsTransport`` is the ABC for all transports. + +- public child ``IntentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IntentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIntentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IntentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/base.py index cbb3e29a8732..c48a8485609e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc.py index 00ba6b90a315..25d9b4788faf 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc_asyncio.py index 826e9fe8e3be..51e0dafeec7d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/rest.py index e5d63de54d0e..8f97ef6a82da 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/intents/transports/rest.py @@ -609,6 +609,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IntentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py index 300b3cf8bf04..1b1693570af9 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> PagesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -952,7 +952,7 @@ async def sample_delete_page(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -978,8 +978,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -988,7 +992,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -996,7 +1000,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1007,7 +1011,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1033,8 +1037,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1043,7 +1051,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1051,7 +1059,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1062,7 +1070,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,8 +1099,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1101,7 +1113,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1109,7 +1121,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1117,7 +1129,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1143,8 +1155,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1153,7 +1169,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1161,7 +1177,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1172,7 +1188,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1198,8 +1214,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1208,7 +1228,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1216,7 +1236,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py index d73c21680fc4..9a64e6ee2790 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/client.py @@ -116,7 +116,7 @@ class PagesClient(metaclass=PagesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -639,7 +643,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -736,7 +740,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -832,7 +836,7 @@ def __init__( self._universe_domain = PagesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1569,7 +1573,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1595,8 +1599,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1605,7 +1613,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1614,7 +1622,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1628,7 +1636,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1654,8 +1662,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1664,7 +1676,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1673,7 +1685,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1687,7 +1699,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1716,8 +1728,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1726,7 +1742,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1734,7 +1750,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1742,7 +1758,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1768,8 +1784,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1778,7 +1798,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1787,7 +1807,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1801,7 +1821,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1827,8 +1847,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1837,7 +1861,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1846,7 +1870,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/README.rst index 56fb11300bd4..251ef5f867d4 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PagesTransport` is the ABC for all transports. -- public child `PagesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PagesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePagesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PagesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PagesTransport`` is the ABC for all transports. + +- public child ``PagesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PagesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePagesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PagesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/base.py index 2e479ee68bc0..05a540aa6174 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc.py index 63f72d16ac61..2f7c057aaacb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc_asyncio.py index 8918238243b1..273e7937a9d1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/rest.py index c87f83fc0604..f3170fa39f85 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/pages/transports/rest.py @@ -497,6 +497,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PagesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py index bab1605db31d..7b6da129f1a7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> PlaybooksTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1716,7 +1716,7 @@ async def sample_delete_playbook_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1742,8 +1742,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1752,7 +1756,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1760,7 +1764,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1771,7 +1775,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1797,8 +1801,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1807,7 +1815,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1815,7 +1823,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1826,7 +1834,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1855,8 +1863,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1865,7 +1877,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1873,7 +1885,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1881,7 +1893,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1907,8 +1919,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1917,7 +1933,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1925,7 +1941,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1936,7 +1952,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1962,8 +1978,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1972,7 +1992,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1980,7 +2000,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py index 394130e3de8a..02d6a08b92fd 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/client.py @@ -127,7 +127,7 @@ class PlaybooksClient(metaclass=PlaybooksClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -602,7 +606,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -699,7 +703,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -795,7 +799,7 @@ def __init__( self._universe_domain = PlaybooksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2264,7 +2268,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2290,8 +2294,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2300,7 +2308,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2309,7 +2317,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2323,7 +2331,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2349,8 +2357,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2359,7 +2371,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2368,7 +2380,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2382,7 +2394,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2411,8 +2423,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2421,7 +2437,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2429,7 +2445,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2437,7 +2453,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2463,8 +2479,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2473,7 +2493,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2482,7 +2502,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2496,7 +2516,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2522,8 +2542,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2532,7 +2556,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2541,7 +2565,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/README.rst index 86cc8ac1f27f..e72d8621a949 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PlaybooksTransport` is the ABC for all transports. -- public child `PlaybooksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PlaybooksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePlaybooksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PlaybooksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PlaybooksTransport`` is the ABC for all transports. + +- public child ``PlaybooksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PlaybooksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePlaybooksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PlaybooksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py index e32aafd61bc0..144a2fdbef8b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py index 64bf760de090..6555eeb5cf89 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py index 57d80a3ce277..52a5ddc60cde 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py index 82e26c57faeb..571487da198f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/playbooks/transports/rest.py @@ -861,6 +861,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PlaybooksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/async_client.py index f5dd1336723c..23a9d59a68b7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/async_client.py @@ -218,7 +218,7 @@ def transport(self) -> SecuritySettingsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -958,7 +958,7 @@ async def sample_delete_security_settings(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -984,8 +984,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -994,7 +998,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1002,7 +1006,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1013,7 +1017,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,8 +1043,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1049,7 +1057,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1057,7 +1065,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1068,7 +1076,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1097,8 +1105,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1107,7 +1119,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1115,7 +1127,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1123,7 +1135,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1149,8 +1161,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1159,7 +1175,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1167,7 +1183,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1178,7 +1194,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1204,8 +1220,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1214,7 +1234,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1222,7 +1242,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/client.py index beb2d4c0d7dc..9742eb3f9998 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/client.py @@ -116,7 +116,7 @@ class SecuritySettingsServiceClient(metaclass=SecuritySettingsServiceClientMeta) """Service for managing security settings for Dialogflow.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -485,7 +489,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -584,7 +588,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -686,7 +690,7 @@ def __init__( self._universe_domain = SecuritySettingsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1409,7 +1413,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1435,8 +1439,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1445,7 +1453,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1454,7 +1462,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1468,7 +1476,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1494,8 +1502,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1504,7 +1516,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1513,7 +1525,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1527,7 +1539,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1556,8 +1568,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1566,7 +1582,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1574,7 +1590,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1582,7 +1598,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1608,8 +1624,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1618,7 +1638,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1627,7 +1647,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1641,7 +1661,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1667,8 +1687,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1677,7 +1701,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1686,7 +1710,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/README.rst index 9c682790a84b..3f11dacd984d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SecuritySettingsServiceTransport` is the ABC for all transports. -- public child `SecuritySettingsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SecuritySettingsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSecuritySettingsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SecuritySettingsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SecuritySettingsServiceTransport`` is the ABC for all transports. + +- public child ``SecuritySettingsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SecuritySettingsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSecuritySettingsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SecuritySettingsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/base.py index af1713953505..39f5cbb7d40a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc.py index a0536e762d2c..51a969ac4fc1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc_asyncio.py index 51c0155b552f..087e06fb00ca 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/rest.py index ae2bbdab1320..488c4744f67b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/security_settings_service/transports/rest.py @@ -530,6 +530,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SecuritySettingsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/async_client.py index 8486d075e1fe..3980d6d96f5c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SessionEntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -994,7 +994,7 @@ async def sample_delete_session_entity_type(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1020,8 +1020,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1030,7 +1034,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1038,7 +1042,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1049,7 +1053,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1075,8 +1079,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1085,7 +1093,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1093,7 +1101,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1112,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1133,8 +1141,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1143,7 +1155,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1151,7 +1163,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1159,7 +1171,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1185,8 +1197,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1195,7 +1211,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1203,7 +1219,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1214,7 +1230,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1240,8 +1256,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1250,7 +1270,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1258,7 +1278,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/client.py index fda7b9d1d59c..e1b3b6a19f27 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/client.py @@ -118,7 +118,7 @@ class SessionEntityTypesClient(metaclass=SessionEntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -447,7 +451,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -544,7 +548,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = SessionEntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1429,7 +1433,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1455,8 +1459,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1465,7 +1473,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1474,7 +1482,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1488,7 +1496,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1514,8 +1522,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1524,7 +1536,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1533,7 +1545,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1547,7 +1559,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1576,8 +1588,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1586,7 +1602,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1594,7 +1610,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1602,7 +1618,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1628,8 +1644,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1638,7 +1658,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1647,7 +1667,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1661,7 +1681,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1687,8 +1707,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1697,7 +1721,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1706,7 +1730,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/README.rst index fa50039837f6..edbabf709074 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionEntityTypesTransport` is the ABC for all transports. -- public child `SessionEntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionEntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionEntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionEntityTypesTransport`` is the ABC for all transports. + +- public child ``SessionEntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionEntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionEntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/base.py index 827d66f6d036..22f56afb92c1 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc.py index 0884f496ddfb..d709f1eb322f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc_asyncio.py index 6ccba3a258c7..e89001f99a48 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/rest.py index d597bb4e391a..ed01d2460402 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/session_entity_types/transports/rest.py @@ -533,6 +533,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionEntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py index a7b68fcf7a1e..44e23cdac51e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/async_client.py @@ -218,7 +218,7 @@ def transport(self) -> SessionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -948,7 +948,7 @@ async def sample_submit_answer_feedback(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -974,8 +974,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -984,7 +988,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -992,7 +996,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1003,7 +1007,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1029,8 +1033,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1039,7 +1047,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1047,7 +1055,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1058,7 +1066,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1087,8 +1095,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1097,7 +1109,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1105,7 +1117,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1113,7 +1125,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1139,8 +1151,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1149,7 +1165,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1157,7 +1173,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1168,7 +1184,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1194,8 +1210,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1204,7 +1224,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1212,7 +1232,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py index fd0e67126a52..e3885392a6e9 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/client.py @@ -117,7 +117,7 @@ class SessionsClient(metaclass=SessionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -764,7 +768,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -861,7 +865,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -957,7 +961,7 @@ def __init__( self._universe_domain = SessionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1675,7 +1679,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1701,8 +1705,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1711,7 +1719,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1720,7 +1728,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1734,7 +1742,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1760,8 +1768,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1770,7 +1782,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1779,7 +1791,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1793,7 +1805,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1822,8 +1834,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1832,7 +1848,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1840,7 +1856,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1848,7 +1864,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1874,8 +1890,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1884,7 +1904,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1893,7 +1913,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1907,7 +1927,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1933,8 +1953,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1943,7 +1967,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1952,7 +1976,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/README.rst index ff5ae65346f4..bff74be61084 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionsTransport` is the ABC for all transports. -- public child `SessionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionsTransport`` is the ABC for all transports. + +- public child ``SessionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/base.py index 35f7162d6a62..7c463d6dd745 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc.py index f5c5f1a2383f..4f708586be92 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc_asyncio.py index e58cbe92c04a..17ddbb6a183f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/rest.py index 0c1a47043364..cdf17498be45 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/sessions/transports/rest.py @@ -547,6 +547,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py index d0aab20e6546..bb11a60aa199 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> TestCasesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1688,7 +1688,7 @@ async def sample_get_test_case_result(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1714,8 +1714,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1724,7 +1728,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1732,7 +1736,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1743,7 +1747,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1769,8 +1773,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1779,7 +1787,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1787,7 +1795,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1798,7 +1806,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1827,8 +1835,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1837,7 +1849,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1845,7 +1857,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1853,7 +1865,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1879,8 +1891,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1889,7 +1905,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1897,7 +1913,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1908,7 +1924,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1934,8 +1950,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1944,7 +1964,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1952,7 +1972,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py index 090a5c40d854..dbc8db566d12 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/client.py @@ -120,7 +120,7 @@ class TestCasesClient(metaclass=TestCasesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -739,7 +743,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -836,7 +840,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -932,7 +936,7 @@ def __init__( self._universe_domain = TestCasesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2367,7 +2371,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2393,8 +2397,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2403,7 +2411,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2412,7 +2420,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2426,7 +2434,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2452,8 +2460,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2462,7 +2474,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2471,7 +2483,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2485,7 +2497,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2514,8 +2526,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2524,7 +2540,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2532,7 +2548,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2540,7 +2556,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2566,8 +2582,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2576,7 +2596,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2585,7 +2605,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2599,7 +2619,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2625,8 +2645,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2635,7 +2659,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2644,7 +2668,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/README.rst index 39094500a03e..0c88d81b48dc 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TestCasesTransport` is the ABC for all transports. -- public child `TestCasesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TestCasesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTestCasesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TestCasesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TestCasesTransport`` is the ABC for all transports. + +- public child ``TestCasesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TestCasesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTestCasesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TestCasesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/base.py index 39d7b71776be..ae2196b95dc5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc.py index 64cc557ce417..25b4c6aa0cad 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc_asyncio.py index 6e4ef7ebe2eb..a6f089e570f6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/rest.py index eb035adff9b3..c87f2db5017d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/test_cases/transports/rest.py @@ -906,6 +906,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TestCasesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py index 4bed48adf836..0f289e00491b 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> ToolsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1589,7 +1589,7 @@ async def sample_restore_tool_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1615,8 +1615,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1625,7 +1629,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1633,7 +1637,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1644,7 +1648,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1670,8 +1674,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1680,7 +1688,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1688,7 +1696,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1699,7 +1707,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1728,8 +1736,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1738,7 +1750,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1746,7 +1758,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1754,7 +1766,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1780,8 +1792,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1790,7 +1806,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1798,7 +1814,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1809,7 +1825,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1835,8 +1851,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1845,7 +1865,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1853,7 +1873,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py index fb78e475f2f5..df55c8eecb37 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/client.py @@ -119,7 +119,7 @@ class ToolsClient(metaclass=ToolsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -518,7 +522,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -615,7 +619,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -711,7 +715,7 @@ def __init__( self._universe_domain = ToolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2077,7 +2081,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2103,8 +2107,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2113,7 +2121,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2122,7 +2130,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2136,7 +2144,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2162,8 +2170,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2172,7 +2184,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2181,7 +2193,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2195,7 +2207,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2224,8 +2236,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2234,7 +2250,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2242,7 +2258,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2250,7 +2266,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2276,8 +2292,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2286,7 +2306,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2295,7 +2315,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2309,7 +2329,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2335,8 +2355,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2345,7 +2369,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2354,7 +2378,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/README.rst index f7b77e1167bf..6a4417039c6e 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ToolsTransport` is the ABC for all transports. -- public child `ToolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ToolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseToolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ToolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ToolsTransport`` is the ABC for all transports. + +- public child ``ToolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ToolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseToolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ToolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/base.py index 897f578fa396..6d424eadbdcb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc.py index 953aa5d9c6e4..47ab376f29ef 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc_asyncio.py index e49c228f34c3..ffb4fd0cca10 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/rest.py index 2f7f69e4d539..ed381ba0ddd5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/tools/transports/rest.py @@ -781,6 +781,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ToolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py index 07dc740760bf..ae78934a9237 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> TransitionRouteGroupsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -984,7 +984,7 @@ async def sample_delete_transition_route_group(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1010,8 +1010,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1020,7 +1024,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1028,7 +1032,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1039,7 +1043,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1065,8 +1069,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1075,7 +1083,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1083,7 +1091,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1094,7 +1102,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1123,8 +1131,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1133,7 +1145,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1141,7 +1153,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1149,7 +1161,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1175,8 +1187,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1185,7 +1201,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1193,7 +1209,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1204,7 +1220,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1230,8 +1246,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1240,7 +1260,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1248,7 +1268,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py index 638197df594c..4e6deb98705d 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/client.py @@ -118,7 +118,7 @@ class TransitionRouteGroupsClient(metaclass=TransitionRouteGroupsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -593,7 +597,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -692,7 +696,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -792,7 +796,7 @@ def __init__( self._universe_domain = TransitionRouteGroupsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1553,7 +1557,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1579,8 +1583,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1589,7 +1597,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1598,7 +1606,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1612,7 +1620,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1638,8 +1646,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1648,7 +1660,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1657,7 +1669,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1671,7 +1683,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1700,8 +1712,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1710,7 +1726,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1718,7 +1734,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1726,7 +1742,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1752,8 +1768,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1762,7 +1782,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1771,7 +1791,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1785,7 +1805,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1811,8 +1831,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1821,7 +1845,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1830,7 +1854,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/README.rst index 5c64183b283e..458c7753d75c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`TransitionRouteGroupsTransport` is the ABC for all transports. -- public child `TransitionRouteGroupsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `TransitionRouteGroupsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseTransitionRouteGroupsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `TransitionRouteGroupsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``TransitionRouteGroupsTransport`` is the ABC for all transports. + +- public child ``TransitionRouteGroupsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``TransitionRouteGroupsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseTransitionRouteGroupsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``TransitionRouteGroupsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/base.py index 6c428d51c596..8cab84f4fbd2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc.py index a9933d5dda11..8fe58f9caac9 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc_asyncio.py index 40bb1c3f0ec0..85bc4e62a075 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/rest.py index 9858ddb5ef9d..ea13b419597f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/transition_route_groups/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[TransitionRouteGroupsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/async_client.py index ff956e8c7b8e..0064f5e35adb 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> VersionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1184,7 +1184,7 @@ async def sample_compare_versions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1210,8 +1210,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1220,7 +1224,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1228,7 +1232,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1239,7 +1243,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1265,8 +1269,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1275,7 +1283,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1283,7 +1291,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1294,7 +1302,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,8 +1331,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1333,7 +1345,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1341,7 +1353,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1349,7 +1361,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1375,8 +1387,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1385,7 +1401,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1393,7 +1409,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1404,7 +1420,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1430,8 +1446,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1440,7 +1460,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1448,7 +1468,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/client.py index e0cfa86833db..862cd6d146a6 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/client.py @@ -121,7 +121,7 @@ class VersionsClient(metaclass=VersionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -450,7 +454,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -643,7 +647,7 @@ def __init__( self._universe_domain = VersionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1615,7 +1619,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1641,8 +1645,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1651,7 +1659,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1660,7 +1668,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1674,7 +1682,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1700,8 +1708,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1710,7 +1722,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1719,7 +1731,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1733,7 +1745,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1762,8 +1774,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1772,7 +1788,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1780,7 +1796,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1788,7 +1804,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1814,8 +1830,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1824,7 +1844,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1833,7 +1853,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1847,7 +1867,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1873,8 +1893,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1883,7 +1907,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1892,7 +1916,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/README.rst index ac30fdf3d846..f820acfcbfa3 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VersionsTransport` is the ABC for all transports. -- public child `VersionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VersionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVersionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VersionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VersionsTransport`` is the ABC for all transports. + +- public child ``VersionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VersionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVersionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VersionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/base.py index 50a8395abd21..bfff82c5899a 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc.py index d29e5061d033..71bf5808860c 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc_asyncio.py index 601818b71b2a..a046670fb4da 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/rest.py index c0b493a173c5..4e234be7371f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/versions/transports/rest.py @@ -617,6 +617,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VersionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py index 8e9c70890a58..091e9a06242f 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> WebhooksTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -901,7 +901,7 @@ async def sample_delete_webhook(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -927,8 +927,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -937,7 +941,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -945,7 +949,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -956,7 +960,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -982,8 +986,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -992,7 +1000,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1000,7 +1008,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1011,7 +1019,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1040,8 +1048,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1050,7 +1062,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1058,7 +1070,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1066,7 +1078,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1092,8 +1104,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1102,7 +1118,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1126,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1121,7 +1137,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1147,8 +1163,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1157,7 +1177,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1165,7 +1185,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py index 43266452a1c9..fb060bd73481 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/client.py @@ -117,7 +117,7 @@ class WebhooksClient(metaclass=WebhooksClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -490,7 +494,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -587,7 +591,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -683,7 +687,7 @@ def __init__( self._universe_domain = WebhooksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1378,7 +1382,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1404,8 +1408,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1414,7 +1422,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1423,7 +1431,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1437,7 +1445,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1463,8 +1471,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1473,7 +1485,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1482,7 +1494,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1496,7 +1508,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1525,8 +1537,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1535,7 +1551,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1543,7 +1559,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1551,7 +1567,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1577,8 +1593,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1587,7 +1607,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1596,7 +1616,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1610,7 +1630,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1636,8 +1656,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1646,7 +1670,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1655,7 +1679,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/README.rst b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/README.rst index 57875ddfdecf..3ec765697728 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/README.rst +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WebhooksTransport` is the ABC for all transports. -- public child `WebhooksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WebhooksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWebhooksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WebhooksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WebhooksTransport`` is the ABC for all transports. + +- public child ``WebhooksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WebhooksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWebhooksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WebhooksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/base.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/base.py index f6555acd0481..434b3e3f93f2 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/base.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc.py index 646ba3c441e2..a8020ca1f387 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc_asyncio.py index 26d314aec8d8..1fc6f64ed8a7 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/rest.py b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/rest.py index e3b90e986751..453aa86d10c5 100644 --- a/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/rest.py +++ b/packages/google-cloud-dialogflow-cx/google/cloud/dialogflowcx_v3beta1/services/webhooks/transports/rest.py @@ -507,6 +507,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WebhooksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index 12956b8cf85a..1c196c9d25b1 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dialogflow-cx/setup.py b/packages/google-cloud-dialogflow-cx/setup.py index 4a0b69655cb8..521f0aa802ba 100644 --- a/packages/google-cloud-dialogflow-cx/setup.py +++ b/packages/google-cloud-dialogflow-cx/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dialogflow-cx" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dialogflow-cx/testing/constraints-3.7.txt b/packages/google-cloud-dialogflow-cx/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-dialogflow-cx/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-dialogflow-cx/testing/constraints-3.8.txt b/packages/google-cloud-dialogflow-cx/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-dialogflow-cx/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-dialogflow-cx/testing/constraints-3.9.txt b/packages/google-cloud-dialogflow-cx/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-dialogflow-cx/testing/constraints-3.9.txt +++ b/packages/google-cloud-dialogflow-cx/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_agents.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_agents.py index 972851be2899..156ee55351e0 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_agents.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_agents.py @@ -141,6 +141,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AgentsClient._get_default_mtls_endpoint(None) is None assert AgentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -156,6 +157,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AgentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AgentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1234,11 +1236,13 @@ def test_agents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7640,8 +7644,9 @@ def test_list_agents_rest_bad_request(request_type=agent.ListAgentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7702,17 +7707,15 @@ def test_list_agents_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_list_agents" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_list_agents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_list_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_list_agents") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_list_agents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_list_agents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7761,8 +7764,9 @@ def test_get_agent_rest_bad_request(request_type=agent.GetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7850,17 +7854,15 @@ def test_get_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_get_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_get_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7909,8 +7911,9 @@ def test_create_agent_rest_bad_request(request_type=gcdc_agent.CreateAgentReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8126,17 +8129,17 @@ def test_create_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_create_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_create_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_create_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_create_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_create_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_create_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8187,8 +8190,9 @@ def test_update_agent_rest_bad_request(request_type=gcdc_agent.UpdateAgentReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8406,17 +8410,17 @@ def test_update_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_update_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_update_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_update_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_update_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_update_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_update_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8465,8 +8469,9 @@ def test_delete_agent_rest_bad_request(request_type=agent.DeleteAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8521,13 +8526,11 @@ def test_delete_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "pre_delete_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "pre_delete_agent") as pre, + ): pre.assert_not_called() pb_message = agent.DeleteAgentRequest.pb(agent.DeleteAgentRequest()) transcode.return_value = { @@ -8568,8 +8571,9 @@ def test_export_agent_rest_bad_request(request_type=agent.ExportAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8624,19 +8628,18 @@ def test_export_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_export_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_export_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8685,8 +8688,9 @@ def test_restore_agent_rest_bad_request(request_type=agent.RestoreAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8741,19 +8745,18 @@ def test_restore_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_restore_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_restore_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8802,8 +8805,9 @@ def test_validate_agent_rest_bad_request(request_type=agent.ValidateAgentRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8864,17 +8868,19 @@ def test_validate_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_validate_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_validate_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_validate_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_validate_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_validate_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_validate_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8929,8 +8935,9 @@ def test_get_agent_validation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8993,18 +9000,20 @@ def test_get_agent_validation_result_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent_validation_result" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, - "post_get_agent_validation_result_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_agent_validation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_agent_validation_result" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, + "post_get_agent_validation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_get_agent_validation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9061,8 +9070,9 @@ def test_get_generative_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9127,17 +9137,20 @@ def test_get_generative_settings_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_generative_settings" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_generative_settings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_generative_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_generative_settings" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, + "post_get_generative_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_get_generative_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9199,8 +9212,9 @@ def test_update_generative_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9371,18 +9385,20 @@ def test_update_generative_settings_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_update_generative_settings" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, - "post_update_generative_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_update_generative_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_update_generative_settings" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, + "post_update_generative_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_update_generative_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9440,8 +9456,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9500,8 +9517,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9562,8 +9580,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9624,8 +9643,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9684,8 +9704,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10056,11 +10077,14 @@ def test_agents_base_transport(): def test_agents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport( @@ -10080,9 +10104,12 @@ def test_agents_base_transport_with_credentials_file(): def test_agents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport() @@ -10160,11 +10187,12 @@ def test_agents_transport_auth_gdch_credentials(transport_class): def test_agents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11005,6 +11033,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11150,6 +11210,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11295,6 +11389,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11440,6 +11568,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11581,6 +11743,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_changelogs.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_changelogs.py index 80340b092f80..c6cc082000cb 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_changelogs.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_changelogs.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ChangelogsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ChangelogsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ChangelogsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_changelogs_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2807,8 +2813,9 @@ def test_list_changelogs_rest_bad_request(request_type=changelog.ListChangelogsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2871,17 +2878,19 @@ def test_list_changelogs_rest_interceptors(null_interceptor): ) client = ChangelogsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_list_changelogs" - ) as post, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_list_changelogs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChangelogsRestInterceptor, "pre_list_changelogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_list_changelogs" + ) as post, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_list_changelogs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChangelogsRestInterceptor, "pre_list_changelogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2936,8 +2945,9 @@ def test_get_changelog_rest_bad_request(request_type=changelog.GetChangelogReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3014,17 +3024,19 @@ def test_get_changelog_rest_interceptors(null_interceptor): ) client = ChangelogsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_get_changelog" - ) as post, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_get_changelog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChangelogsRestInterceptor, "pre_get_changelog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_get_changelog" + ) as post, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_get_changelog_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChangelogsRestInterceptor, "pre_get_changelog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3075,8 +3087,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3135,8 +3148,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3197,8 +3211,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3259,8 +3274,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3319,8 +3335,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3474,11 +3491,14 @@ def test_changelogs_base_transport(): def test_changelogs_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChangelogsTransport( @@ -3498,9 +3518,12 @@ def test_changelogs_base_transport_with_credentials_file(): def test_changelogs_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChangelogsTransport() @@ -3578,11 +3601,12 @@ def test_changelogs_transport_auth_gdch_credentials(transport_class): def test_changelogs_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4143,6 +4167,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4288,6 +4344,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4433,6 +4523,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4578,6 +4702,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4719,6 +4877,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_deployments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_deployments.py index 60d8f80ea5d8..e2f9ec34bc0c 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_deployments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_deployments.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeploymentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DeploymentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DeploymentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1246,11 +1250,13 @@ def test_deployments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2807,8 +2813,9 @@ def test_list_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2873,17 +2880,19 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = DeploymentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeploymentsRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_list_deployments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentsRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2938,8 +2947,9 @@ def test_get_deployment_rest_bad_request(request_type=deployment.GetDeploymentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3008,17 +3018,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = DeploymentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeploymentsRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentsRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3071,8 +3083,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3131,8 +3144,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3193,8 +3207,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3255,8 +3270,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3315,8 +3331,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3470,11 +3487,14 @@ def test_deployments_base_transport(): def test_deployments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeploymentsTransport( @@ -3494,9 +3514,12 @@ def test_deployments_base_transport_with_credentials_file(): def test_deployments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeploymentsTransport() @@ -3574,11 +3597,12 @@ def test_deployments_transport_auth_gdch_credentials(transport_class): def test_deployments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4244,6 +4268,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4389,6 +4445,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4534,6 +4624,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4679,6 +4803,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4820,6 +4978,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_entity_types.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_entity_types.py index b8ba951fb607..f266f5c7a128 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_entity_types.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_entity_types.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EntityTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1251,11 +1255,13 @@ def test_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5585,8 +5591,9 @@ def test_get_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5664,17 +5671,19 @@ def test_get_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_get_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_get_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5727,8 +5736,9 @@ def test_create_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5883,17 +5893,20 @@ def test_create_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_create_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_create_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_create_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_create_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5952,8 +5965,9 @@ def test_update_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6112,17 +6126,20 @@ def test_update_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_update_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_update_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_update_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_update_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6179,8 +6196,9 @@ def test_delete_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6239,13 +6257,13 @@ def test_delete_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_delete_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_delete_entity_type" + ) as pre, + ): pre.assert_not_called() pb_message = entity_type.DeleteEntityTypeRequest.pb( entity_type.DeleteEntityTypeRequest() @@ -6290,8 +6308,9 @@ def test_list_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6354,17 +6373,20 @@ def test_list_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_list_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_list_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_list_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_list_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6422,8 +6444,9 @@ def test_export_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6480,19 +6503,21 @@ def test_export_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_export_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_export_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_export_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_export_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_export_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_export_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6545,8 +6570,9 @@ def test_import_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6603,19 +6629,21 @@ def test_import_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_import_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_import_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_import_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_import_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_import_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_import_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6668,8 +6696,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6728,8 +6757,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6790,8 +6820,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6852,8 +6883,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6912,8 +6944,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7206,11 +7239,14 @@ def test_entity_types_base_transport(): def test_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport( @@ -7230,9 +7266,12 @@ def test_entity_types_base_transport_with_credentials_file(): def test_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport() @@ -7310,11 +7349,12 @@ def test_entity_types_transport_auth_gdch_credentials(transport_class): def test_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7924,6 +7964,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8069,6 +8141,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8214,6 +8320,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8359,6 +8499,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8500,6 +8674,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_environments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_environments.py index 5034bb8397b9..32ddca77fd94 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_environments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_environments.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EnvironmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EnvironmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EnvironmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1268,11 +1273,13 @@ def test_environments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7192,8 +7199,9 @@ def test_list_environments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7256,17 +7264,20 @@ def test_list_environments_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_list_environments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_list_environments" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_list_environments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_list_environments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7326,8 +7337,9 @@ def test_get_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7396,17 +7408,19 @@ def test_get_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_get_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_get_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7459,8 +7473,9 @@ def test_create_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7637,19 +7652,21 @@ def test_create_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_create_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_create_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_create_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_create_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7706,8 +7723,9 @@ def test_update_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7888,19 +7906,21 @@ def test_update_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_update_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_update_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_update_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_update_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7955,8 +7975,9 @@ def test_delete_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8015,13 +8036,13 @@ def test_delete_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_delete_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_delete_environment" + ) as pre, + ): pre.assert_not_called() pb_message = environment.DeleteEnvironmentRequest.pb( environment.DeleteEnvironmentRequest() @@ -8068,8 +8089,9 @@ def test_lookup_environment_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8134,18 +8156,20 @@ def test_lookup_environment_history_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_lookup_environment_history" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, - "post_lookup_environment_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_lookup_environment_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_lookup_environment_history" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_lookup_environment_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_lookup_environment_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8205,8 +8229,9 @@ def test_run_continuous_test_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8265,19 +8290,21 @@ def test_run_continuous_test_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_run_continuous_test" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_run_continuous_test_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_run_continuous_test" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_run_continuous_test" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_run_continuous_test_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_run_continuous_test" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8332,8 +8359,9 @@ def test_list_continuous_test_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8398,18 +8426,20 @@ def test_list_continuous_test_results_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_continuous_test_results" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, - "post_list_continuous_test_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_list_continuous_test_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_list_continuous_test_results" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_list_continuous_test_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_list_continuous_test_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8467,8 +8497,9 @@ def test_deploy_flow_rest_bad_request(request_type=environment.DeployFlowRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8527,19 +8558,20 @@ def test_deploy_flow_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_deploy_flow" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_deploy_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_deploy_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_deploy_flow" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_deploy_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_deploy_flow" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8590,8 +8622,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8650,8 +8683,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8712,8 +8746,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8774,8 +8809,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8834,8 +8870,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9172,11 +9209,14 @@ def test_environments_base_transport(): def test_environments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport( @@ -9196,9 +9236,12 @@ def test_environments_base_transport_with_credentials_file(): def test_environments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport() @@ -9276,11 +9319,12 @@ def test_environments_transport_auth_gdch_credentials(transport_class): def test_environments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10109,6 +10153,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10254,6 +10330,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10399,6 +10509,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10544,6 +10688,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10685,6 +10863,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_examples.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_examples.py index 4c6e6c79cc67..09f4602dcc4a 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_examples.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_examples.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ExamplesClient._get_default_mtls_endpoint(None) is None assert ExamplesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -141,6 +142,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ExamplesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ExamplesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1230,11 +1232,13 @@ def test_examples_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4505,8 +4509,9 @@ def test_create_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4693,17 +4698,19 @@ def test_create_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_create_example" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_create_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_create_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_create_example" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_create_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_create_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4756,8 +4763,9 @@ def test_delete_example_rest_bad_request(request_type=example.DeleteExampleReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4814,13 +4822,13 @@ def test_delete_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_delete_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_delete_example" + ) as pre, + ): pre.assert_not_called() pb_message = example.DeleteExampleRequest.pb(example.DeleteExampleRequest()) transcode.return_value = { @@ -4863,8 +4871,9 @@ def test_list_examples_rest_bad_request(request_type=example.ListExamplesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4927,17 +4936,19 @@ def test_list_examples_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_list_examples" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_list_examples_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_list_examples" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_list_examples" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_list_examples_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_list_examples" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4990,8 +5001,9 @@ def test_get_example_rest_bad_request(request_type=example.GetExampleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5064,17 +5076,17 @@ def test_get_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_get_example" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_get_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_get_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_get_example" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_get_example_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ExamplesRestInterceptor, "pre_get_example") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5129,8 +5141,9 @@ def test_update_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5319,17 +5332,19 @@ def test_update_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_update_example" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_update_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_update_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_update_example" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_update_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_update_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5382,8 +5397,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5442,8 +5458,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5504,8 +5521,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5566,8 +5584,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5626,8 +5645,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5844,11 +5864,14 @@ def test_examples_base_transport(): def test_examples_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.examples.transports.ExamplesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.examples.transports.ExamplesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExamplesTransport( @@ -5868,9 +5891,12 @@ def test_examples_base_transport_with_credentials_file(): def test_examples_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.examples.transports.ExamplesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.examples.transports.ExamplesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExamplesTransport() @@ -5948,11 +5974,12 @@ def test_examples_transport_auth_gdch_credentials(transport_class): def test_examples_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6616,6 +6643,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6761,6 +6820,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6906,6 +6999,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7051,6 +7178,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7192,6 +7353,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_experiments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_experiments.py index 070414fe9148..9ab4c6c99f2b 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_experiments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_experiments.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ExperimentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ExperimentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ExperimentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1249,11 +1253,13 @@ def test_experiments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5745,8 +5751,9 @@ def test_list_experiments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5811,17 +5818,19 @@ def test_list_experiments_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_list_experiments" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_list_experiments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_list_experiments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_list_experiments" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_list_experiments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_list_experiments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5876,8 +5885,9 @@ def test_get_experiment_rest_bad_request(request_type=experiment.GetExperimentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5950,17 +5960,19 @@ def test_get_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_get_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_get_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_get_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_get_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_get_experiment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_get_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6015,8 +6027,9 @@ def test_create_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6220,17 +6233,20 @@ def test_create_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_create_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_create_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_create_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_create_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, + "post_create_experiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_create_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6287,8 +6303,9 @@ def test_update_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6494,17 +6511,20 @@ def test_update_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_update_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_update_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_update_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_update_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, + "post_update_experiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_update_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6559,8 +6579,9 @@ def test_delete_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6619,13 +6640,13 @@ def test_delete_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_delete_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_delete_experiment" + ) as pre, + ): pre.assert_not_called() pb_message = experiment.DeleteExperimentRequest.pb( experiment.DeleteExperimentRequest() @@ -6672,8 +6693,9 @@ def test_start_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6746,17 +6768,19 @@ def test_start_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_start_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_start_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_start_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_start_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_start_experiment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_start_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6811,8 +6835,9 @@ def test_stop_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6885,17 +6910,19 @@ def test_stop_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_stop_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_stop_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_stop_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_stop_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_stop_experiment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_stop_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6948,8 +6975,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7008,8 +7036,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7070,8 +7099,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7132,8 +7162,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7192,8 +7223,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7458,11 +7490,14 @@ def test_experiments_base_transport(): def test_experiments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExperimentsTransport( @@ -7482,9 +7517,12 @@ def test_experiments_base_transport_with_credentials_file(): def test_experiments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExperimentsTransport() @@ -7562,11 +7600,12 @@ def test_experiments_transport_auth_gdch_credentials(transport_class): def test_experiments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8179,6 +8218,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8324,6 +8395,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8469,6 +8574,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8614,6 +8753,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8755,6 +8928,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_flows.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_flows.py index 7a9072478e8a..8028dfe3f07b 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_flows.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_flows.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FlowsClient._get_default_mtls_endpoint(None) is None assert FlowsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -158,6 +159,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FlowsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert FlowsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1232,11 +1234,13 @@ def test_flows_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6861,8 +6865,9 @@ def test_create_flow_rest_bad_request(request_type=gcdc_flow.CreateFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7169,17 +7174,15 @@ def test_create_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_create_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_create_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_create_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_create_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_create_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_create_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7230,8 +7233,9 @@ def test_delete_flow_rest_bad_request(request_type=flow.DeleteFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7288,13 +7292,11 @@ def test_delete_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "pre_delete_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "pre_delete_flow") as pre, + ): pre.assert_not_called() pb_message = flow.DeleteFlowRequest.pb(flow.DeleteFlowRequest()) transcode.return_value = { @@ -7335,8 +7337,9 @@ def test_list_flows_rest_bad_request(request_type=flow.ListFlowsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7397,17 +7400,15 @@ def test_list_flows_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_list_flows" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_list_flows_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_list_flows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_list_flows") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_list_flows_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_list_flows") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7458,8 +7459,9 @@ def test_get_flow_rest_bad_request(request_type=flow.GetFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7530,17 +7532,15 @@ def test_get_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_get_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_get_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_get_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_get_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7593,8 +7593,9 @@ def test_update_flow_rest_bad_request(request_type=gcdc_flow.UpdateFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7905,17 +7906,15 @@ def test_update_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_update_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_update_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_update_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_update_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_update_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_update_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7966,8 +7965,9 @@ def test_train_flow_rest_bad_request(request_type=flow.TrainFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8024,19 +8024,16 @@ def test_train_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FlowsRestInterceptor, "post_train_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_train_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_train_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.FlowsRestInterceptor, "post_train_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_train_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_train_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8087,8 +8084,9 @@ def test_validate_flow_rest_bad_request(request_type=flow.ValidateFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8151,17 +8149,17 @@ def test_validate_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_validate_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_validate_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_validate_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FlowsRestInterceptor, "post_validate_flow" + ) as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_validate_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_validate_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8214,8 +8212,9 @@ def test_get_flow_validation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8278,17 +8277,20 @@ def test_get_flow_validation_result_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow_validation_result" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow_validation_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_get_flow_validation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FlowsRestInterceptor, "post_get_flow_validation_result" + ) as post, + mock.patch.object( + transports.FlowsRestInterceptor, + "post_get_flow_validation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FlowsRestInterceptor, "pre_get_flow_validation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8339,8 +8341,9 @@ def test_import_flow_rest_bad_request(request_type=flow.ImportFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8395,19 +8398,16 @@ def test_import_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FlowsRestInterceptor, "post_import_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_import_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_import_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.FlowsRestInterceptor, "post_import_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_import_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_import_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8458,8 +8458,9 @@ def test_export_flow_rest_bad_request(request_type=flow.ExportFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8516,19 +8517,16 @@ def test_export_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FlowsRestInterceptor, "post_export_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_export_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_export_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.FlowsRestInterceptor, "post_export_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_export_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_export_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8579,8 +8577,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8639,8 +8638,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8701,8 +8701,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8763,8 +8764,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8823,8 +8825,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9170,11 +9173,14 @@ def test_flows_base_transport(): def test_flows_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.flows.transports.FlowsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.flows.transports.FlowsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FlowsTransport( @@ -9194,9 +9200,12 @@ def test_flows_base_transport_with_credentials_file(): def test_flows_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.flows.transports.FlowsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.flows.transports.FlowsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FlowsTransport() @@ -9274,11 +9283,12 @@ def test_flows_transport_auth_gdch_credentials(transport_class): def test_flows_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10137,6 +10147,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10282,6 +10324,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10427,6 +10503,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10572,6 +10682,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10713,6 +10857,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_generators.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_generators.py index ce0d8984bc27..c6ba04a2d89b 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_generators.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_generators.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeneratorsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GeneratorsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + GeneratorsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_generators_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4491,8 +4497,9 @@ def test_list_generators_rest_bad_request(request_type=generator.ListGeneratorsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4555,17 +4562,19 @@ def test_list_generators_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_list_generators" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_list_generators" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4620,8 +4629,9 @@ def test_get_generator_rest_bad_request(request_type=generator.GetGeneratorReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4688,17 +4698,19 @@ def test_get_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_get_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_get_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4749,8 +4761,9 @@ def test_create_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4898,17 +4911,19 @@ def test_create_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_create_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_create_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4965,8 +4980,9 @@ def test_update_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5118,17 +5134,19 @@ def test_update_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_update_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_update_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5183,8 +5201,9 @@ def test_delete_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5243,13 +5262,13 @@ def test_delete_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_delete_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_delete_generator" + ) as pre, + ): pre.assert_not_called() pb_message = generator.DeleteGeneratorRequest.pb( generator.DeleteGeneratorRequest() @@ -5294,8 +5313,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5354,8 +5374,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5416,8 +5437,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5478,8 +5500,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5538,8 +5561,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5756,11 +5780,14 @@ def test_generators_base_transport(): def test_generators_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport( @@ -5780,9 +5807,12 @@ def test_generators_base_transport_with_credentials_file(): def test_generators_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport() @@ -5860,11 +5890,12 @@ def test_generators_transport_auth_gdch_credentials(transport_class): def test_generators_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6434,6 +6465,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6579,6 +6642,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6724,6 +6821,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6869,6 +7000,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7010,6 +7175,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_intents.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_intents.py index c020fc2158a7..afa495737fb6 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_intents.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_intents.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IntentsClient._get_default_mtls_endpoint(None) is None assert IntentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -142,6 +143,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert IntentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IntentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1221,11 +1223,13 @@ def test_intents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5326,8 +5330,9 @@ def test_list_intents_rest_bad_request(request_type=intent.ListIntentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5388,17 +5393,17 @@ def test_list_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_list_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_list_intents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5449,8 +5454,9 @@ def test_get_intent_rest_bad_request(request_type=intent.GetIntentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5521,17 +5527,15 @@ def test_get_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_get_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.IntentsRestInterceptor, "post_get_intent") as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_get_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_get_intent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5580,8 +5584,9 @@ def test_create_intent_rest_bad_request(request_type=gcdc_intent.CreateIntentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5740,17 +5745,19 @@ def test_create_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_create_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_create_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5805,8 +5812,9 @@ def test_update_intent_rest_bad_request(request_type=gcdc_intent.UpdateIntentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5969,17 +5977,19 @@ def test_update_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_update_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_update_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6032,8 +6042,9 @@ def test_delete_intent_rest_bad_request(request_type=intent.DeleteIntentRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6090,13 +6101,13 @@ def test_delete_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "pre_delete_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_delete_intent" + ) as pre, + ): pre.assert_not_called() pb_message = intent.DeleteIntentRequest.pb(intent.DeleteIntentRequest()) transcode.return_value = { @@ -6137,8 +6148,9 @@ def test_import_intents_rest_bad_request(request_type=intent.ImportIntentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6193,19 +6205,20 @@ def test_import_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_import_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_import_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_import_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_import_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_import_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_import_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6254,8 +6267,9 @@ def test_export_intents_rest_bad_request(request_type=intent.ExportIntentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6310,19 +6324,20 @@ def test_export_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_export_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_export_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_export_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_export_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_export_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_export_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6373,8 +6388,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6433,8 +6449,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6495,8 +6512,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6557,8 +6575,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6617,8 +6636,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6899,11 +6919,14 @@ def test_intents_base_transport(): def test_intents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport( @@ -6923,9 +6946,12 @@ def test_intents_base_transport_with_credentials_file(): def test_intents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport() @@ -7003,11 +7029,12 @@ def test_intents_transport_auth_gdch_credentials(transport_class): def test_intents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7646,6 +7673,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7791,6 +7850,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7936,6 +8029,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8081,6 +8208,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8222,6 +8383,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_pages.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_pages.py index f9a35b85794e..338eab5b53d6 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_pages.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_pages.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PagesClient._get_default_mtls_endpoint(None) is None assert PagesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -148,6 +149,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PagesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert PagesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1222,11 +1224,13 @@ def test_pages_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4476,8 +4480,9 @@ def test_list_pages_rest_bad_request(request_type=page.ListPagesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4540,17 +4545,15 @@ def test_list_pages_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_list_pages" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_list_pages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_list_pages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_list_pages") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_list_pages_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_list_pages") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4601,8 +4604,9 @@ def test_get_page_rest_bad_request(request_type=page.GetPageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4671,17 +4675,15 @@ def test_get_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_get_page" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_get_page_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_get_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_get_page") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_get_page_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_get_page") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4732,8 +4734,9 @@ def test_create_page_rest_bad_request(request_type=gcdc_page.CreatePageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5026,17 +5029,15 @@ def test_create_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_create_page" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_create_page_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_create_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_create_page") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_create_page_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_create_page") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5089,8 +5090,9 @@ def test_update_page_rest_bad_request(request_type=gcdc_page.UpdatePageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5385,17 +5387,15 @@ def test_update_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_update_page" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_update_page_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_update_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_update_page") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_update_page_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_update_page") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5446,8 +5446,9 @@ def test_delete_page_rest_bad_request(request_type=page.DeletePageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5504,13 +5505,11 @@ def test_delete_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "pre_delete_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "pre_delete_page") as pre, + ): pre.assert_not_called() pb_message = page.DeletePageRequest.pb(page.DeletePageRequest()) transcode.return_value = { @@ -5553,8 +5552,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5613,8 +5613,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5675,8 +5676,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5737,8 +5739,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5797,8 +5800,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6015,11 +6019,14 @@ def test_pages_base_transport(): def test_pages_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.pages.transports.PagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.pages.transports.PagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PagesTransport( @@ -6039,9 +6046,12 @@ def test_pages_base_transport_with_credentials_file(): def test_pages_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.pages.transports.PagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.pages.transports.PagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PagesTransport() @@ -6119,11 +6129,12 @@ def test_pages_transport_auth_gdch_credentials(transport_class): def test_pages_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6933,6 +6944,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7078,6 +7121,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7223,6 +7300,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7368,6 +7479,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7509,6 +7654,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_playbooks.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_playbooks.py index ddd7bd49d8f6..541e8a6f293c 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_playbooks.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_playbooks.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PlaybooksClient._get_default_mtls_endpoint(None) is None assert PlaybooksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -159,6 +160,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PlaybooksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + PlaybooksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1259,11 +1263,13 @@ def test_playbooks_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8581,8 +8587,9 @@ def test_create_playbook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8879,17 +8886,19 @@ def test_create_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_create_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_create_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_create_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_create_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_create_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_create_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8942,8 +8951,9 @@ def test_delete_playbook_rest_bad_request(request_type=playbook.DeletePlaybookRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9000,13 +9010,13 @@ def test_delete_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_delete_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_delete_playbook" + ) as pre, + ): pre.assert_not_called() pb_message = playbook.DeletePlaybookRequest.pb(playbook.DeletePlaybookRequest()) transcode.return_value = { @@ -9047,8 +9057,9 @@ def test_list_playbooks_rest_bad_request(request_type=playbook.ListPlaybooksRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9109,17 +9120,19 @@ def test_list_playbooks_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbooks" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbooks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_list_playbooks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_list_playbooks" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_list_playbooks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_list_playbooks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9172,8 +9185,9 @@ def test_get_playbook_rest_bad_request(request_type=playbook.GetPlaybookRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9252,17 +9266,19 @@ def test_get_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_get_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_get_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_get_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_get_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9313,8 +9329,9 @@ def test_export_playbook_rest_bad_request(request_type=playbook.ExportPlaybookRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9371,19 +9388,20 @@ def test_export_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PlaybooksRestInterceptor, "post_export_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_export_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_export_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_export_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_export_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_export_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9432,8 +9450,9 @@ def test_import_playbook_rest_bad_request(request_type=playbook.ImportPlaybookRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9488,19 +9507,20 @@ def test_import_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PlaybooksRestInterceptor, "post_import_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_import_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_import_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_import_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_import_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_import_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9555,8 +9575,9 @@ def test_update_playbook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9857,17 +9878,19 @@ def test_update_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_update_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_update_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_update_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_update_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_update_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_update_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9922,8 +9945,9 @@ def test_create_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10262,18 +10286,20 @@ def test_create_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_create_playbook_version" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, - "post_create_playbook_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_create_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_create_playbook_version" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_create_playbook_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_create_playbook_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10328,8 +10354,9 @@ def test_get_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10394,17 +10421,20 @@ def test_get_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook_version" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_get_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_get_playbook_version" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_get_playbook_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_get_playbook_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10459,8 +10489,9 @@ def test_restore_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10520,18 +10551,20 @@ def test_restore_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_restore_playbook_version" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, - "post_restore_playbook_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_restore_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_restore_playbook_version" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_restore_playbook_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_restore_playbook_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10591,8 +10624,9 @@ def test_list_playbook_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10655,17 +10689,20 @@ def test_list_playbook_versions_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbook_versions" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbook_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_list_playbook_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_list_playbook_versions" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_list_playbook_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_list_playbook_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10725,8 +10762,9 @@ def test_delete_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10783,13 +10821,13 @@ def test_delete_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_delete_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_delete_playbook_version" + ) as pre, + ): pre.assert_not_called() pb_message = playbook.DeletePlaybookVersionRequest.pb( playbook.DeletePlaybookVersionRequest() @@ -10834,8 +10872,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10894,8 +10933,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10956,8 +10996,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11018,8 +11059,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11078,8 +11120,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11475,11 +11518,14 @@ def test_playbooks_base_transport(): def test_playbooks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PlaybooksTransport( @@ -11499,9 +11545,12 @@ def test_playbooks_base_transport_with_credentials_file(): def test_playbooks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PlaybooksTransport() @@ -11579,11 +11628,12 @@ def test_playbooks_transport_auth_gdch_credentials(transport_class): def test_playbooks_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12394,6 +12444,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12539,6 +12621,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12684,6 +12800,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12829,6 +12979,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12970,6 +13154,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_security_settings_service.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_security_settings_service.py index 8c05b320ad43..7e8fba784cfe 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_security_settings_service.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_security_settings_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SecuritySettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): SecuritySettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SecuritySettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_security_settings_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4898,8 +4905,9 @@ def test_create_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5073,20 +5081,22 @@ def test_create_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_create_security_settings", - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_create_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "pre_create_security_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_create_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_create_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_create_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5146,8 +5156,9 @@ def test_get_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5235,18 +5246,22 @@ def test_get_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "post_get_security_settings" - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_get_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "pre_get_security_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_get_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_get_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_get_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5305,8 +5320,9 @@ def test_update_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5484,20 +5500,22 @@ def test_update_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_update_security_settings", - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_update_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "pre_update_security_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_update_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_update_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_update_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5555,8 +5573,9 @@ def test_list_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5619,18 +5638,22 @@ def test_list_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "post_list_security_settings" - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_list_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "pre_list_security_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_list_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_list_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_list_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5690,8 +5713,9 @@ def test_delete_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5750,14 +5774,14 @@ def test_delete_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "pre_delete_security_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_delete_security_settings", + ) as pre, + ): pre.assert_not_called() pb_message = security_settings.DeleteSecuritySettingsRequest.pb( security_settings.DeleteSecuritySettingsRequest() @@ -5802,8 +5826,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5862,8 +5887,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5924,8 +5950,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5986,8 +6013,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6046,8 +6074,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6274,11 +6303,14 @@ def test_security_settings_service_base_transport(): def test_security_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecuritySettingsServiceTransport( @@ -6298,9 +6330,12 @@ def test_security_settings_service_base_transport_with_credentials_file(): def test_security_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecuritySettingsServiceTransport() @@ -6380,11 +6415,12 @@ def test_security_settings_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7022,6 +7058,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7167,6 +7235,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7312,6 +7414,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7457,6 +7593,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7602,6 +7772,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_session_entity_types.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_session_entity_types.py index 676b3e74cf35..b7d5a34c370b 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_session_entity_types.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_session_entity_types.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionEntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): SessionEntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionEntityTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1328,11 +1333,13 @@ def test_session_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4759,8 +4766,9 @@ def test_list_session_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4827,18 +4835,22 @@ def test_list_session_entity_types_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_list_session_entity_types" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_list_session_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_list_session_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_list_session_entity_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4898,8 +4910,9 @@ def test_get_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4969,18 +4982,20 @@ def test_get_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_get_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_get_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5040,8 +5055,9 @@ def test_create_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5187,18 +5203,22 @@ def test_create_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_create_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_create_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_create_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_create_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5260,8 +5280,9 @@ def test_update_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5409,18 +5430,22 @@ def test_update_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_update_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_update_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_update_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_update_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5480,8 +5505,9 @@ def test_delete_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5540,13 +5566,14 @@ def test_delete_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_delete_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_delete_session_entity_type", + ) as pre, + ): pre.assert_not_called() pb_message = session_entity_type.DeleteSessionEntityTypeRequest.pb( session_entity_type.DeleteSessionEntityTypeRequest() @@ -5591,8 +5618,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5651,8 +5679,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5713,8 +5742,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5775,8 +5805,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5835,8 +5866,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6063,11 +6095,14 @@ def test_session_entity_types_base_transport(): def test_session_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport( @@ -6087,9 +6122,12 @@ def test_session_entity_types_base_transport_with_credentials_file(): def test_session_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport() @@ -6167,11 +6205,12 @@ def test_session_entity_types_transport_auth_gdch_credentials(transport_class): def test_session_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6759,6 +6798,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6904,6 +6975,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7049,6 +7154,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7194,6 +7333,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7335,6 +7508,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_sessions.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_sessions.py index 571fdde4947d..b136bc27c4e9 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_sessions.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_sessions.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionsClient._get_default_mtls_endpoint(None) is None assert SessionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -149,6 +150,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SessionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert SessionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1238,11 +1240,13 @@ def test_sessions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3652,8 +3656,9 @@ def test_detect_intent_rest_bad_request(request_type=session.DetectIntentRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3722,17 +3727,19 @@ def test_detect_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_detect_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_detect_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3787,8 +3794,9 @@ def test_server_streaming_detect_intent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3861,18 +3869,20 @@ def test_server_streaming_detect_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_server_streaming_detect_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, - "post_server_streaming_detect_intent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_server_streaming_detect_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_server_streaming_detect_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, + "post_server_streaming_detect_intent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_server_streaming_detect_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3937,8 +3947,9 @@ def test_match_intent_rest_bad_request(request_type=session.MatchIntentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4000,17 +4011,19 @@ def test_match_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_match_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_match_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_match_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_match_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_match_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_match_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4065,8 +4078,9 @@ def test_fulfill_intent_rest_bad_request(request_type=session.FulfillIntentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4133,17 +4147,19 @@ def test_fulfill_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_fulfill_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_fulfill_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_fulfill_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_fulfill_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_fulfill_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_fulfill_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4198,8 +4214,9 @@ def test_submit_answer_feedback_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4264,17 +4281,20 @@ def test_submit_answer_feedback_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_submit_answer_feedback" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_submit_answer_feedback_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_submit_answer_feedback" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_submit_answer_feedback" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, + "post_submit_answer_feedback_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_submit_answer_feedback" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4327,8 +4347,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4387,8 +4408,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4449,8 +4471,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4511,8 +4534,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4571,8 +4595,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4794,11 +4819,14 @@ def test_sessions_base_transport(): def test_sessions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport( @@ -4818,9 +4846,12 @@ def test_sessions_base_transport_with_credentials_file(): def test_sessions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport() @@ -4898,11 +4929,12 @@ def test_sessions_transport_auth_gdch_credentials(transport_class): def test_sessions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5840,6 +5872,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5985,6 +6049,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6130,6 +6228,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6275,6 +6407,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6416,6 +6582,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_test_cases.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_test_cases.py index 207b8948443e..0e676a375b4d 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_test_cases.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_test_cases.py @@ -144,6 +144,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TestCasesClient._get_default_mtls_endpoint(None) is None assert TestCasesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -160,6 +161,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TestCasesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TestCasesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1262,11 +1266,13 @@ def test_test_cases_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8179,8 +8185,9 @@ def test_list_test_cases_rest_bad_request(request_type=test_case.ListTestCasesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8241,17 +8248,19 @@ def test_list_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_list_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_list_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_list_test_cases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_list_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8304,8 +8313,9 @@ def test_batch_delete_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8360,13 +8370,13 @@ def test_batch_delete_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_batch_delete_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_batch_delete_test_cases" + ) as pre, + ): pre.assert_not_called() pb_message = test_case.BatchDeleteTestCasesRequest.pb( test_case.BatchDeleteTestCasesRequest() @@ -8411,8 +8421,9 @@ def test_get_test_case_rest_bad_request(request_type=test_case.GetTestCaseReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8481,17 +8492,19 @@ def test_get_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_get_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_get_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_get_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_get_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8542,8 +8555,9 @@ def test_create_test_case_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8952,17 +8966,19 @@ def test_create_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_create_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_create_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_create_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_create_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_create_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_create_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9019,8 +9035,9 @@ def test_update_test_case_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9433,17 +9450,19 @@ def test_update_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_update_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_update_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_update_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_update_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_update_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_update_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9496,8 +9515,9 @@ def test_run_test_case_rest_bad_request(request_type=test_case.RunTestCaseReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9554,19 +9574,20 @@ def test_run_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_run_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_run_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_run_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_run_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_run_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_run_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9617,8 +9638,9 @@ def test_batch_run_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9673,19 +9695,21 @@ def test_batch_run_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_batch_run_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_batch_run_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_batch_run_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_batch_run_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, + "post_batch_run_test_cases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_batch_run_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9738,8 +9762,9 @@ def test_calculate_coverage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9800,17 +9825,19 @@ def test_calculate_coverage_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_calculate_coverage" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_calculate_coverage_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_calculate_coverage" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_calculate_coverage" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_calculate_coverage_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_calculate_coverage" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9868,8 +9895,9 @@ def test_import_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9924,19 +9952,20 @@ def test_import_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_import_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_import_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_import_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_import_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_import_test_cases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_import_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9989,8 +10018,9 @@ def test_export_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10045,19 +10075,20 @@ def test_export_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_export_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_export_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_export_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_export_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_export_test_cases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_export_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10112,8 +10143,9 @@ def test_list_test_case_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10176,17 +10208,20 @@ def test_list_test_case_results_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_case_results" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_case_results_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_list_test_case_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_list_test_case_results" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, + "post_list_test_case_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_list_test_case_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10246,8 +10281,9 @@ def test_get_test_case_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10314,17 +10350,20 @@ def test_get_test_case_result_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case_result" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_get_test_case_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_get_test_case_result" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, + "post_get_test_case_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_get_test_case_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10377,8 +10416,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10437,8 +10477,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10499,8 +10540,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10561,8 +10603,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10621,8 +10664,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11022,11 +11066,14 @@ def test_test_cases_base_transport(): def test_test_cases_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TestCasesTransport( @@ -11046,9 +11093,12 @@ def test_test_cases_base_transport_with_credentials_file(): def test_test_cases_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TestCasesTransport() @@ -11126,11 +11176,12 @@ def test_test_cases_transport_auth_gdch_credentials(transport_class): def test_test_cases_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12117,6 +12168,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12262,6 +12345,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12407,6 +12524,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12552,6 +12703,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12693,6 +12878,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_tools.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_tools.py index 8fd4623199f4..3786f89708c8 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_tools.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_tools.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ToolsClient._get_default_mtls_endpoint(None) is None assert ToolsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ToolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ToolsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1214,11 +1216,13 @@ def test_tools_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7571,8 +7575,9 @@ def test_create_tool_rest_bad_request(request_type=gcdc_tool.CreateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7756,17 +7761,15 @@ def test_create_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_create_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_create_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_create_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7815,8 +7818,9 @@ def test_list_tools_rest_bad_request(request_type=tool.ListToolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7877,17 +7881,15 @@ def test_list_tools_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_list_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_list_tools") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_list_tools") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7938,8 +7940,9 @@ def test_get_tool_rest_bad_request(request_type=tool.GetToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8008,17 +8011,15 @@ def test_get_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_get_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_get_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_get_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8071,8 +8072,9 @@ def test_update_tool_rest_bad_request(request_type=gcdc_tool.UpdateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8260,17 +8262,15 @@ def test_update_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_update_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_update_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_update_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_update_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8321,8 +8321,9 @@ def test_delete_tool_rest_bad_request(request_type=tool.DeleteToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8379,13 +8380,11 @@ def test_delete_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "pre_delete_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "pre_delete_tool") as pre, + ): pre.assert_not_called() pb_message = tool.DeleteToolRequest.pb(tool.DeleteToolRequest()) transcode.return_value = { @@ -8428,8 +8427,9 @@ def test_list_tool_versions_rest_bad_request(request_type=tool.ListToolVersionsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8492,17 +8492,19 @@ def test_list_tool_versions_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tool_versions" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tool_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_list_tool_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tool_versions" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tool_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_list_tool_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8557,8 +8559,9 @@ def test_create_tool_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8746,17 +8749,19 @@ def test_create_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_version" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_create_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_version" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_create_tool_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8807,8 +8812,9 @@ def test_get_tool_version_rest_bad_request(request_type=tool.GetToolVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8873,17 +8879,19 @@ def test_get_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_version" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_get_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_version" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_get_tool_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8936,8 +8944,9 @@ def test_delete_tool_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8994,13 +9003,13 @@ def test_delete_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "pre_delete_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_delete_tool_version" + ) as pre, + ): pre.assert_not_called() pb_message = tool.DeleteToolVersionRequest.pb(tool.DeleteToolVersionRequest()) transcode.return_value = { @@ -9045,8 +9054,9 @@ def test_restore_tool_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9106,17 +9116,19 @@ def test_restore_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_restore_tool_version" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_restore_tool_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_restore_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_restore_tool_version" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_restore_tool_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_restore_tool_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9169,8 +9181,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9229,8 +9242,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9291,8 +9305,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9353,8 +9368,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9413,8 +9429,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9744,11 +9761,14 @@ def test_tools_base_transport(): def test_tools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport( @@ -9768,9 +9788,12 @@ def test_tools_base_transport_with_credentials_file(): def test_tools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport() @@ -9848,11 +9871,12 @@ def test_tools_transport_auth_gdch_credentials(transport_class): def test_tools_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10522,6 +10546,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10667,6 +10723,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10812,6 +10902,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10957,6 +11081,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11098,6 +11256,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_transition_route_groups.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_transition_route_groups.py index 87489736549e..1b6cf18ee929 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_transition_route_groups.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_transition_route_groups.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TransitionRouteGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): TransitionRouteGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TransitionRouteGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1358,11 +1363,13 @@ def test_transition_route_groups_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4813,8 +4820,9 @@ def test_list_transition_route_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4881,20 +4889,22 @@ def test_list_transition_route_groups_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_list_transition_route_groups", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_list_transition_route_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_list_transition_route_groups", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_list_transition_route_groups", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_list_transition_route_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_list_transition_route_groups", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4954,8 +4964,9 @@ def test_get_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5022,20 +5033,22 @@ def test_get_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_get_transition_route_group", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_get_transition_route_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_get_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_get_transition_route_group", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_get_transition_route_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_get_transition_route_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5095,8 +5108,9 @@ def test_create_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5350,20 +5364,22 @@ def test_create_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_create_transition_route_group", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_create_transition_route_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_create_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_create_transition_route_group", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_create_transition_route_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_create_transition_route_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5425,8 +5441,9 @@ def test_update_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5682,20 +5699,22 @@ def test_update_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_update_transition_route_group", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_update_transition_route_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_update_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_update_transition_route_group", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_update_transition_route_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_update_transition_route_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5755,8 +5774,9 @@ def test_delete_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5815,14 +5835,14 @@ def test_delete_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_delete_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_delete_transition_route_group", + ) as pre, + ): pre.assert_not_called() pb_message = transition_route_group.DeleteTransitionRouteGroupRequest.pb( transition_route_group.DeleteTransitionRouteGroupRequest() @@ -5867,8 +5887,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5927,8 +5948,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5989,8 +6011,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6051,8 +6074,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6111,8 +6135,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6339,11 +6364,14 @@ def test_transition_route_groups_base_transport(): def test_transition_route_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TransitionRouteGroupsTransport( @@ -6363,9 +6391,12 @@ def test_transition_route_groups_base_transport_with_credentials_file(): def test_transition_route_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TransitionRouteGroupsTransport() @@ -6445,11 +6476,12 @@ def test_transition_route_groups_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7220,6 +7252,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7365,6 +7429,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7510,6 +7608,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7655,6 +7787,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7798,6 +7964,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_versions.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_versions.py index 10e653b4ec38..09b4d231b3cc 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_versions.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_versions.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VersionsClient._get_default_mtls_endpoint(None) is None assert VersionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -146,6 +147,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert VersionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1235,11 +1237,13 @@ def test_versions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5596,8 +5600,9 @@ def test_list_versions_rest_bad_request(request_type=version.ListVersionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5660,17 +5665,19 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5723,8 +5730,9 @@ def test_get_version_rest_bad_request(request_type=version.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5793,17 +5801,17 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VersionsRestInterceptor, "pre_get_version") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5856,8 +5864,9 @@ def test_create_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5993,19 +6002,20 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6062,8 +6072,9 @@ def test_update_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6213,17 +6224,19 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6276,8 +6289,9 @@ def test_delete_version_rest_bad_request(request_type=version.DeleteVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6334,13 +6348,13 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() pb_message = version.DeleteVersionRequest.pb(version.DeleteVersionRequest()) transcode.return_value = { @@ -6383,8 +6397,9 @@ def test_load_version_rest_bad_request(request_type=version.LoadVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6441,19 +6456,20 @@ def test_load_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_load_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_load_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_load_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_load_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_load_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_load_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6504,8 +6520,9 @@ def test_compare_versions_rest_bad_request(request_type=version.CompareVersionsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6570,17 +6587,19 @@ def test_compare_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_compare_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_compare_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_compare_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_compare_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_compare_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_compare_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6633,8 +6652,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6693,8 +6713,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6755,8 +6776,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6817,8 +6839,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6877,8 +6900,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7159,11 +7183,14 @@ def test_versions_base_transport(): def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport( @@ -7183,9 +7210,12 @@ def test_versions_base_transport_with_credentials_file(): def test_versions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport() @@ -7263,11 +7293,12 @@ def test_versions_transport_auth_gdch_credentials(transport_class): def test_versions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7880,6 +7911,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8025,6 +8088,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8170,6 +8267,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8315,6 +8446,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8456,6 +8621,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_webhooks.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_webhooks.py index 0705e008a0c5..b4eba9a2b2b0 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_webhooks.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3/test_webhooks.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WebhooksClient._get_default_mtls_endpoint(None) is None assert WebhooksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert WebhooksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert WebhooksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_webhooks_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4447,8 +4451,9 @@ def test_list_webhooks_rest_bad_request(request_type=webhook.ListWebhooksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4509,17 +4514,19 @@ def test_list_webhooks_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_list_webhooks" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_list_webhooks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_list_webhooks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_list_webhooks" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_list_webhooks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_list_webhooks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4572,8 +4579,9 @@ def test_get_webhook_rest_bad_request(request_type=webhook.GetWebhookRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4640,17 +4648,17 @@ def test_get_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_get_webhook" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_get_webhook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_get_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_get_webhook" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_get_webhook_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WebhooksRestInterceptor, "pre_get_webhook") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4701,8 +4709,9 @@ def test_create_webhook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4863,17 +4872,19 @@ def test_create_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_create_webhook" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_create_webhook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_create_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_create_webhook" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_create_webhook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_create_webhook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4930,8 +4941,9 @@ def test_update_webhook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5096,17 +5108,19 @@ def test_update_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_update_webhook" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_update_webhook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_update_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_update_webhook" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_update_webhook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_update_webhook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5159,8 +5173,9 @@ def test_delete_webhook_rest_bad_request(request_type=webhook.DeleteWebhookReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5217,13 +5232,13 @@ def test_delete_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_delete_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_delete_webhook" + ) as pre, + ): pre.assert_not_called() pb_message = webhook.DeleteWebhookRequest.pb(webhook.DeleteWebhookRequest()) transcode.return_value = { @@ -5266,8 +5281,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5326,8 +5342,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5388,8 +5405,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5450,8 +5468,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5510,8 +5529,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5728,11 +5748,14 @@ def test_webhooks_base_transport(): def test_webhooks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebhooksTransport( @@ -5752,9 +5775,12 @@ def test_webhooks_base_transport_with_credentials_file(): def test_webhooks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebhooksTransport() @@ -5832,11 +5858,12 @@ def test_webhooks_transport_auth_gdch_credentials(transport_class): def test_webhooks_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6461,6 +6488,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6606,6 +6665,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6751,6 +6844,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6896,6 +7023,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7037,6 +7198,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py index 11b76352b066..eafe5c06efda 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_agents.py @@ -142,6 +142,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AgentsClient._get_default_mtls_endpoint(None) is None assert AgentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -157,6 +158,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AgentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AgentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1235,11 +1237,13 @@ def test_agents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7645,8 +7649,9 @@ def test_list_agents_rest_bad_request(request_type=agent.ListAgentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7707,17 +7712,15 @@ def test_list_agents_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_list_agents" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_list_agents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_list_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_list_agents") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_list_agents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_list_agents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7766,8 +7769,9 @@ def test_get_agent_rest_bad_request(request_type=agent.GetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7855,17 +7859,15 @@ def test_get_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_get_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_get_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7914,8 +7916,9 @@ def test_create_agent_rest_bad_request(request_type=gcdc_agent.CreateAgentReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8142,17 +8145,17 @@ def test_create_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_create_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_create_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_create_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_create_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_create_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_create_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8203,8 +8206,9 @@ def test_update_agent_rest_bad_request(request_type=gcdc_agent.UpdateAgentReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8433,17 +8437,17 @@ def test_update_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_update_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_update_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_update_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_update_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_update_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_update_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8492,8 +8496,9 @@ def test_delete_agent_rest_bad_request(request_type=agent.DeleteAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8548,13 +8553,11 @@ def test_delete_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "pre_delete_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "pre_delete_agent") as pre, + ): pre.assert_not_called() pb_message = agent.DeleteAgentRequest.pb(agent.DeleteAgentRequest()) transcode.return_value = { @@ -8595,8 +8598,9 @@ def test_export_agent_rest_bad_request(request_type=agent.ExportAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8651,19 +8655,18 @@ def test_export_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_export_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_export_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8712,8 +8715,9 @@ def test_restore_agent_rest_bad_request(request_type=agent.RestoreAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8768,19 +8772,18 @@ def test_restore_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_restore_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_restore_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8829,8 +8832,9 @@ def test_validate_agent_rest_bad_request(request_type=agent.ValidateAgentRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8891,17 +8895,19 @@ def test_validate_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_validate_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_validate_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_validate_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_validate_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_validate_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_validate_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8956,8 +8962,9 @@ def test_get_agent_validation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9020,18 +9027,20 @@ def test_get_agent_validation_result_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent_validation_result" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, - "post_get_agent_validation_result_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_agent_validation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_agent_validation_result" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, + "post_get_agent_validation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_get_agent_validation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9088,8 +9097,9 @@ def test_get_generative_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9154,17 +9164,20 @@ def test_get_generative_settings_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_generative_settings" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_generative_settings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_generative_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_generative_settings" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, + "post_get_generative_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_get_generative_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9226,8 +9239,9 @@ def test_update_generative_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9403,18 +9417,20 @@ def test_update_generative_settings_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_update_generative_settings" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, - "post_update_generative_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_update_generative_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_update_generative_settings" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, + "post_update_generative_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_update_generative_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9472,8 +9488,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9532,8 +9549,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9594,8 +9612,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9656,8 +9675,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9716,8 +9736,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10088,11 +10109,14 @@ def test_agents_base_transport(): def test_agents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport( @@ -10112,9 +10136,12 @@ def test_agents_base_transport_with_credentials_file(): def test_agents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport() @@ -10192,11 +10219,12 @@ def test_agents_transport_auth_gdch_credentials(transport_class): def test_agents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11037,6 +11065,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11182,6 +11242,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11327,6 +11421,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11472,6 +11600,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11613,6 +11775,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_changelogs.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_changelogs.py index a408c1b593bc..71a89d3a13d1 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_changelogs.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_changelogs.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ChangelogsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ChangelogsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ChangelogsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_changelogs_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2807,8 +2813,9 @@ def test_list_changelogs_rest_bad_request(request_type=changelog.ListChangelogsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2871,17 +2878,19 @@ def test_list_changelogs_rest_interceptors(null_interceptor): ) client = ChangelogsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_list_changelogs" - ) as post, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_list_changelogs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChangelogsRestInterceptor, "pre_list_changelogs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_list_changelogs" + ) as post, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_list_changelogs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChangelogsRestInterceptor, "pre_list_changelogs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2936,8 +2945,9 @@ def test_get_changelog_rest_bad_request(request_type=changelog.GetChangelogReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3014,17 +3024,19 @@ def test_get_changelog_rest_interceptors(null_interceptor): ) client = ChangelogsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_get_changelog" - ) as post, mock.patch.object( - transports.ChangelogsRestInterceptor, "post_get_changelog_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChangelogsRestInterceptor, "pre_get_changelog" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_get_changelog" + ) as post, + mock.patch.object( + transports.ChangelogsRestInterceptor, "post_get_changelog_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChangelogsRestInterceptor, "pre_get_changelog" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3075,8 +3087,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3135,8 +3148,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3197,8 +3211,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3259,8 +3274,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3319,8 +3335,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3474,11 +3491,14 @@ def test_changelogs_base_transport(): def test_changelogs_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChangelogsTransport( @@ -3498,9 +3518,12 @@ def test_changelogs_base_transport_with_credentials_file(): def test_changelogs_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.changelogs.transports.ChangelogsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChangelogsTransport() @@ -3578,11 +3601,12 @@ def test_changelogs_transport_auth_gdch_credentials(transport_class): def test_changelogs_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4143,6 +4167,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4288,6 +4344,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4433,6 +4523,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4578,6 +4702,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4719,6 +4877,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ChangelogsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ChangelogsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ChangelogsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py index cf0a5040ee0b..30a7e639b815 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_conversation_history.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationHistoryClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): ConversationHistoryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationHistoryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_conversation_history_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3504,8 +3511,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3568,18 +3576,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ConversationHistoryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationHistoryRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ConversationHistoryRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationHistoryRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3639,8 +3649,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3709,18 +3720,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ConversationHistoryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationHistoryRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ConversationHistoryRestInterceptor, - "post_get_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationHistoryRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3777,8 +3790,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3837,13 +3851,13 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = ConversationHistoryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationHistoryRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationHistoryRestInterceptor, "pre_delete_conversation" + ) as pre, + ): pre.assert_not_called() pb_message = conversation_history.DeleteConversationRequest.pb( conversation_history.DeleteConversationRequest() @@ -3888,8 +3902,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3948,8 +3963,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4010,8 +4026,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4072,8 +4089,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4132,8 +4150,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4312,11 +4331,14 @@ def test_conversation_history_base_transport(): def test_conversation_history_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.conversation_history.transports.ConversationHistoryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.conversation_history.transports.ConversationHistoryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationHistoryTransport( @@ -4336,9 +4358,12 @@ def test_conversation_history_base_transport_with_credentials_file(): def test_conversation_history_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.conversation_history.transports.ConversationHistoryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.conversation_history.transports.ConversationHistoryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationHistoryTransport() @@ -4416,11 +4441,12 @@ def test_conversation_history_transport_auth_gdch_credentials(transport_class): def test_conversation_history_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5552,6 +5578,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationHistoryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationHistoryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationHistoryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5697,6 +5755,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationHistoryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationHistoryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationHistoryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5842,6 +5934,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationHistoryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationHistoryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationHistoryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5987,6 +6113,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationHistoryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationHistoryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationHistoryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6130,6 +6290,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationHistoryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationHistoryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationHistoryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_deployments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_deployments.py index 06d8956199b3..3b757c1f69d3 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_deployments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_deployments.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DeploymentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DeploymentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DeploymentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1246,11 +1250,13 @@ def test_deployments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2807,8 +2813,9 @@ def test_list_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2873,17 +2880,19 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = DeploymentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeploymentsRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_list_deployments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentsRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2938,8 +2947,9 @@ def test_get_deployment_rest_bad_request(request_type=deployment.GetDeploymentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3008,17 +3018,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = DeploymentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.DeploymentsRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DeploymentsRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.DeploymentsRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DeploymentsRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3071,8 +3083,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3131,8 +3144,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3193,8 +3207,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3255,8 +3270,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3315,8 +3331,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3470,11 +3487,14 @@ def test_deployments_base_transport(): def test_deployments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeploymentsTransport( @@ -3494,9 +3514,12 @@ def test_deployments_base_transport_with_credentials_file(): def test_deployments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.deployments.transports.DeploymentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DeploymentsTransport() @@ -3574,11 +3597,12 @@ def test_deployments_transport_auth_gdch_credentials(transport_class): def test_deployments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4244,6 +4268,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4389,6 +4445,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4534,6 +4624,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4679,6 +4803,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4820,6 +4978,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DeploymentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DeploymentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DeploymentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_entity_types.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_entity_types.py index b7cb9be23644..5bf3ecf2f2f6 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_entity_types.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_entity_types.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EntityTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1251,11 +1255,13 @@ def test_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5585,8 +5591,9 @@ def test_get_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5664,17 +5671,19 @@ def test_get_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_get_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_get_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5727,8 +5736,9 @@ def test_create_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5883,17 +5893,20 @@ def test_create_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_create_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_create_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_create_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_create_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5952,8 +5965,9 @@ def test_update_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6112,17 +6126,20 @@ def test_update_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_update_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_update_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_update_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_update_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6179,8 +6196,9 @@ def test_delete_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6239,13 +6257,13 @@ def test_delete_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_delete_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_delete_entity_type" + ) as pre, + ): pre.assert_not_called() pb_message = entity_type.DeleteEntityTypeRequest.pb( entity_type.DeleteEntityTypeRequest() @@ -6290,8 +6308,9 @@ def test_list_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6354,17 +6373,20 @@ def test_list_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_list_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_list_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_list_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_list_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6422,8 +6444,9 @@ def test_export_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6480,19 +6503,21 @@ def test_export_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_export_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_export_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_export_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_export_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_export_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_export_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6545,8 +6570,9 @@ def test_import_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6603,19 +6629,21 @@ def test_import_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_import_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_import_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_import_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_import_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_import_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_import_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6668,8 +6696,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6728,8 +6757,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6790,8 +6820,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6852,8 +6883,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6912,8 +6944,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7206,11 +7239,14 @@ def test_entity_types_base_transport(): def test_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport( @@ -7230,9 +7266,12 @@ def test_entity_types_base_transport_with_credentials_file(): def test_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport() @@ -7310,11 +7349,12 @@ def test_entity_types_transport_auth_gdch_credentials(transport_class): def test_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7924,6 +7964,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8069,6 +8141,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8214,6 +8320,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8359,6 +8499,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8500,6 +8674,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py index b14887c0a6d1..07460bfacf9d 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_environments.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EnvironmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EnvironmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EnvironmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1268,11 +1273,13 @@ def test_environments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7192,8 +7199,9 @@ def test_list_environments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7256,17 +7264,20 @@ def test_list_environments_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_list_environments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_list_environments" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_list_environments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_list_environments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7326,8 +7337,9 @@ def test_get_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7396,17 +7408,19 @@ def test_get_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_get_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_get_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7459,8 +7473,9 @@ def test_create_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7637,19 +7652,21 @@ def test_create_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_create_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_create_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_create_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_create_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7706,8 +7723,9 @@ def test_update_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7888,19 +7906,21 @@ def test_update_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_update_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_update_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_update_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_update_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7955,8 +7975,9 @@ def test_delete_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8015,13 +8036,13 @@ def test_delete_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_delete_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_delete_environment" + ) as pre, + ): pre.assert_not_called() pb_message = environment.DeleteEnvironmentRequest.pb( environment.DeleteEnvironmentRequest() @@ -8068,8 +8089,9 @@ def test_lookup_environment_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8134,18 +8156,20 @@ def test_lookup_environment_history_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_lookup_environment_history" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, - "post_lookup_environment_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_lookup_environment_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_lookup_environment_history" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_lookup_environment_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_lookup_environment_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8205,8 +8229,9 @@ def test_run_continuous_test_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8265,19 +8290,21 @@ def test_run_continuous_test_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_run_continuous_test" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_run_continuous_test_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_run_continuous_test" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_run_continuous_test" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_run_continuous_test_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_run_continuous_test" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8332,8 +8359,9 @@ def test_list_continuous_test_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8398,18 +8426,20 @@ def test_list_continuous_test_results_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_continuous_test_results" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, - "post_list_continuous_test_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_list_continuous_test_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_list_continuous_test_results" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_list_continuous_test_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_list_continuous_test_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8467,8 +8497,9 @@ def test_deploy_flow_rest_bad_request(request_type=environment.DeployFlowRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8527,19 +8558,20 @@ def test_deploy_flow_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_deploy_flow" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_deploy_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_deploy_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_deploy_flow" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_deploy_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_deploy_flow" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8590,8 +8622,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8650,8 +8683,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8712,8 +8746,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8774,8 +8809,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8834,8 +8870,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9172,11 +9209,14 @@ def test_environments_base_transport(): def test_environments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport( @@ -9196,9 +9236,12 @@ def test_environments_base_transport_with_credentials_file(): def test_environments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport() @@ -9276,11 +9319,12 @@ def test_environments_transport_auth_gdch_credentials(transport_class): def test_environments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10109,6 +10153,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10254,6 +10330,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10399,6 +10509,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10544,6 +10688,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10685,6 +10863,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py index 3069667d16a5..0e6135b90deb 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_examples.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ExamplesClient._get_default_mtls_endpoint(None) is None assert ExamplesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -145,6 +146,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ExamplesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ExamplesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1234,11 +1236,13 @@ def test_examples_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4509,8 +4513,9 @@ def test_create_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4821,17 +4826,19 @@ def test_create_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_create_example" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_create_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_create_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_create_example" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_create_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_create_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4884,8 +4891,9 @@ def test_delete_example_rest_bad_request(request_type=example.DeleteExampleReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4942,13 +4950,13 @@ def test_delete_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_delete_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_delete_example" + ) as pre, + ): pre.assert_not_called() pb_message = example.DeleteExampleRequest.pb(example.DeleteExampleRequest()) transcode.return_value = { @@ -4991,8 +4999,9 @@ def test_list_examples_rest_bad_request(request_type=example.ListExamplesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5055,17 +5064,19 @@ def test_list_examples_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_list_examples" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_list_examples_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_list_examples" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_list_examples" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_list_examples_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_list_examples" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5118,8 +5129,9 @@ def test_get_example_rest_bad_request(request_type=example.GetExampleRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5192,17 +5204,17 @@ def test_get_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_get_example" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_get_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_get_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_get_example" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_get_example_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ExamplesRestInterceptor, "pre_get_example") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5257,8 +5269,9 @@ def test_update_example_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5571,17 +5584,19 @@ def test_update_example_rest_interceptors(null_interceptor): ) client = ExamplesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExamplesRestInterceptor, "post_update_example" - ) as post, mock.patch.object( - transports.ExamplesRestInterceptor, "post_update_example_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExamplesRestInterceptor, "pre_update_example" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_update_example" + ) as post, + mock.patch.object( + transports.ExamplesRestInterceptor, "post_update_example_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExamplesRestInterceptor, "pre_update_example" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5634,8 +5649,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5694,8 +5710,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5756,8 +5773,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5818,8 +5836,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5878,8 +5897,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6096,11 +6116,14 @@ def test_examples_base_transport(): def test_examples_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.examples.transports.ExamplesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.examples.transports.ExamplesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExamplesTransport( @@ -6120,9 +6143,12 @@ def test_examples_base_transport_with_credentials_file(): def test_examples_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.examples.transports.ExamplesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.examples.transports.ExamplesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExamplesTransport() @@ -6200,11 +6226,12 @@ def test_examples_transport_auth_gdch_credentials(transport_class): def test_examples_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6868,6 +6895,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7013,6 +7072,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7158,6 +7251,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7303,6 +7430,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7444,6 +7605,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ExamplesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ExamplesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ExamplesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_experiments.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_experiments.py index fe94dae73ea9..b5e006cc262a 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_experiments.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_experiments.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ExperimentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ExperimentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ExperimentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1249,11 +1253,13 @@ def test_experiments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5745,8 +5751,9 @@ def test_list_experiments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5811,17 +5818,19 @@ def test_list_experiments_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_list_experiments" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_list_experiments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_list_experiments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_list_experiments" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_list_experiments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_list_experiments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5876,8 +5885,9 @@ def test_get_experiment_rest_bad_request(request_type=experiment.GetExperimentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5950,17 +5960,19 @@ def test_get_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_get_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_get_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_get_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_get_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_get_experiment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_get_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6015,8 +6027,9 @@ def test_create_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6220,17 +6233,20 @@ def test_create_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_create_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_create_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_create_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_create_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, + "post_create_experiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_create_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6287,8 +6303,9 @@ def test_update_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6494,17 +6511,20 @@ def test_update_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_update_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_update_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_update_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_update_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, + "post_update_experiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_update_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6559,8 +6579,9 @@ def test_delete_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6619,13 +6640,13 @@ def test_delete_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_delete_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_delete_experiment" + ) as pre, + ): pre.assert_not_called() pb_message = experiment.DeleteExperimentRequest.pb( experiment.DeleteExperimentRequest() @@ -6672,8 +6693,9 @@ def test_start_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6746,17 +6768,19 @@ def test_start_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_start_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_start_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_start_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_start_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_start_experiment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_start_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6811,8 +6835,9 @@ def test_stop_experiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6885,17 +6910,19 @@ def test_stop_experiment_rest_interceptors(null_interceptor): ) client = ExperimentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_stop_experiment" - ) as post, mock.patch.object( - transports.ExperimentsRestInterceptor, "post_stop_experiment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ExperimentsRestInterceptor, "pre_stop_experiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_stop_experiment" + ) as post, + mock.patch.object( + transports.ExperimentsRestInterceptor, "post_stop_experiment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ExperimentsRestInterceptor, "pre_stop_experiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6948,8 +6975,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7008,8 +7036,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7070,8 +7099,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7132,8 +7162,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7192,8 +7223,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7458,11 +7490,14 @@ def test_experiments_base_transport(): def test_experiments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExperimentsTransport( @@ -7482,9 +7517,12 @@ def test_experiments_base_transport_with_credentials_file(): def test_experiments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.experiments.transports.ExperimentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ExperimentsTransport() @@ -7562,11 +7600,12 @@ def test_experiments_transport_auth_gdch_credentials(transport_class): def test_experiments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8179,6 +8218,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8324,6 +8395,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8469,6 +8574,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8614,6 +8753,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8755,6 +8928,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ExperimentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ExperimentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ExperimentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py index 54195beee17e..306a609ba175 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_flows.py @@ -143,6 +143,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FlowsClient._get_default_mtls_endpoint(None) is None assert FlowsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -158,6 +159,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FlowsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert FlowsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1232,11 +1234,13 @@ def test_flows_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6861,8 +6865,9 @@ def test_create_flow_rest_bad_request(request_type=gcdc_flow.CreateFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7168,17 +7173,15 @@ def test_create_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_create_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_create_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_create_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_create_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_create_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_create_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7229,8 +7232,9 @@ def test_delete_flow_rest_bad_request(request_type=flow.DeleteFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7287,13 +7291,11 @@ def test_delete_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "pre_delete_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "pre_delete_flow") as pre, + ): pre.assert_not_called() pb_message = flow.DeleteFlowRequest.pb(flow.DeleteFlowRequest()) transcode.return_value = { @@ -7334,8 +7336,9 @@ def test_list_flows_rest_bad_request(request_type=flow.ListFlowsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7396,17 +7399,15 @@ def test_list_flows_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_list_flows" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_list_flows_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_list_flows" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_list_flows") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_list_flows_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_list_flows") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7457,8 +7458,9 @@ def test_get_flow_rest_bad_request(request_type=flow.GetFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7529,17 +7531,15 @@ def test_get_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_get_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_get_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_get_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_get_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7592,8 +7592,9 @@ def test_update_flow_rest_bad_request(request_type=gcdc_flow.UpdateFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7903,17 +7904,15 @@ def test_update_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_update_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_update_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_update_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FlowsRestInterceptor, "post_update_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_update_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_update_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7964,8 +7963,9 @@ def test_train_flow_rest_bad_request(request_type=flow.TrainFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8022,19 +8022,16 @@ def test_train_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FlowsRestInterceptor, "post_train_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_train_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_train_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.FlowsRestInterceptor, "post_train_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_train_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_train_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8085,8 +8082,9 @@ def test_validate_flow_rest_bad_request(request_type=flow.ValidateFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8149,17 +8147,17 @@ def test_validate_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_validate_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_validate_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_validate_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FlowsRestInterceptor, "post_validate_flow" + ) as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_validate_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_validate_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8212,8 +8210,9 @@ def test_get_flow_validation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8276,17 +8275,20 @@ def test_get_flow_validation_result_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow_validation_result" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_get_flow_validation_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_get_flow_validation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FlowsRestInterceptor, "post_get_flow_validation_result" + ) as post, + mock.patch.object( + transports.FlowsRestInterceptor, + "post_get_flow_validation_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FlowsRestInterceptor, "pre_get_flow_validation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8337,8 +8339,9 @@ def test_import_flow_rest_bad_request(request_type=flow.ImportFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8393,19 +8396,16 @@ def test_import_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FlowsRestInterceptor, "post_import_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_import_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_import_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.FlowsRestInterceptor, "post_import_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_import_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_import_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8456,8 +8456,9 @@ def test_export_flow_rest_bad_request(request_type=flow.ExportFlowRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8514,19 +8515,16 @@ def test_export_flow_rest_interceptors(null_interceptor): ) client = FlowsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FlowsRestInterceptor, "post_export_flow" - ) as post, mock.patch.object( - transports.FlowsRestInterceptor, "post_export_flow_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FlowsRestInterceptor, "pre_export_flow" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.FlowsRestInterceptor, "post_export_flow") as post, + mock.patch.object( + transports.FlowsRestInterceptor, "post_export_flow_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FlowsRestInterceptor, "pre_export_flow") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8577,8 +8575,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8637,8 +8636,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8699,8 +8699,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8761,8 +8762,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8821,8 +8823,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9168,11 +9171,14 @@ def test_flows_base_transport(): def test_flows_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.flows.transports.FlowsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.flows.transports.FlowsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FlowsTransport( @@ -9192,9 +9198,12 @@ def test_flows_base_transport_with_credentials_file(): def test_flows_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.flows.transports.FlowsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.flows.transports.FlowsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FlowsTransport() @@ -9272,11 +9281,12 @@ def test_flows_transport_auth_gdch_credentials(transport_class): def test_flows_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10135,6 +10145,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10280,6 +10322,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10425,6 +10501,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10570,6 +10680,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10711,6 +10855,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = FlowsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = FlowsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = FlowsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py index 438459813652..7867588719e9 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_generators.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeneratorsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GeneratorsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + GeneratorsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1243,11 +1247,13 @@ def test_generators_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4491,8 +4497,9 @@ def test_list_generators_rest_bad_request(request_type=generator.ListGeneratorsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4555,17 +4562,19 @@ def test_list_generators_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_list_generators" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_list_generators" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4620,8 +4629,9 @@ def test_get_generator_rest_bad_request(request_type=generator.GetGeneratorReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4688,17 +4698,19 @@ def test_get_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_get_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_get_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4749,8 +4761,9 @@ def test_create_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4903,17 +4916,19 @@ def test_create_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_create_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_create_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4970,8 +4985,9 @@ def test_update_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5128,17 +5144,19 @@ def test_update_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_update_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_update_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5193,8 +5211,9 @@ def test_delete_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5253,13 +5272,13 @@ def test_delete_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_delete_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_delete_generator" + ) as pre, + ): pre.assert_not_called() pb_message = generator.DeleteGeneratorRequest.pb( generator.DeleteGeneratorRequest() @@ -5304,8 +5323,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5364,8 +5384,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5426,8 +5447,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5488,8 +5510,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5548,8 +5571,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5766,11 +5790,14 @@ def test_generators_base_transport(): def test_generators_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport( @@ -5790,9 +5817,12 @@ def test_generators_base_transport_with_credentials_file(): def test_generators_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport() @@ -5870,11 +5900,12 @@ def test_generators_transport_auth_gdch_credentials(transport_class): def test_generators_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6444,6 +6475,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6589,6 +6652,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6734,6 +6831,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6879,6 +7010,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7020,6 +7185,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_intents.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_intents.py index 193b1bd2ed35..99c903d39bb1 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_intents.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_intents.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IntentsClient._get_default_mtls_endpoint(None) is None assert IntentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -142,6 +143,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert IntentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IntentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1221,11 +1223,13 @@ def test_intents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5326,8 +5330,9 @@ def test_list_intents_rest_bad_request(request_type=intent.ListIntentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5388,17 +5393,17 @@ def test_list_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_list_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_list_intents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5449,8 +5454,9 @@ def test_get_intent_rest_bad_request(request_type=intent.GetIntentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5521,17 +5527,15 @@ def test_get_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_get_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.IntentsRestInterceptor, "post_get_intent") as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_get_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_get_intent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5580,8 +5584,9 @@ def test_create_intent_rest_bad_request(request_type=gcdc_intent.CreateIntentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5740,17 +5745,19 @@ def test_create_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_create_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_create_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5805,8 +5812,9 @@ def test_update_intent_rest_bad_request(request_type=gcdc_intent.UpdateIntentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5969,17 +5977,19 @@ def test_update_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_update_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_update_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6032,8 +6042,9 @@ def test_delete_intent_rest_bad_request(request_type=intent.DeleteIntentRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6090,13 +6101,13 @@ def test_delete_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "pre_delete_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_delete_intent" + ) as pre, + ): pre.assert_not_called() pb_message = intent.DeleteIntentRequest.pb(intent.DeleteIntentRequest()) transcode.return_value = { @@ -6137,8 +6148,9 @@ def test_import_intents_rest_bad_request(request_type=intent.ImportIntentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6193,19 +6205,20 @@ def test_import_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_import_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_import_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_import_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_import_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_import_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_import_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6254,8 +6267,9 @@ def test_export_intents_rest_bad_request(request_type=intent.ExportIntentsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6310,19 +6324,20 @@ def test_export_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_export_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_export_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_export_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_export_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_export_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_export_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6373,8 +6388,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6433,8 +6449,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6495,8 +6512,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6557,8 +6575,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6617,8 +6636,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6899,11 +6919,14 @@ def test_intents_base_transport(): def test_intents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport( @@ -6923,9 +6946,12 @@ def test_intents_base_transport_with_credentials_file(): def test_intents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport() @@ -7003,11 +7029,12 @@ def test_intents_transport_auth_gdch_credentials(transport_class): def test_intents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7646,6 +7673,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7791,6 +7850,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7936,6 +8029,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8081,6 +8208,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8222,6 +8383,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py index 9c9fdef7258c..d0a55949d920 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PagesClient._get_default_mtls_endpoint(None) is None assert PagesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -148,6 +149,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PagesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert PagesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1222,11 +1224,13 @@ def test_pages_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4476,8 +4480,9 @@ def test_list_pages_rest_bad_request(request_type=page.ListPagesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4540,17 +4545,15 @@ def test_list_pages_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_list_pages" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_list_pages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_list_pages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_list_pages") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_list_pages_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_list_pages") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4601,8 +4604,9 @@ def test_get_page_rest_bad_request(request_type=page.GetPageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4671,17 +4675,15 @@ def test_get_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_get_page" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_get_page_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_get_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_get_page") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_get_page_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_get_page") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4732,8 +4734,9 @@ def test_create_page_rest_bad_request(request_type=gcdc_page.CreatePageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5025,17 +5028,15 @@ def test_create_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_create_page" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_create_page_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_create_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_create_page") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_create_page_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_create_page") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5088,8 +5089,9 @@ def test_update_page_rest_bad_request(request_type=gcdc_page.UpdatePageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5383,17 +5385,15 @@ def test_update_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "post_update_page" - ) as post, mock.patch.object( - transports.PagesRestInterceptor, "post_update_page_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PagesRestInterceptor, "pre_update_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "post_update_page") as post, + mock.patch.object( + transports.PagesRestInterceptor, "post_update_page_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PagesRestInterceptor, "pre_update_page") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5444,8 +5444,9 @@ def test_delete_page_rest_bad_request(request_type=page.DeletePageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5502,13 +5503,11 @@ def test_delete_page_rest_interceptors(null_interceptor): ) client = PagesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PagesRestInterceptor, "pre_delete_page" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PagesRestInterceptor, "pre_delete_page") as pre, + ): pre.assert_not_called() pb_message = page.DeletePageRequest.pb(page.DeletePageRequest()) transcode.return_value = { @@ -5551,8 +5550,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5611,8 +5611,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5673,8 +5674,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5735,8 +5737,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5795,8 +5798,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6013,11 +6017,14 @@ def test_pages_base_transport(): def test_pages_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.pages.transports.PagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.pages.transports.PagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PagesTransport( @@ -6037,9 +6044,12 @@ def test_pages_base_transport_with_credentials_file(): def test_pages_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.pages.transports.PagesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.pages.transports.PagesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PagesTransport() @@ -6117,11 +6127,12 @@ def test_pages_transport_auth_gdch_credentials(transport_class): def test_pages_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6931,6 +6942,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7076,6 +7119,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7221,6 +7298,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7366,6 +7477,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7507,6 +7652,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = PagesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = PagesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = PagesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py index 6cdf7d9533e4..ed5b99587a7c 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_playbooks.py @@ -144,6 +144,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PlaybooksClient._get_default_mtls_endpoint(None) is None assert PlaybooksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -160,6 +161,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PlaybooksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + PlaybooksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1260,11 +1264,13 @@ def test_playbooks_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8582,8 +8588,9 @@ def test_create_playbook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8885,17 +8892,19 @@ def test_create_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_create_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_create_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_create_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_create_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_create_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_create_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8948,8 +8957,9 @@ def test_delete_playbook_rest_bad_request(request_type=playbook.DeletePlaybookRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9006,13 +9016,13 @@ def test_delete_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_delete_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_delete_playbook" + ) as pre, + ): pre.assert_not_called() pb_message = playbook.DeletePlaybookRequest.pb(playbook.DeletePlaybookRequest()) transcode.return_value = { @@ -9053,8 +9063,9 @@ def test_list_playbooks_rest_bad_request(request_type=playbook.ListPlaybooksRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9115,17 +9126,19 @@ def test_list_playbooks_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbooks" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbooks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_list_playbooks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_list_playbooks" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_list_playbooks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_list_playbooks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9178,8 +9191,9 @@ def test_get_playbook_rest_bad_request(request_type=playbook.GetPlaybookRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9258,17 +9272,19 @@ def test_get_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_get_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_get_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_get_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_get_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9319,8 +9335,9 @@ def test_export_playbook_rest_bad_request(request_type=playbook.ExportPlaybookRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9377,19 +9394,20 @@ def test_export_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PlaybooksRestInterceptor, "post_export_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_export_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_export_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_export_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_export_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_export_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9438,8 +9456,9 @@ def test_import_playbook_rest_bad_request(request_type=playbook.ImportPlaybookRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9494,19 +9513,20 @@ def test_import_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PlaybooksRestInterceptor, "post_import_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_import_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_import_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_import_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_import_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_import_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9561,8 +9581,9 @@ def test_update_playbook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9868,17 +9889,19 @@ def test_update_playbook_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_update_playbook" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_update_playbook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_update_playbook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_update_playbook" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_update_playbook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_update_playbook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9933,8 +9956,9 @@ def test_create_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10400,18 +10424,20 @@ def test_create_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_create_playbook_version" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, - "post_create_playbook_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_create_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_create_playbook_version" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_create_playbook_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_create_playbook_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10466,8 +10492,9 @@ def test_get_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10532,17 +10559,20 @@ def test_get_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook_version" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_get_playbook_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_get_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_get_playbook_version" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_get_playbook_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_get_playbook_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10597,8 +10627,9 @@ def test_restore_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10658,18 +10689,20 @@ def test_restore_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_restore_playbook_version" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, - "post_restore_playbook_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_restore_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_restore_playbook_version" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_restore_playbook_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_restore_playbook_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10729,8 +10762,9 @@ def test_list_playbook_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10793,17 +10827,20 @@ def test_list_playbook_versions_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbook_versions" - ) as post, mock.patch.object( - transports.PlaybooksRestInterceptor, "post_list_playbook_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_list_playbook_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "post_list_playbook_versions" + ) as post, + mock.patch.object( + transports.PlaybooksRestInterceptor, + "post_list_playbook_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_list_playbook_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10863,8 +10900,9 @@ def test_delete_playbook_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10921,13 +10959,13 @@ def test_delete_playbook_version_rest_interceptors(null_interceptor): ) client = PlaybooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PlaybooksRestInterceptor, "pre_delete_playbook_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PlaybooksRestInterceptor, "pre_delete_playbook_version" + ) as pre, + ): pre.assert_not_called() pb_message = playbook.DeletePlaybookVersionRequest.pb( playbook.DeletePlaybookVersionRequest() @@ -10972,8 +11010,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11032,8 +11071,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11094,8 +11134,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11156,8 +11197,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11216,8 +11258,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11613,11 +11656,14 @@ def test_playbooks_base_transport(): def test_playbooks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PlaybooksTransport( @@ -11637,9 +11683,12 @@ def test_playbooks_base_transport_with_credentials_file(): def test_playbooks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.playbooks.transports.PlaybooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PlaybooksTransport() @@ -11717,11 +11766,12 @@ def test_playbooks_transport_auth_gdch_credentials(transport_class): def test_playbooks_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12532,6 +12582,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12677,6 +12759,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12822,6 +12938,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12967,6 +13117,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13108,6 +13292,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = PlaybooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = PlaybooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = PlaybooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_security_settings_service.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_security_settings_service.py index ad349ca636b4..3c33ad36ddae 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_security_settings_service.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_security_settings_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SecuritySettingsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): SecuritySettingsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SecuritySettingsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_security_settings_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4898,8 +4905,9 @@ def test_create_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5073,20 +5081,22 @@ def test_create_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_create_security_settings", - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_create_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "pre_create_security_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_create_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_create_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_create_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5146,8 +5156,9 @@ def test_get_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5235,18 +5246,22 @@ def test_get_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "post_get_security_settings" - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_get_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "pre_get_security_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_get_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_get_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_get_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5305,8 +5320,9 @@ def test_update_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5484,20 +5500,22 @@ def test_update_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_update_security_settings", - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_update_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "pre_update_security_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_update_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_update_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_update_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5555,8 +5573,9 @@ def test_list_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5619,18 +5638,22 @@ def test_list_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "post_list_security_settings" - ) as post, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "post_list_security_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, "pre_list_security_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_list_security_settings", + ) as post, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "post_list_security_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_list_security_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5690,8 +5713,9 @@ def test_delete_security_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5750,14 +5774,14 @@ def test_delete_security_settings_rest_interceptors(null_interceptor): ) client = SecuritySettingsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SecuritySettingsServiceRestInterceptor, - "pre_delete_security_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SecuritySettingsServiceRestInterceptor, + "pre_delete_security_settings", + ) as pre, + ): pre.assert_not_called() pb_message = security_settings.DeleteSecuritySettingsRequest.pb( security_settings.DeleteSecuritySettingsRequest() @@ -5802,8 +5826,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5862,8 +5887,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5924,8 +5950,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5986,8 +6013,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6046,8 +6074,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6274,11 +6303,14 @@ def test_security_settings_service_base_transport(): def test_security_settings_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecuritySettingsServiceTransport( @@ -6298,9 +6330,12 @@ def test_security_settings_service_base_transport_with_credentials_file(): def test_security_settings_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.security_settings_service.transports.SecuritySettingsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SecuritySettingsServiceTransport() @@ -6380,11 +6415,12 @@ def test_security_settings_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7022,6 +7058,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7167,6 +7235,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7312,6 +7414,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7457,6 +7593,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7602,6 +7772,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SecuritySettingsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SecuritySettingsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SecuritySettingsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_session_entity_types.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_session_entity_types.py index 70ff0b6b568d..2e34148db5c4 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_session_entity_types.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_session_entity_types.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionEntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): SessionEntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionEntityTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1328,11 +1333,13 @@ def test_session_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4759,8 +4766,9 @@ def test_list_session_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4827,18 +4835,22 @@ def test_list_session_entity_types_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_list_session_entity_types" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_list_session_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_list_session_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_list_session_entity_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4898,8 +4910,9 @@ def test_get_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4969,18 +4982,20 @@ def test_get_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_get_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_get_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5040,8 +5055,9 @@ def test_create_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5187,18 +5203,22 @@ def test_create_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_create_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_create_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_create_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_create_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5260,8 +5280,9 @@ def test_update_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5409,18 +5430,22 @@ def test_update_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_update_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_update_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_update_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_update_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5480,8 +5505,9 @@ def test_delete_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5540,13 +5566,14 @@ def test_delete_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_delete_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_delete_session_entity_type", + ) as pre, + ): pre.assert_not_called() pb_message = session_entity_type.DeleteSessionEntityTypeRequest.pb( session_entity_type.DeleteSessionEntityTypeRequest() @@ -5591,8 +5618,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5651,8 +5679,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5713,8 +5742,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5775,8 +5805,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5835,8 +5866,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6063,11 +6095,14 @@ def test_session_entity_types_base_transport(): def test_session_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport( @@ -6087,9 +6122,12 @@ def test_session_entity_types_base_transport_with_credentials_file(): def test_session_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport() @@ -6167,11 +6205,12 @@ def test_session_entity_types_transport_auth_gdch_credentials(transport_class): def test_session_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6759,6 +6798,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6904,6 +6975,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7049,6 +7154,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7194,6 +7333,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7335,6 +7508,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py index aa966624c5da..09111cba55f5 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_sessions.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionsClient._get_default_mtls_endpoint(None) is None assert SessionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -149,6 +150,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SessionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert SessionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1238,11 +1240,13 @@ def test_sessions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3652,8 +3656,9 @@ def test_detect_intent_rest_bad_request(request_type=session.DetectIntentRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3722,17 +3727,19 @@ def test_detect_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_detect_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_detect_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3787,8 +3794,9 @@ def test_server_streaming_detect_intent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3861,18 +3869,20 @@ def test_server_streaming_detect_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_server_streaming_detect_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, - "post_server_streaming_detect_intent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_server_streaming_detect_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_server_streaming_detect_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, + "post_server_streaming_detect_intent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_server_streaming_detect_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3937,8 +3947,9 @@ def test_match_intent_rest_bad_request(request_type=session.MatchIntentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4000,17 +4011,19 @@ def test_match_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_match_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_match_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_match_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_match_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_match_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_match_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4065,8 +4078,9 @@ def test_fulfill_intent_rest_bad_request(request_type=session.FulfillIntentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4133,17 +4147,19 @@ def test_fulfill_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_fulfill_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_fulfill_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_fulfill_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_fulfill_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_fulfill_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_fulfill_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4198,8 +4214,9 @@ def test_submit_answer_feedback_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4264,17 +4281,20 @@ def test_submit_answer_feedback_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_submit_answer_feedback" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_submit_answer_feedback_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_submit_answer_feedback" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_submit_answer_feedback" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, + "post_submit_answer_feedback_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_submit_answer_feedback" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4327,8 +4347,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4387,8 +4408,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4449,8 +4471,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4511,8 +4534,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4571,8 +4595,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4794,11 +4819,14 @@ def test_sessions_base_transport(): def test_sessions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport( @@ -4818,9 +4846,12 @@ def test_sessions_base_transport_with_credentials_file(): def test_sessions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport() @@ -4898,11 +4929,12 @@ def test_sessions_transport_auth_gdch_credentials(transport_class): def test_sessions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5872,6 +5904,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6017,6 +6081,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6162,6 +6260,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6307,6 +6439,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6448,6 +6614,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py index 8ef49c39b64c..345bd8d1b35d 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_test_cases.py @@ -144,6 +144,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TestCasesClient._get_default_mtls_endpoint(None) is None assert TestCasesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -160,6 +161,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert TestCasesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + TestCasesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1262,11 +1266,13 @@ def test_test_cases_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8179,8 +8185,9 @@ def test_list_test_cases_rest_bad_request(request_type=test_case.ListTestCasesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8241,17 +8248,19 @@ def test_list_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_list_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_list_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_list_test_cases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_list_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8304,8 +8313,9 @@ def test_batch_delete_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8360,13 +8370,13 @@ def test_batch_delete_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_batch_delete_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_batch_delete_test_cases" + ) as pre, + ): pre.assert_not_called() pb_message = test_case.BatchDeleteTestCasesRequest.pb( test_case.BatchDeleteTestCasesRequest() @@ -8411,8 +8421,9 @@ def test_get_test_case_rest_bad_request(request_type=test_case.GetTestCaseReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8481,17 +8492,19 @@ def test_get_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_get_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_get_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_get_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_get_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8542,8 +8555,9 @@ def test_create_test_case_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8951,17 +8965,19 @@ def test_create_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_create_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_create_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_create_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_create_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_create_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_create_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9018,8 +9034,9 @@ def test_update_test_case_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9431,17 +9448,19 @@ def test_update_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_update_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_update_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_update_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_update_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_update_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_update_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9494,8 +9513,9 @@ def test_run_test_case_rest_bad_request(request_type=test_case.RunTestCaseReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9552,19 +9572,20 @@ def test_run_test_case_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_run_test_case" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_run_test_case_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_run_test_case" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_run_test_case" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_run_test_case_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_run_test_case" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9615,8 +9636,9 @@ def test_batch_run_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9671,19 +9693,21 @@ def test_batch_run_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_batch_run_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_batch_run_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_batch_run_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_batch_run_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, + "post_batch_run_test_cases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_batch_run_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9736,8 +9760,9 @@ def test_calculate_coverage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9798,17 +9823,19 @@ def test_calculate_coverage_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_calculate_coverage" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_calculate_coverage_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_calculate_coverage" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_calculate_coverage" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_calculate_coverage_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_calculate_coverage" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9866,8 +9893,9 @@ def test_import_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9922,19 +9950,20 @@ def test_import_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_import_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_import_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_import_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_import_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_import_test_cases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_import_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9987,8 +10016,9 @@ def test_export_test_cases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10043,19 +10073,20 @@ def test_export_test_cases_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.TestCasesRestInterceptor, "post_export_test_cases" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_export_test_cases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_export_test_cases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.TestCasesRestInterceptor, "post_export_test_cases" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_export_test_cases_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_export_test_cases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10110,8 +10141,9 @@ def test_list_test_case_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10174,17 +10206,20 @@ def test_list_test_case_results_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_case_results" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_list_test_case_results_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_list_test_case_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_list_test_case_results" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, + "post_list_test_case_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_list_test_case_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10244,8 +10279,9 @@ def test_get_test_case_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10312,17 +10348,20 @@ def test_get_test_case_result_rest_interceptors(null_interceptor): ) client = TestCasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case_result" - ) as post, mock.patch.object( - transports.TestCasesRestInterceptor, "post_get_test_case_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.TestCasesRestInterceptor, "pre_get_test_case_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TestCasesRestInterceptor, "post_get_test_case_result" + ) as post, + mock.patch.object( + transports.TestCasesRestInterceptor, + "post_get_test_case_result_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TestCasesRestInterceptor, "pre_get_test_case_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10375,8 +10414,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10435,8 +10475,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10497,8 +10538,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10559,8 +10601,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10619,8 +10662,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11020,11 +11064,14 @@ def test_test_cases_base_transport(): def test_test_cases_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TestCasesTransport( @@ -11044,9 +11091,12 @@ def test_test_cases_base_transport_with_credentials_file(): def test_test_cases_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.test_cases.transports.TestCasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TestCasesTransport() @@ -11124,11 +11174,12 @@ def test_test_cases_transport_auth_gdch_credentials(transport_class): def test_test_cases_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12115,6 +12166,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12260,6 +12343,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12405,6 +12522,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12550,6 +12701,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12691,6 +12876,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = TestCasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = TestCasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = TestCasesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py index 2fcf9ae29f46..bf607d048f79 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_tools.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ToolsClient._get_default_mtls_endpoint(None) is None assert ToolsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ToolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ToolsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1218,11 +1220,13 @@ def test_tools_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8000,8 +8004,9 @@ def test_create_tool_rest_bad_request(request_type=gcdc_tool.CreateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8208,17 +8213,15 @@ def test_create_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_create_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_create_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_create_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8267,8 +8270,9 @@ def test_list_tools_rest_bad_request(request_type=tool.ListToolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8329,17 +8333,15 @@ def test_list_tools_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_list_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_list_tools") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_list_tools") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8388,8 +8390,9 @@ def test_export_tools_rest_bad_request(request_type=tool.ExportToolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8444,19 +8447,16 @@ def test_export_tools_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ToolsRestInterceptor, "post_export_tools" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_export_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_export_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.ToolsRestInterceptor, "post_export_tools") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_export_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_export_tools") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8507,8 +8507,9 @@ def test_get_tool_rest_bad_request(request_type=tool.GetToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8577,17 +8578,15 @@ def test_get_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_get_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_get_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_get_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8640,8 +8639,9 @@ def test_update_tool_rest_bad_request(request_type=gcdc_tool.UpdateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8852,17 +8852,15 @@ def test_update_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_update_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_update_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_update_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_update_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8913,8 +8911,9 @@ def test_delete_tool_rest_bad_request(request_type=tool.DeleteToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8971,13 +8970,11 @@ def test_delete_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "pre_delete_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "pre_delete_tool") as pre, + ): pre.assert_not_called() pb_message = tool.DeleteToolRequest.pb(tool.DeleteToolRequest()) transcode.return_value = { @@ -9020,8 +9017,9 @@ def test_list_tool_versions_rest_bad_request(request_type=tool.ListToolVersionsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9084,17 +9082,19 @@ def test_list_tool_versions_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tool_versions" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tool_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_list_tool_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tool_versions" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tool_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_list_tool_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9149,8 +9149,9 @@ def test_create_tool_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9364,17 +9365,19 @@ def test_create_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_version" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_create_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_version" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_create_tool_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9425,8 +9428,9 @@ def test_get_tool_version_rest_bad_request(request_type=tool.GetToolVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9491,17 +9495,19 @@ def test_get_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_version" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_get_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_version" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_get_tool_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9554,8 +9560,9 @@ def test_delete_tool_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9612,13 +9619,13 @@ def test_delete_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "pre_delete_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_delete_tool_version" + ) as pre, + ): pre.assert_not_called() pb_message = tool.DeleteToolVersionRequest.pb(tool.DeleteToolVersionRequest()) transcode.return_value = { @@ -9663,8 +9670,9 @@ def test_restore_tool_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9724,17 +9732,19 @@ def test_restore_tool_version_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_restore_tool_version" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_restore_tool_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_restore_tool_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ToolsRestInterceptor, "post_restore_tool_version" + ) as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_restore_tool_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ToolsRestInterceptor, "pre_restore_tool_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9787,8 +9797,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9847,8 +9858,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9909,8 +9921,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9971,8 +9984,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10031,8 +10045,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10405,11 +10420,14 @@ def test_tools_base_transport(): def test_tools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport( @@ -10429,9 +10447,12 @@ def test_tools_base_transport_with_credentials_file(): def test_tools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport() @@ -10509,11 +10530,12 @@ def test_tools_transport_auth_gdch_credentials(transport_class): def test_tools_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11220,6 +11242,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11365,6 +11419,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11510,6 +11598,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11655,6 +11777,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11796,6 +11952,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py index 32ed83252ee0..4b2ab124a989 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_transition_route_groups.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert TransitionRouteGroupsClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): TransitionRouteGroupsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + TransitionRouteGroupsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1358,11 +1363,13 @@ def test_transition_route_groups_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4813,8 +4820,9 @@ def test_list_transition_route_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4881,20 +4889,22 @@ def test_list_transition_route_groups_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_list_transition_route_groups", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_list_transition_route_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_list_transition_route_groups", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_list_transition_route_groups", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_list_transition_route_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_list_transition_route_groups", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4954,8 +4964,9 @@ def test_get_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5022,20 +5033,22 @@ def test_get_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_get_transition_route_group", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_get_transition_route_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_get_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_get_transition_route_group", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_get_transition_route_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_get_transition_route_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5095,8 +5108,9 @@ def test_create_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5349,20 +5363,22 @@ def test_create_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_create_transition_route_group", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_create_transition_route_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_create_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_create_transition_route_group", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_create_transition_route_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_create_transition_route_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5424,8 +5440,9 @@ def test_update_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5680,20 +5697,22 @@ def test_update_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_update_transition_route_group", - ) as post, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "post_update_transition_route_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_update_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_update_transition_route_group", + ) as post, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "post_update_transition_route_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_update_transition_route_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5753,8 +5772,9 @@ def test_delete_transition_route_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5813,14 +5833,14 @@ def test_delete_transition_route_group_rest_interceptors(null_interceptor): ) client = TransitionRouteGroupsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.TransitionRouteGroupsRestInterceptor, - "pre_delete_transition_route_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.TransitionRouteGroupsRestInterceptor, + "pre_delete_transition_route_group", + ) as pre, + ): pre.assert_not_called() pb_message = transition_route_group.DeleteTransitionRouteGroupRequest.pb( transition_route_group.DeleteTransitionRouteGroupRequest() @@ -5865,8 +5885,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5925,8 +5946,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5987,8 +6009,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6049,8 +6072,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6109,8 +6133,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6337,11 +6362,14 @@ def test_transition_route_groups_base_transport(): def test_transition_route_groups_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TransitionRouteGroupsTransport( @@ -6361,9 +6389,12 @@ def test_transition_route_groups_base_transport_with_credentials_file(): def test_transition_route_groups_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.transition_route_groups.transports.TransitionRouteGroupsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.TransitionRouteGroupsTransport() @@ -6443,11 +6474,12 @@ def test_transition_route_groups_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7218,6 +7250,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7363,6 +7427,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7508,6 +7606,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7653,6 +7785,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7796,6 +7962,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = TransitionRouteGroupsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = TransitionRouteGroupsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = TransitionRouteGroupsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_versions.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_versions.py index da1b4a9552ba..c51683c34373 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_versions.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_versions.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VersionsClient._get_default_mtls_endpoint(None) is None assert VersionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -146,6 +147,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert VersionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1235,11 +1237,13 @@ def test_versions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5596,8 +5600,9 @@ def test_list_versions_rest_bad_request(request_type=version.ListVersionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5660,17 +5665,19 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5723,8 +5730,9 @@ def test_get_version_rest_bad_request(request_type=version.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5793,17 +5801,17 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VersionsRestInterceptor, "pre_get_version") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5856,8 +5864,9 @@ def test_create_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5993,19 +6002,20 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6062,8 +6072,9 @@ def test_update_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6213,17 +6224,19 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6276,8 +6289,9 @@ def test_delete_version_rest_bad_request(request_type=version.DeleteVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6334,13 +6348,13 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() pb_message = version.DeleteVersionRequest.pb(version.DeleteVersionRequest()) transcode.return_value = { @@ -6383,8 +6397,9 @@ def test_load_version_rest_bad_request(request_type=version.LoadVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6441,19 +6456,20 @@ def test_load_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.VersionsRestInterceptor, "post_load_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_load_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_load_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.VersionsRestInterceptor, "post_load_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_load_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_load_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6504,8 +6520,9 @@ def test_compare_versions_rest_bad_request(request_type=version.CompareVersionsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6570,17 +6587,19 @@ def test_compare_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_compare_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_compare_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_compare_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_compare_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_compare_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_compare_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6633,8 +6652,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6693,8 +6713,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6755,8 +6776,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6817,8 +6839,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6877,8 +6900,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7159,11 +7183,14 @@ def test_versions_base_transport(): def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport( @@ -7183,9 +7210,12 @@ def test_versions_base_transport_with_credentials_file(): def test_versions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport() @@ -7263,11 +7293,12 @@ def test_versions_transport_auth_gdch_credentials(transport_class): def test_versions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7880,6 +7911,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8025,6 +8088,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8170,6 +8267,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8315,6 +8446,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8456,6 +8621,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py index 6fc797333c95..e0d202819344 100644 --- a/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py +++ b/packages/google-cloud-dialogflow-cx/tests/unit/gapic/dialogflowcx_v3beta1/test_webhooks.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WebhooksClient._get_default_mtls_endpoint(None) is None assert WebhooksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert WebhooksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert WebhooksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_webhooks_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4447,8 +4451,9 @@ def test_list_webhooks_rest_bad_request(request_type=webhook.ListWebhooksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4509,17 +4514,19 @@ def test_list_webhooks_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_list_webhooks" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_list_webhooks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_list_webhooks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_list_webhooks" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_list_webhooks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_list_webhooks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4572,8 +4579,9 @@ def test_get_webhook_rest_bad_request(request_type=webhook.GetWebhookRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4640,17 +4648,17 @@ def test_get_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_get_webhook" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_get_webhook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_get_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_get_webhook" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_get_webhook_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.WebhooksRestInterceptor, "pre_get_webhook") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4701,8 +4709,9 @@ def test_create_webhook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4863,17 +4872,19 @@ def test_create_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_create_webhook" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_create_webhook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_create_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_create_webhook" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_create_webhook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_create_webhook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4930,8 +4941,9 @@ def test_update_webhook_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5096,17 +5108,19 @@ def test_update_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "post_update_webhook" - ) as post, mock.patch.object( - transports.WebhooksRestInterceptor, "post_update_webhook_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_update_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_update_webhook" + ) as post, + mock.patch.object( + transports.WebhooksRestInterceptor, "post_update_webhook_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_update_webhook" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5159,8 +5173,9 @@ def test_delete_webhook_rest_bad_request(request_type=webhook.DeleteWebhookReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5217,13 +5232,13 @@ def test_delete_webhook_rest_interceptors(null_interceptor): ) client = WebhooksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.WebhooksRestInterceptor, "pre_delete_webhook" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.WebhooksRestInterceptor, "pre_delete_webhook" + ) as pre, + ): pre.assert_not_called() pb_message = webhook.DeleteWebhookRequest.pb(webhook.DeleteWebhookRequest()) transcode.return_value = { @@ -5266,8 +5281,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5326,8 +5342,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5388,8 +5405,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5450,8 +5468,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5510,8 +5529,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5728,11 +5748,14 @@ def test_webhooks_base_transport(): def test_webhooks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebhooksTransport( @@ -5752,9 +5775,12 @@ def test_webhooks_base_transport_with_credentials_file(): def test_webhooks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflowcx_v3beta1.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflowcx_v3beta1.services.webhooks.transports.WebhooksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WebhooksTransport() @@ -5832,11 +5858,12 @@ def test_webhooks_transport_auth_gdch_credentials(transport_class): def test_webhooks_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6461,6 +6488,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6606,6 +6665,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6751,6 +6844,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6896,6 +7023,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7037,6 +7198,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = WebhooksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = WebhooksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = WebhooksClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py index a0498576d991..dfa121c06529 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> AgentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1417,7 +1417,7 @@ async def sample_get_validation_result(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1443,8 +1443,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1453,7 +1457,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1461,7 +1465,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1472,7 +1476,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1498,8 +1502,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1508,7 +1516,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1516,7 +1524,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1527,7 +1535,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1556,8 +1564,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1566,7 +1578,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1574,7 +1586,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1582,7 +1594,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1608,8 +1620,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1618,7 +1634,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1626,7 +1642,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1637,7 +1653,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1663,8 +1679,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1673,7 +1693,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1681,7 +1701,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py index 09af80ec0b1f..ac5914e8e6ce 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py @@ -117,7 +117,7 @@ class AgentsClient(metaclass=AgentsClientMeta): """Service for managing [Agents][google.cloud.dialogflow.v2.Agent].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -435,7 +439,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -532,7 +536,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = AgentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1836,7 +1840,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1862,8 +1866,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1872,7 +1880,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1881,7 +1889,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1895,7 +1903,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1921,8 +1929,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1931,7 +1943,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1940,7 +1952,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1954,7 +1966,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1983,8 +1995,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1993,7 +2009,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2001,7 +2017,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2009,7 +2025,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2035,8 +2051,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2045,7 +2065,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2054,7 +2074,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2068,7 +2088,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2094,8 +2114,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2104,7 +2128,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2113,7 +2137,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/README.rst index 588acebd9fdd..0a289f4e53c3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AgentsTransport` is the ABC for all transports. -- public child `AgentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AgentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAgentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AgentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AgentsTransport`` is the ABC for all transports. + +- public child ``AgentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AgentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAgentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AgentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py index b47f80c5984c..7c6cfdbbd906 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py index 5ab71171eaef..a0ab4eef31e2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py index 15fd33a8e84f..166fa56c684d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py index 59c05990d852..ca4e6cb19c03 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py @@ -718,6 +718,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AgentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py index 582e6e0cc820..3af188307ef1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> AnswerRecordsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -593,7 +593,7 @@ async def sample_update_answer_record(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -619,8 +619,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -629,7 +633,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -637,7 +641,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -648,7 +652,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -674,8 +678,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -684,7 +692,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -692,7 +700,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -703,7 +711,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -732,8 +740,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -742,7 +754,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -750,7 +762,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -758,7 +770,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -784,8 +796,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -794,7 +810,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -802,7 +818,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -813,7 +829,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -839,8 +855,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -849,7 +869,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -857,7 +877,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py index 1a20eff8a817..0c160ceb3b62 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py @@ -116,7 +116,7 @@ class AnswerRecordsClient(metaclass=AnswerRecordsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -499,7 +503,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -596,7 +600,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -692,7 +696,7 @@ def __init__( self._universe_domain = AnswerRecordsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1080,7 +1084,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1106,8 +1110,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1116,7 +1124,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1125,7 +1133,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1139,7 +1147,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1165,8 +1173,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1175,7 +1187,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1184,7 +1196,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1198,7 +1210,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1227,8 +1239,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1237,7 +1253,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1245,7 +1261,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1253,7 +1269,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1279,8 +1295,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1289,7 +1309,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1298,7 +1318,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1312,7 +1332,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1338,8 +1358,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1348,7 +1372,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1357,7 +1381,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/README.rst index f061d90902ce..1f50d03c3e46 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AnswerRecordsTransport` is the ABC for all transports. -- public child `AnswerRecordsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AnswerRecordsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAnswerRecordsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AnswerRecordsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AnswerRecordsTransport`` is the ABC for all transports. + +- public child ``AnswerRecordsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AnswerRecordsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAnswerRecordsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AnswerRecordsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py index 20b5fffa8858..bbbabb277e4f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py index 8dbe9a2e5ba2..a315242f0ad5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py index a9d1338bd1ac..06f5bd4e1fc0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py index 6051e3fd627f..cb75a58db232 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py @@ -387,6 +387,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AnswerRecordsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py index 2716c094004d..2eb59ad24e67 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> ContextsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1053,7 +1053,7 @@ async def sample_delete_all_contexts(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1079,8 +1079,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1089,7 +1093,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1097,7 +1101,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1108,7 +1112,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1138,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1152,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1160,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1163,7 +1171,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1192,8 +1200,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1202,7 +1214,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1210,7 +1222,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1218,7 +1230,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1244,8 +1256,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1254,7 +1270,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1262,7 +1278,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1273,7 +1289,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1299,8 +1315,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1309,7 +1329,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1317,7 +1337,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py index ac524ca677cd..25c61646c583 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py @@ -115,7 +115,7 @@ class ContextsClient(metaclass=ContextsClientMeta): """Service for managing [Contexts][google.cloud.dialogflow.v2.Context].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -440,7 +444,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -537,7 +541,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -633,7 +637,7 @@ def __init__( self._universe_domain = ContextsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1483,7 +1487,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1509,8 +1513,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1519,7 +1527,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1528,7 +1536,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1542,7 +1550,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1568,8 +1576,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1578,7 +1590,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1587,7 +1599,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1601,7 +1613,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1630,8 +1642,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1640,7 +1656,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1648,7 +1664,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1656,7 +1672,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1682,8 +1698,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1692,7 +1712,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1701,7 +1721,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1715,7 +1735,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1741,8 +1761,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1751,7 +1775,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1760,7 +1784,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/README.rst index be49e5b446d8..ae6892ceba4d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContextsTransport` is the ABC for all transports. -- public child `ContextsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContextsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContextsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContextsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContextsTransport`` is the ABC for all transports. + +- public child ``ContextsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContextsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContextsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContextsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py index c3c08a12e813..2b52f137be60 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py index b8ed5b9fa877..e1a5b0d2e7e0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py index 6ce04e62b970..c113bf4d2f6c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py index 34a8ec79d6c8..d12979000b62 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py @@ -520,6 +520,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContextsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py index e72acd99c120..5a316b0aeba4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> ConversationDatasetsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -994,7 +994,7 @@ async def sample_import_conversation_data(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1020,8 +1020,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1030,7 +1034,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1038,7 +1042,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1049,7 +1053,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1075,8 +1079,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1085,7 +1093,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1093,7 +1101,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1112,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1133,8 +1141,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1143,7 +1155,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1151,7 +1163,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1159,7 +1171,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1185,8 +1197,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1195,7 +1211,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1203,7 +1219,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1214,7 +1230,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1240,8 +1256,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1250,7 +1270,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1258,7 +1278,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py index 8d3e2cd87fee..00faa1435fc3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py @@ -123,7 +123,7 @@ class ConversationDatasetsClient(metaclass=ConversationDatasetsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -448,7 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -545,7 +549,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -645,7 +649,7 @@ def __init__( self._universe_domain = ConversationDatasetsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1424,7 +1428,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1450,8 +1454,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1460,7 +1468,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1469,7 +1477,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1483,7 +1491,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1509,8 +1517,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1519,7 +1531,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1528,7 +1540,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1542,7 +1554,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1571,8 +1583,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1581,7 +1597,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1589,7 +1605,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1597,7 +1613,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1623,8 +1639,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1633,7 +1653,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1642,7 +1662,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1656,7 +1676,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1682,8 +1702,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1692,7 +1716,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1701,7 +1725,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/README.rst index f309c7b3ddc5..647895bcf223 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationDatasetsTransport` is the ABC for all transports. -- public child `ConversationDatasetsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationDatasetsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationDatasetsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationDatasetsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationDatasetsTransport`` is the ABC for all transports. + +- public child ``ConversationDatasetsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationDatasetsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationDatasetsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationDatasetsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py index cc17922ae964..6de4855b45dc 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py index 4fcf645f4a65..47d70eec2f0e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py index 8917f03b791a..05b6206728ab 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py index 2c9089900888..9f9ff3dc351c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py @@ -567,6 +567,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationDatasetsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py index bc70ed1e1a21..7d9d48043995 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> ConversationModelsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1506,7 +1506,7 @@ async def sample_create_conversation_model_evaluation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1532,8 +1532,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1542,7 +1546,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1550,7 +1554,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1561,7 +1565,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1587,8 +1591,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1597,7 +1605,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1605,7 +1613,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1616,7 +1624,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1645,8 +1653,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1655,7 +1667,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1663,7 +1675,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1671,7 +1683,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1697,8 +1709,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1707,7 +1723,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1715,7 +1731,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1726,7 +1742,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1752,8 +1768,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1762,7 +1782,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1770,7 +1790,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py index 3578127110d6..566a3ce27538 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py @@ -119,7 +119,7 @@ class ConversationModelsClient(metaclass=ConversationModelsClientMeta): """Manages a collection of models for human agent assistant.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -510,7 +514,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -607,7 +611,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -707,7 +711,7 @@ def __init__( self._universe_domain = ConversationModelsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1985,7 +1989,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2011,8 +2015,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2021,7 +2029,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2030,7 +2038,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2044,7 +2052,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2070,8 +2078,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2080,7 +2092,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2089,7 +2101,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2103,7 +2115,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2132,8 +2144,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2142,7 +2158,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2150,7 +2166,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2158,7 +2174,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2184,8 +2200,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2194,7 +2214,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2203,7 +2223,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2217,7 +2237,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2243,8 +2263,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2253,7 +2277,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2262,7 +2286,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/README.rst index bf17902445af..693e3b5cca94 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationModelsTransport` is the ABC for all transports. -- public child `ConversationModelsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationModelsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationModelsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationModelsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationModelsTransport`` is the ABC for all transports. + +- public child ``ConversationModelsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationModelsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationModelsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationModelsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py index e141ac251b67..835fcf9b77ac 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py index 2fe6539dd0d1..f71efd9e42e7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py index 755c783db2a3..07a2013f4963 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py index 75618dbb4e91..510a97e00ab5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py @@ -797,6 +797,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationModelsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py index 0c4b2a81d3ca..14ac2d326a11 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py @@ -233,7 +233,7 @@ def transport(self) -> ConversationProfilesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1337,7 +1337,7 @@ async def sample_clear_suggestion_feature_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1363,8 +1363,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1377,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1381,7 +1385,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1392,7 +1396,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1418,8 +1422,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1428,7 +1436,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1436,7 +1444,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1447,7 +1455,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1476,8 +1484,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1486,7 +1498,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1494,7 +1506,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1502,7 +1514,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1528,8 +1540,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1538,7 +1554,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1546,7 +1562,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1557,7 +1573,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1583,8 +1599,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1593,7 +1613,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1601,7 +1621,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py index 7b01b1a406ea..aca7e9d59558 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py @@ -125,7 +125,7 @@ class ConversationProfilesClient(metaclass=ConversationProfilesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -592,7 +596,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -689,7 +693,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -789,7 +793,7 @@ def __init__( self._universe_domain = ConversationProfilesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1882,7 +1886,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1908,8 +1912,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1918,7 +1926,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1927,7 +1935,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1941,7 +1949,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1967,8 +1975,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1977,7 +1989,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1986,7 +1998,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2000,7 +2012,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2029,8 +2041,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2039,7 +2055,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2047,7 +2063,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2055,7 +2071,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2081,8 +2097,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2091,7 +2111,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2100,7 +2120,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2114,7 +2134,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2140,8 +2160,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2150,7 +2174,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2159,7 +2183,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/README.rst index 46d5e61b80d3..d95de5267564 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationProfilesTransport` is the ABC for all transports. -- public child `ConversationProfilesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationProfilesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationProfilesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationProfilesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationProfilesTransport`` is the ABC for all transports. + +- public child ``ConversationProfilesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationProfilesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationProfilesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationProfilesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py index 84e74e80431f..476469060e77 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py index ad507e99cb7e..f60e45abd2f4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py index 1239b71a7d7c..cc63a97af2d4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py index 8dad56bb594b..3012e90ac638 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py @@ -648,6 +648,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationProfilesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py index 1167a037765a..177da090a198 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py @@ -230,7 +230,7 @@ def transport(self) -> ConversationsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1651,7 +1651,7 @@ async def sample_generate_suggestions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1677,8 +1677,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1687,7 +1691,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1695,7 +1699,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1706,7 +1710,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1732,8 +1736,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1742,7 +1750,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1750,7 +1758,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1761,7 +1769,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1790,8 +1798,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1800,7 +1812,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1808,7 +1820,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1816,7 +1828,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1842,8 +1854,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1852,7 +1868,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1860,7 +1876,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1871,7 +1887,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1897,8 +1913,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1907,7 +1927,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1915,7 +1935,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py index a101a141d45c..659531046ae9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py @@ -116,7 +116,7 @@ class ConversationsClient(metaclass=ConversationsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -691,7 +695,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -788,7 +792,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -884,7 +888,7 @@ def __init__( self._universe_domain = ConversationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2283,7 +2287,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2309,8 +2313,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2319,7 +2327,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2328,7 +2336,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2342,7 +2350,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2368,8 +2376,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2378,7 +2390,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2387,7 +2399,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2401,7 +2413,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2430,8 +2442,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2440,7 +2456,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2448,7 +2464,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2456,7 +2472,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2482,8 +2498,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2492,7 +2512,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2501,7 +2521,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2515,7 +2535,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2541,8 +2561,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2551,7 +2575,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2560,7 +2584,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/README.rst index a042fbfdf9ec..83e09969a531 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationsTransport` is the ABC for all transports. -- public child `ConversationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationsTransport`` is the ABC for all transports. + +- public child ``ConversationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py index f61df65bf947..d63a52ff08aa 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py index 30018fcf83ac..dc175f3f3cec 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py index 759b9db26c0b..a64a0a50c938 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py index 8a1be4252bf1..35025d4fa9b4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py @@ -915,6 +915,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py index 0e253a0119b7..54e5cde0085c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> DocumentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1403,7 +1403,7 @@ async def sample_export_document(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1429,8 +1429,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1439,7 +1443,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1447,7 +1451,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1458,7 +1462,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1484,8 +1488,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1494,7 +1502,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1502,7 +1510,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1513,7 +1521,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1542,8 +1550,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1552,7 +1564,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1560,7 +1572,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1568,7 +1580,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1594,8 +1606,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1604,7 +1620,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1612,7 +1628,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1623,7 +1639,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1649,8 +1665,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1659,7 +1679,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1667,7 +1687,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py index 13ccd2af1fcd..367d66f835e2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py @@ -119,7 +119,7 @@ class DocumentsClient(metaclass=DocumentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -637,7 +641,7 @@ def __init__( self._universe_domain = DocumentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1827,7 +1831,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1853,8 +1857,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1863,7 +1871,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1872,7 +1880,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1886,7 +1894,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1912,8 +1920,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1922,7 +1934,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1931,7 +1943,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1945,7 +1957,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1974,8 +1986,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1984,7 +2000,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1992,7 +2008,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2000,7 +2016,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2026,8 +2042,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2036,7 +2056,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2045,7 +2065,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2059,7 +2079,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2085,8 +2105,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2095,7 +2119,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2104,7 +2128,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/README.rst index e32cc9537fa5..36b29020180e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentsTransport` is the ABC for all transports. -- public child `DocumentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentsTransport`` is the ABC for all transports. + +- public child ``DocumentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py index c118e1e6ab2c..63f41fed328f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py index 923c0162a87d..89c509336b8a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py index abed9328a837..b2ed7a79b1b3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py index 503fe3224d6d..dd6f48e949c9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py @@ -708,6 +708,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/async_client.py index e0db52b7084e..2b3a32a32f0d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> EncryptionSpecServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -570,7 +570,7 @@ async def sample_initialize_encryption_spec(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -596,8 +596,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -606,7 +610,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -614,7 +618,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -625,7 +629,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -651,8 +655,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -661,7 +669,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -669,7 +677,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -680,7 +688,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -709,8 +717,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -719,7 +731,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -727,7 +739,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -735,7 +747,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -761,8 +773,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -771,7 +787,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -779,7 +795,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -790,7 +806,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -816,8 +832,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -826,7 +846,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -834,7 +854,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/client.py index 7a189e50efdd..ae9fd00a3b7f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/client.py @@ -116,7 +116,7 @@ class EncryptionSpecServiceClient(metaclass=EncryptionSpecServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -439,7 +443,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -638,7 +642,7 @@ def __init__( self._universe_domain = EncryptionSpecServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1002,7 +1006,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1028,8 +1032,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1038,7 +1046,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1047,7 +1055,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1061,7 +1069,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1087,8 +1095,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1097,7 +1109,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1106,7 +1118,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1120,7 +1132,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1149,8 +1161,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1159,7 +1175,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1167,7 +1183,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1175,7 +1191,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1201,8 +1217,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1211,7 +1231,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1220,7 +1240,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1234,7 +1254,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1260,8 +1280,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1270,7 +1294,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1279,7 +1303,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/README.rst index 41b8af159e75..23d25732bff4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EncryptionSpecServiceTransport` is the ABC for all transports. -- public child `EncryptionSpecServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EncryptionSpecServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEncryptionSpecServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EncryptionSpecServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EncryptionSpecServiceTransport`` is the ABC for all transports. + +- public child ``EncryptionSpecServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EncryptionSpecServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEncryptionSpecServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EncryptionSpecServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/base.py index 4b0133edd7d3..367946e1a294 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc.py index 624b36cf00fd..1431bda15cd2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc_asyncio.py index 7033d9def6db..d812b41a6bc9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/rest.py index 96920bb7c652..d93fc0fd3a06 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/encryption_spec_service/transports/rest.py @@ -386,6 +386,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EncryptionSpecServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py index 2d650c8bcc91..da05551cb593 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> EntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1782,7 +1782,7 @@ async def sample_batch_delete_entities(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1808,8 +1808,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1818,7 +1822,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1826,7 +1830,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1837,7 +1841,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1863,8 +1867,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1873,7 +1881,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1881,7 +1889,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1892,7 +1900,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1921,8 +1929,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1931,7 +1943,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1939,7 +1951,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1947,7 +1959,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1973,8 +1985,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1983,7 +1999,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1991,7 +2007,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2002,7 +2018,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2028,8 +2044,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2038,7 +2058,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2046,7 +2066,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py index e99777abcd75..c59a6b4ebd11 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py @@ -119,7 +119,7 @@ class EntityTypesClient(metaclass=EntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = EntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2198,7 +2202,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2224,8 +2228,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2234,7 +2242,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2243,7 +2251,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2257,7 +2265,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2283,8 +2291,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2293,7 +2305,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2302,7 +2314,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2316,7 +2328,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2345,8 +2357,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2355,7 +2371,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2363,7 +2379,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2371,7 +2387,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2397,8 +2413,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2407,7 +2427,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2416,7 +2436,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2430,7 +2450,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2456,8 +2476,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2466,7 +2490,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2475,7 +2499,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/README.rst index b4d0b3fbe48a..8f527eecf449 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EntityTypesTransport` is the ABC for all transports. -- public child `EntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EntityTypesTransport`` is the ABC for all transports. + +- public child ``EntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py index e6930e6174ad..5f7f84a0f1ad 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py index 0d1ca677f950..a42bbc64d226 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py index 418f8c8d917b..3218ceee1b4a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py index 48bd5da394cf..1ad60cee1153 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py @@ -799,6 +799,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py index 868a1f41b21e..241913ee5af3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> EnvironmentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -936,7 +936,7 @@ async def sample_get_environment_history(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -962,8 +962,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -972,7 +976,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -980,7 +984,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -991,7 +995,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1017,8 +1021,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1027,7 +1035,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1035,7 +1043,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1046,7 +1054,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1075,8 +1083,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1085,7 +1097,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1093,7 +1105,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1101,7 +1113,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1127,8 +1139,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1137,7 +1153,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1145,7 +1161,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1156,7 +1172,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1182,8 +1198,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1192,7 +1212,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1200,7 +1220,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py index c6ce51585dc4..dde07524cad1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py @@ -115,7 +115,7 @@ class EnvironmentsClient(metaclass=EnvironmentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -471,7 +475,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = EnvironmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1394,7 +1398,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1420,8 +1424,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1430,7 +1438,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1439,7 +1447,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1453,7 +1461,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1479,8 +1487,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1489,7 +1501,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1498,7 +1510,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1512,7 +1524,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1541,8 +1553,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1551,7 +1567,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1559,7 +1575,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1567,7 +1583,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1593,8 +1609,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1603,7 +1623,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1612,7 +1632,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1626,7 +1646,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1652,8 +1672,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1662,7 +1686,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1671,7 +1695,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/README.rst index bce85d4987a6..47903acc874a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EnvironmentsTransport` is the ABC for all transports. -- public child `EnvironmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EnvironmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEnvironmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EnvironmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EnvironmentsTransport`` is the ABC for all transports. + +- public child ``EnvironmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EnvironmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEnvironmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EnvironmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py index 1d65116e9ecd..70d4cff139ed 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py index c32a8066bc1c..f50a8eb969bb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py index 32713e2f9915..3712428f9da1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py index 64a8a81582ae..063fcab3bbe5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py @@ -573,6 +573,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EnvironmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py index 673a2fd7c174..9a4609d5d354 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> FulfillmentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -554,7 +554,7 @@ async def sample_update_fulfillment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -580,8 +580,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -590,7 +594,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -598,7 +602,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -609,7 +613,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -635,8 +639,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -645,7 +653,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -653,7 +661,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -664,7 +672,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -693,8 +701,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -703,7 +715,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -711,7 +723,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -719,7 +731,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -745,8 +757,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -755,7 +771,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -763,7 +779,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -774,7 +790,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -800,8 +816,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -810,7 +830,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -818,7 +838,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py index d412c834ae55..0fce2d8c886c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py @@ -115,7 +115,7 @@ class FulfillmentsClient(metaclass=FulfillmentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -530,7 +534,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( self._universe_domain = FulfillmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -985,7 +989,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1011,8 +1015,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1021,7 +1029,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1030,7 +1038,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1044,7 +1052,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1070,8 +1078,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1080,7 +1092,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1089,7 +1101,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1103,7 +1115,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1132,8 +1144,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1142,7 +1158,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1150,7 +1166,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1158,7 +1174,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1184,8 +1200,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1194,7 +1214,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1203,7 +1223,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1217,7 +1237,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1243,8 +1263,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1253,7 +1277,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1262,7 +1286,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/README.rst index d805f3c8fe03..1a07951285d5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FulfillmentsTransport` is the ABC for all transports. -- public child `FulfillmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FulfillmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFulfillmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FulfillmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FulfillmentsTransport`` is the ABC for all transports. + +- public child ``FulfillmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FulfillmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFulfillmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FulfillmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py index a39c98ea8567..662b50e03eef 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py index 297d7568c414..06e6cc97fdc2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py index d1b3eb3cee5b..bf52907e20d8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py index c0cdc9dae9f3..d69582eea134 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py @@ -385,6 +385,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FulfillmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/async_client.py index 9db02fc78c48..d03e14c4f2e2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> GeneratorEvaluationsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -813,7 +813,7 @@ async def sample_delete_generator_evaluation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -839,8 +839,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -849,7 +853,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -857,7 +861,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -868,7 +872,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -894,8 +898,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -904,7 +912,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -912,7 +920,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -923,7 +931,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -952,8 +960,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -962,7 +974,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -970,7 +982,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -978,7 +990,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1004,8 +1016,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1014,7 +1030,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1022,7 +1038,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1033,7 +1049,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1075,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1089,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1077,7 +1097,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/client.py index eba833af3603..294919aad191 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/client.py @@ -118,7 +118,7 @@ class GeneratorEvaluationsClient(metaclass=GeneratorEvaluationsClientMeta): """Service for managing generator evaluations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -489,7 +493,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -586,7 +590,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -686,7 +690,7 @@ def __init__( self._universe_domain = GeneratorEvaluationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1287,7 +1291,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1313,8 +1317,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1323,7 +1331,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1332,7 +1340,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1346,7 +1354,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1372,8 +1380,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1382,7 +1394,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1391,7 +1403,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1405,7 +1417,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1434,8 +1446,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1444,7 +1460,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1452,7 +1468,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1460,7 +1476,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1486,8 +1502,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1496,7 +1516,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1505,7 +1525,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1519,7 +1539,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1545,8 +1565,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1555,7 +1579,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1564,7 +1588,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/README.rst index d4d6f1446c83..9ef230eb18fb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeneratorEvaluationsTransport` is the ABC for all transports. -- public child `GeneratorEvaluationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeneratorEvaluationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeneratorEvaluationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeneratorEvaluationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeneratorEvaluationsTransport`` is the ABC for all transports. + +- public child ``GeneratorEvaluationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeneratorEvaluationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeneratorEvaluationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeneratorEvaluationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/base.py index 6917eecbd4f9..87978021a3e6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc.py index 33061a8aebe3..bf0f72cfb736 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc_asyncio.py index 2b6cd86c222d..ef85ad245d2b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/rest.py index 7a71892e3714..4a7e109b3214 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generator_evaluations/transports/rest.py @@ -470,6 +470,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeneratorEvaluationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/async_client.py index 330d466ec290..dd6fa36fe6d9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> GeneratorsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -902,7 +902,7 @@ async def sample_update_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -928,8 +928,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -938,7 +942,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -946,7 +950,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -957,7 +961,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -983,8 +987,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -993,7 +1001,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1001,7 +1009,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1012,7 +1020,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1041,8 +1049,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1051,7 +1063,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1059,7 +1071,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1067,7 +1079,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1093,8 +1105,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1103,7 +1119,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1111,7 +1127,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1138,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1164,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1178,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1166,7 +1186,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/client.py index 90381cea2553..365855fd35c1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/client.py @@ -120,7 +120,7 @@ class GeneratorsClient(metaclass=GeneratorsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = GeneratorsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1353,7 +1357,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1379,8 +1383,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1389,7 +1397,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1398,7 +1406,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1412,7 +1420,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1438,8 +1446,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1448,7 +1460,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1457,7 +1469,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1471,7 +1483,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1500,8 +1512,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1510,7 +1526,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1518,7 +1534,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1526,7 +1542,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1552,8 +1568,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1562,7 +1582,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1571,7 +1591,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1585,7 +1605,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1611,8 +1631,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1621,7 +1645,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1630,7 +1654,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/README.rst index c234b834ba8e..e218647a5ad5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeneratorsTransport` is the ABC for all transports. -- public child `GeneratorsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeneratorsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeneratorsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeneratorsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeneratorsTransport`` is the ABC for all transports. + +- public child ``GeneratorsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeneratorsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeneratorsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeneratorsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/base.py index df62742c595c..7aa9a9159b32 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc.py index 83d2a74d8657..c68093977573 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc_asyncio.py index c9ec8c4f6860..30a0cc29d5ea 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/rest.py index cd167d6da927..5f2ebfba102c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/generators/transports/rest.py @@ -516,6 +516,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeneratorsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py index cc752a4aba12..836dc1e69bc3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> IntentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1309,7 +1309,7 @@ async def sample_batch_delete_intents(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1335,8 +1335,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1345,7 +1349,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1353,7 +1357,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1368,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1390,8 +1394,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1400,7 +1408,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1408,7 +1416,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1419,7 +1427,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1448,8 +1456,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1458,7 +1470,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1466,7 +1478,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1474,7 +1486,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1500,8 +1512,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1510,7 +1526,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1518,7 +1534,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1529,7 +1545,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1555,8 +1571,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1565,7 +1585,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1573,7 +1593,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py index 28f8765dae27..3050befd45d2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py @@ -118,7 +118,7 @@ class IntentsClient(metaclass=IntentsClientMeta): """Service for managing [Intents][google.cloud.dialogflow.v2.Intent].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -460,7 +464,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -557,7 +561,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -653,7 +657,7 @@ def __init__( self._universe_domain = IntentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1751,7 +1755,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1777,8 +1781,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1787,7 +1795,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1796,7 +1804,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1810,7 +1818,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1836,8 +1844,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1846,7 +1858,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1855,7 +1867,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1869,7 +1881,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1898,8 +1910,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1908,7 +1924,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1916,7 +1932,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1924,7 +1940,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1950,8 +1966,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1960,7 +1980,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1969,7 +1989,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1983,7 +2003,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2009,8 +2029,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2019,7 +2043,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2028,7 +2052,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/README.rst index 38d1ee740feb..9709e71cbb93 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IntentsTransport` is the ABC for all transports. -- public child `IntentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IntentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIntentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IntentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IntentsTransport`` is the ABC for all transports. + +- public child ``IntentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IntentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIntentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IntentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py index af46cd89d217..82e6cdda1fb8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py index e0c071e9037c..4ea6d45dc3f1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py index 8cae740c2a73..e5c13d937be6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py index 8ae35d74f2a6..84a959d9a941 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py @@ -608,6 +608,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IntentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py index 23b2969d9be8..f62ecb7a8c8b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> KnowledgeBasesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -933,7 +933,7 @@ async def sample_update_knowledge_base(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -959,8 +959,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -969,7 +973,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -977,7 +981,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -988,7 +992,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1014,8 +1018,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1024,7 +1032,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1032,7 +1040,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1043,7 +1051,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1072,8 +1080,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1082,7 +1094,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1090,7 +1102,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1098,7 +1110,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1124,8 +1136,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1134,7 +1150,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1142,7 +1158,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1153,7 +1169,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1179,8 +1195,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1189,7 +1209,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1197,7 +1217,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py index 2761101bd387..1e1bab9e5e07 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py @@ -116,7 +116,7 @@ class KnowledgeBasesClient(metaclass=KnowledgeBasesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -438,7 +442,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -535,7 +539,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -631,7 +635,7 @@ def __init__( self._universe_domain = KnowledgeBasesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1356,7 +1360,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1382,8 +1386,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1392,7 +1400,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1401,7 +1409,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1415,7 +1423,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1441,8 +1449,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1451,7 +1463,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1460,7 +1472,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1474,7 +1486,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1503,8 +1515,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1513,7 +1529,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1521,7 +1537,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1529,7 +1545,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1555,8 +1571,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1565,7 +1585,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1574,7 +1594,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1588,7 +1608,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1614,8 +1634,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1624,7 +1648,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1633,7 +1657,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/README.rst index 182c8054de2b..81589fc15d0a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`KnowledgeBasesTransport` is the ABC for all transports. -- public child `KnowledgeBasesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `KnowledgeBasesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseKnowledgeBasesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `KnowledgeBasesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``KnowledgeBasesTransport`` is the ABC for all transports. + +- public child ``KnowledgeBasesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``KnowledgeBasesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseKnowledgeBasesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``KnowledgeBasesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py index 93c94039e92d..c477709df193 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py index c4b73666f284..3542aa30f911 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py index 9057483aa292..d08030f0f71c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py index 1f78812fc78c..75a1f540323d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py @@ -526,6 +526,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[KnowledgeBasesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py index 7aa8f795320d..508ada1daf04 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> ParticipantsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1549,7 +1549,7 @@ async def sample_suggest_knowledge_assist(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1575,8 +1575,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1585,7 +1589,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1593,7 +1597,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1604,7 +1608,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1630,8 +1634,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1640,7 +1648,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1648,7 +1656,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1659,7 +1667,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1688,8 +1696,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1698,7 +1710,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1706,7 +1718,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1714,7 +1726,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1740,8 +1752,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1750,7 +1766,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1758,7 +1774,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1769,7 +1785,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1795,8 +1811,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1805,7 +1825,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1813,7 +1833,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py index 4ef56e7d6a64..46a274dbd63a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py @@ -118,7 +118,7 @@ class ParticipantsClient(metaclass=ParticipantsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -591,7 +595,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -688,7 +692,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -784,7 +788,7 @@ def __init__( self._universe_domain = ParticipantsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2096,7 +2100,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2122,8 +2126,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2132,7 +2140,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2141,7 +2149,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2155,7 +2163,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2181,8 +2189,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2191,7 +2203,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2200,7 +2212,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2214,7 +2226,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2243,8 +2255,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2253,7 +2269,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2261,7 +2277,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2269,7 +2285,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2295,8 +2311,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2305,7 +2325,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2314,7 +2334,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2328,7 +2348,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2354,8 +2374,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2364,7 +2388,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2373,7 +2397,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/README.rst index 797199a35f26..93cb8a8c5845 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ParticipantsTransport` is the ABC for all transports. -- public child `ParticipantsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ParticipantsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseParticipantsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ParticipantsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ParticipantsTransport`` is the ABC for all transports. + +- public child ``ParticipantsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ParticipantsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseParticipantsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ParticipantsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py index 9f36fafde00b..3d619730aef5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py index 4a7b7c4a7518..eeca047836fd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py index 9985878762d9..5eac06ad1fdf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py index 77a3ede08947..b8aba87109cd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py @@ -792,6 +792,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ParticipantsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py index 958ec9362e16..e2a35e3f090f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SessionEntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -988,7 +988,7 @@ async def sample_delete_session_entity_type(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1014,8 +1014,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1024,7 +1028,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1032,7 +1036,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1043,7 +1047,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1069,8 +1073,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1079,7 +1087,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1087,7 +1095,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1098,7 +1106,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1127,8 +1135,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1137,7 +1149,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1145,7 +1157,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1153,7 +1165,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1179,8 +1191,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1189,7 +1205,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1197,7 +1213,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1208,7 +1224,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1234,8 +1250,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1244,7 +1264,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1252,7 +1272,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py index e06b75d3f079..38a707e2b521 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py @@ -118,7 +118,7 @@ class SessionEntityTypesClient(metaclass=SessionEntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -640,7 +644,7 @@ def __init__( self._universe_domain = SessionEntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1419,7 +1423,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1445,8 +1449,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1455,7 +1463,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1464,7 +1472,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1478,7 +1486,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1504,8 +1512,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1514,7 +1526,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1523,7 +1535,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1537,7 +1549,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1566,8 +1578,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1576,7 +1592,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1584,7 +1600,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1592,7 +1608,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1618,8 +1634,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1628,7 +1648,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1637,7 +1657,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1651,7 +1671,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1677,8 +1697,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1687,7 +1711,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1696,7 +1720,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/README.rst index fa50039837f6..edbabf709074 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionEntityTypesTransport` is the ABC for all transports. -- public child `SessionEntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionEntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionEntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionEntityTypesTransport`` is the ABC for all transports. + +- public child ``SessionEntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionEntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionEntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py index d0e1e1d8d42e..03dde8d7446e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py index 67b130cbc0f9..756419d03523 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py index 782a3ce5b141..bb3de5c4cd71 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py index dec556b5a96c..5ee223e35e51 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py @@ -533,6 +533,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionEntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py index 9af499eea757..b3e45a67387f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> SessionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -633,7 +633,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -659,8 +659,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -669,7 +673,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -677,7 +681,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -688,7 +692,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -714,8 +718,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -724,7 +732,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -732,7 +740,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -743,7 +751,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -772,8 +780,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -782,7 +794,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -790,7 +802,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -798,7 +810,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -824,8 +836,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -834,7 +850,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -842,7 +858,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -853,7 +869,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -879,8 +895,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -889,7 +909,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -897,7 +917,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py index cea9975d5458..3798dcec913a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py @@ -119,7 +119,7 @@ class SessionsClient(metaclass=SessionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -524,7 +528,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -621,7 +625,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -717,7 +721,7 @@ def __init__( self._universe_domain = SessionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1145,7 +1149,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1171,8 +1175,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1181,7 +1189,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1190,7 +1198,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1204,7 +1212,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1230,8 +1238,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1240,7 +1252,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1249,7 +1261,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1263,7 +1275,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1292,8 +1304,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1302,7 +1318,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1310,7 +1326,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1318,7 +1334,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1344,8 +1360,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1354,7 +1374,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1363,7 +1383,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1377,7 +1397,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1403,8 +1423,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1413,7 +1437,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1422,7 +1446,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/README.rst index ff5ae65346f4..bff74be61084 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionsTransport` is the ABC for all transports. -- public child `SessionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionsTransport`` is the ABC for all transports. + +- public child ``SessionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py index 49e6078ddc80..e1015022ec0c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py index ef4a2a845bd6..8647daf1190f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py index 162704db94c6..c4c0cd9ae1c4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py index ea51fc6690db..1d25e597ea95 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py @@ -332,6 +332,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/async_client.py index d85cd80c8222..a957c1e4eb86 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> SipTrunksTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -888,7 +888,7 @@ async def sample_update_sip_trunk(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -914,8 +914,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -924,7 +928,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -932,7 +936,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -943,7 +947,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -969,8 +973,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -979,7 +987,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -987,7 +995,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -998,7 +1006,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1035,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1049,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1057,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1053,7 +1065,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1079,8 +1091,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1089,7 +1105,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1097,7 +1113,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1108,7 +1124,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1150,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1164,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1172,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/client.py index d5a0914c7759..624e719e2035 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/client.py @@ -116,7 +116,7 @@ class SipTrunksClient(metaclass=SipTrunksClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = SipTrunksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1319,7 +1323,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1345,8 +1349,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1355,7 +1363,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1364,7 +1372,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1378,7 +1386,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1404,8 +1412,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1414,7 +1426,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1423,7 +1435,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1437,7 +1449,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1466,8 +1478,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1476,7 +1492,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1484,7 +1500,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1492,7 +1508,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1518,8 +1534,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1528,7 +1548,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1537,7 +1557,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1551,7 +1571,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1577,8 +1597,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1587,7 +1611,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1596,7 +1620,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/README.rst index 8351a234d6f9..b7973953c8d4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SipTrunksTransport` is the ABC for all transports. -- public child `SipTrunksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SipTrunksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSipTrunksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SipTrunksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SipTrunksTransport`` is the ABC for all transports. + +- public child ``SipTrunksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SipTrunksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSipTrunksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SipTrunksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/base.py index b2c6b3865f00..d45c68f4bcdf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc.py index bdc83144f0fd..b98ca1609b2e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc_asyncio.py index 2e3ddd28fcca..c36304bafc70 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/rest.py index 2e79e8039c53..4940841d8a94 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sip_trunks/transports/rest.py @@ -511,6 +511,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SipTrunksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/async_client.py index 2aac2373935a..7acc42429ac7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> ToolsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -896,7 +896,7 @@ async def sample_update_tool(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -922,8 +922,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -932,7 +936,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -940,7 +944,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -951,7 +955,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -977,8 +981,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -987,7 +995,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -995,7 +1003,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1006,7 +1014,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1035,8 +1043,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1045,7 +1057,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1053,7 +1065,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1061,7 +1073,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1087,8 +1099,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1097,7 +1113,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1105,7 +1121,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1116,7 +1132,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1142,8 +1158,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1152,7 +1172,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1160,7 +1180,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/client.py index 6992358dfdd5..9d63686eadea 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/client.py @@ -118,7 +118,7 @@ class ToolsClient(metaclass=ToolsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -489,7 +493,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -586,7 +590,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -682,7 +686,7 @@ def __init__( self._universe_domain = ToolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1375,7 +1379,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1401,8 +1405,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1411,7 +1419,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1420,7 +1428,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1434,7 +1442,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1460,8 +1468,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1470,7 +1482,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1479,7 +1491,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1493,7 +1505,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1522,8 +1534,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1532,7 +1548,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1540,7 +1556,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1548,7 +1564,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1574,8 +1590,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1584,7 +1604,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1593,7 +1613,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1607,7 +1627,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1633,8 +1653,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1643,7 +1667,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1652,7 +1676,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/README.rst index f7b77e1167bf..6a4417039c6e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ToolsTransport` is the ABC for all transports. -- public child `ToolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ToolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseToolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ToolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ToolsTransport`` is the ABC for all transports. + +- public child ``ToolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ToolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseToolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ToolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/base.py index 1a7042b7a500..4897eabc1469 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc.py index 9e54c922ca00..b51166d87033 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc_asyncio.py index 5e49c2382a3b..48330ce946e9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/rest.py index b9945ebf3875..4f7222bb0150 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/tools/transports/rest.py @@ -494,6 +494,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ToolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py index 68ee1a17be16..08021bf90a7d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> VersionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -949,7 +949,7 @@ async def sample_delete_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -975,8 +975,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -985,7 +989,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -993,7 +997,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1004,7 +1008,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1030,8 +1034,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1040,7 +1048,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1048,7 +1056,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1059,7 +1067,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1088,8 +1096,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1098,7 +1110,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1106,7 +1118,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1114,7 +1126,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1140,8 +1152,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1150,7 +1166,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1158,7 +1174,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1169,7 +1185,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1195,8 +1211,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1205,7 +1225,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1213,7 +1233,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py index ab7db5403368..782db54e0654 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py @@ -115,7 +115,7 @@ class VersionsClient(metaclass=VersionsClientMeta): """Service for managing [Versions][google.cloud.dialogflow.v2.Version].""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -630,7 +634,7 @@ def __init__( self._universe_domain = VersionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1379,7 +1383,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1405,8 +1409,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1415,7 +1423,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1424,7 +1432,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1438,7 +1446,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1464,8 +1472,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1474,7 +1486,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1483,7 +1495,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1497,7 +1509,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1526,8 +1538,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1536,7 +1552,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1544,7 +1560,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1552,7 +1568,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1578,8 +1594,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1588,7 +1608,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1597,7 +1617,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1611,7 +1631,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1637,8 +1657,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1647,7 +1671,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1656,7 +1680,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/README.rst index ac30fdf3d846..f820acfcbfa3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VersionsTransport` is the ABC for all transports. -- public child `VersionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VersionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVersionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VersionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VersionsTransport`` is the ABC for all transports. + +- public child ``VersionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VersionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVersionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VersionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py index 496a944a62e2..bb4cd4ce3617 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py index a2cf35ec0764..9c70f21dd541 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py index d4b4021821ed..5e40aab02ea6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py index 4b3cb677e1a4..b91a1549ece2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py @@ -502,6 +502,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VersionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py index c52dde41b9aa..6e502e3c1127 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> AgentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1421,7 +1421,7 @@ async def sample_get_validation_result(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1447,8 +1447,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1457,7 +1461,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1465,7 +1469,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1476,7 +1480,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1502,8 +1506,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1512,7 +1520,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1520,7 +1528,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1531,7 +1539,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1560,8 +1568,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1570,7 +1582,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1578,7 +1590,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1586,7 +1598,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1612,8 +1624,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1622,7 +1638,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1630,7 +1646,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1641,7 +1657,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1667,8 +1683,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1677,7 +1697,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1685,7 +1705,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py index 5966b1d8e7aa..ea491d3b27ab 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py @@ -119,7 +119,7 @@ class AgentsClient(metaclass=AgentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -630,7 +634,7 @@ def __init__( self._universe_domain = AgentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1840,7 +1844,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1866,8 +1870,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1876,7 +1884,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1885,7 +1893,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1899,7 +1907,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1925,8 +1933,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1935,7 +1947,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1944,7 +1956,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1958,7 +1970,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1987,8 +1999,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1997,7 +2013,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2005,7 +2021,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2013,7 +2029,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2039,8 +2055,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2049,7 +2069,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2058,7 +2078,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2072,7 +2092,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2098,8 +2118,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2108,7 +2132,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2117,7 +2141,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/README.rst index 588acebd9fdd..0a289f4e53c3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AgentsTransport` is the ABC for all transports. -- public child `AgentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AgentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAgentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AgentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AgentsTransport`` is the ABC for all transports. + +- public child ``AgentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AgentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAgentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AgentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py index 547bcae9d2c2..8bcd409f44b0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py index 4ba94ab29893..e56d94eed1e5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py index 8bd55111c7e3..ca53eae1bc74 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py index 9cf98a6797bf..ada3b440d2c0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py @@ -719,6 +719,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AgentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py index 28d36a39d58e..43508ed49a9d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> AnswerRecordsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -717,7 +717,7 @@ async def sample_update_answer_record(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -743,8 +743,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -753,7 +757,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -761,7 +765,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -772,7 +776,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -798,8 +802,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -808,7 +816,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -816,7 +824,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -827,7 +835,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -856,8 +864,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -866,7 +878,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -874,7 +886,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -882,7 +894,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -908,8 +920,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -918,7 +934,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -926,7 +942,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -937,7 +953,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -963,8 +979,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -973,7 +993,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -981,7 +1001,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py index cdbc72884617..ff8fbd219e65 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py @@ -116,7 +116,7 @@ class AnswerRecordsClient(metaclass=AnswerRecordsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -521,7 +525,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -618,7 +622,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -714,7 +718,7 @@ def __init__( self._universe_domain = AnswerRecordsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1220,7 +1224,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1246,8 +1250,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1256,7 +1264,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1265,7 +1273,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1279,7 +1287,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1305,8 +1313,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1315,7 +1327,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1324,7 +1336,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1338,7 +1350,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1367,8 +1379,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1377,7 +1393,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1385,7 +1401,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1393,7 +1409,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1419,8 +1435,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1429,7 +1449,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1438,7 +1458,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1452,7 +1472,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1478,8 +1498,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1488,7 +1512,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1497,7 +1521,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/README.rst index f061d90902ce..1f50d03c3e46 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AnswerRecordsTransport` is the ABC for all transports. -- public child `AnswerRecordsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AnswerRecordsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAnswerRecordsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AnswerRecordsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AnswerRecordsTransport`` is the ABC for all transports. + +- public child ``AnswerRecordsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AnswerRecordsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAnswerRecordsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AnswerRecordsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py index b8b407cf1a7a..ce61c173af02 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py index 0c07d2b2fc4c..90fd6989653b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py index a16f6c3c52ac..7a2b8fce3bda 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py index 946b59a74af5..facc69245cc3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py @@ -443,6 +443,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AnswerRecordsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py index de7e8f555a90..a1505ea655a8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> ContextsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1073,7 +1073,7 @@ async def sample_delete_all_contexts(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1099,8 +1099,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1109,7 +1113,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1117,7 +1121,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1128,7 +1132,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1154,8 +1158,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1164,7 +1172,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1172,7 +1180,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1183,7 +1191,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1212,8 +1220,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1222,7 +1234,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1230,7 +1242,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1238,7 +1250,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1264,8 +1276,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1274,7 +1290,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1282,7 +1298,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1293,7 +1309,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1319,8 +1335,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1329,7 +1349,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1337,7 +1357,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py index 24c029e18201..285e5500e6ba 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py @@ -117,7 +117,7 @@ class ContextsClient(metaclass=ContextsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = ContextsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1503,7 +1507,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1529,8 +1533,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1539,7 +1547,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1548,7 +1556,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1562,7 +1570,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1588,8 +1596,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1598,7 +1610,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1607,7 +1619,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1621,7 +1633,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1650,8 +1662,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1660,7 +1676,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1668,7 +1684,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1676,7 +1692,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1702,8 +1718,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1712,7 +1732,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1721,7 +1741,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1735,7 +1755,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1761,8 +1781,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1771,7 +1795,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1780,7 +1804,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/README.rst index be49e5b446d8..ae6892ceba4d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ContextsTransport` is the ABC for all transports. -- public child `ContextsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ContextsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseContextsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ContextsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ContextsTransport`` is the ABC for all transports. + +- public child ``ContextsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ContextsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseContextsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ContextsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py index 00e2310a8a19..9c9250d75e25 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py index 4874cadc25f9..098c913d7b8c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py index b8cc8d2f9883..f3074af10285 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py index d7bdd1e31343..b98f1ad3ad8d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py @@ -521,6 +521,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ContextsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py index ac5bcc2f5b59..effff9497144 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py @@ -233,7 +233,7 @@ def transport(self) -> ConversationProfilesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1333,7 +1333,7 @@ async def sample_clear_suggestion_feature_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1359,8 +1359,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1369,7 +1373,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1377,7 +1381,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1388,7 +1392,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1414,8 +1418,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1424,7 +1432,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1432,7 +1440,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1443,7 +1451,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1472,8 +1480,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1482,7 +1494,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1490,7 +1502,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1498,7 +1510,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1524,8 +1536,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1534,7 +1550,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1542,7 +1558,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1553,7 +1569,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1579,8 +1595,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1589,7 +1609,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1597,7 +1617,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py index 9de76b529fab..7b451338308e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py @@ -125,7 +125,7 @@ class ConversationProfilesClient(metaclass=ConversationProfilesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -592,7 +596,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -689,7 +693,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -789,7 +793,7 @@ def __init__( self._universe_domain = ConversationProfilesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1878,7 +1882,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1904,8 +1908,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1914,7 +1922,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1923,7 +1931,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1937,7 +1945,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1963,8 +1971,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1973,7 +1985,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1982,7 +1994,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1996,7 +2008,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2025,8 +2037,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2035,7 +2051,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2043,7 +2059,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2051,7 +2067,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2077,8 +2093,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2087,7 +2107,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2096,7 +2116,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2110,7 +2130,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2136,8 +2156,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2146,7 +2170,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2155,7 +2179,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/README.rst index 46d5e61b80d3..d95de5267564 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationProfilesTransport` is the ABC for all transports. -- public child `ConversationProfilesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationProfilesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationProfilesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationProfilesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationProfilesTransport`` is the ABC for all transports. + +- public child ``ConversationProfilesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationProfilesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationProfilesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationProfilesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py index d38fcc1f3c92..9d2830caa435 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py index 40bc0f6d202d..3400f4dda2a7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py index d4a23fbc94da..6599e5da6f2a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py index c10a78be6025..4f67567cafe9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py @@ -648,6 +648,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationProfilesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py index 6a87068b4f89..440358830bd0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py @@ -230,7 +230,7 @@ def transport(self) -> ConversationsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1777,7 +1777,7 @@ async def sample_generate_suggestions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1803,8 +1803,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1813,7 +1817,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1821,7 +1825,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1832,7 +1836,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1858,8 +1862,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1868,7 +1876,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1876,7 +1884,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1887,7 +1895,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1916,8 +1924,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1926,7 +1938,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1934,7 +1946,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1942,7 +1954,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1968,8 +1980,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1978,7 +1994,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1986,7 +2002,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1997,7 +2013,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2023,8 +2039,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2033,7 +2053,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2041,7 +2061,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py index 58b7e8b5b410..296f364ac5c2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py @@ -116,7 +116,7 @@ class ConversationsClient(metaclass=ConversationsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -691,7 +695,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -788,7 +792,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -884,7 +888,7 @@ def __init__( self._universe_domain = ConversationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2406,7 +2410,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2432,8 +2436,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2442,7 +2450,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2451,7 +2459,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2465,7 +2473,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2491,8 +2499,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2501,7 +2513,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2510,7 +2522,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2524,7 +2536,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2553,8 +2565,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2563,7 +2579,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2571,7 +2587,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2579,7 +2595,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2605,8 +2621,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2615,7 +2635,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2624,7 +2644,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2638,7 +2658,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2664,8 +2684,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2674,7 +2698,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2683,7 +2707,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/README.rst index a042fbfdf9ec..83e09969a531 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationsTransport` is the ABC for all transports. -- public child `ConversationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationsTransport`` is the ABC for all transports. + +- public child ``ConversationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py index 8113b9dd1eca..a9e030d39a20 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py index efc44cddf14b..9d6a6730caab 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py index d20bc8373567..de086027a59b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py index 6938edaadfaf..fc86d135dd4b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py @@ -974,6 +974,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py index 74a631c32b64..b40f0ef7bf21 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> DocumentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1305,7 +1305,7 @@ async def sample_reload_document(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1331,8 +1331,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1341,7 +1345,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1349,7 +1353,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1360,7 +1364,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1386,8 +1390,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1396,7 +1404,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1404,7 +1412,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1415,7 +1423,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1444,8 +1452,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1454,7 +1466,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1462,7 +1474,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1470,7 +1482,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1496,8 +1508,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1506,7 +1522,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1514,7 +1530,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1525,7 +1541,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1551,8 +1567,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1561,7 +1581,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1569,7 +1589,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py index 8c96e3ac162d..4eac5a87d645 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py @@ -119,7 +119,7 @@ class DocumentsClient(metaclass=DocumentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -637,7 +641,7 @@ def __init__( self._universe_domain = DocumentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1731,7 +1735,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1757,8 +1761,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1767,7 +1775,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1776,7 +1784,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1790,7 +1798,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1816,8 +1824,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1826,7 +1838,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1835,7 +1847,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1849,7 +1861,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1878,8 +1890,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1888,7 +1904,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1896,7 +1912,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1904,7 +1920,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1930,8 +1946,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1940,7 +1960,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1949,7 +1969,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1963,7 +1983,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1989,8 +2009,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1999,7 +2023,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2008,7 +2032,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/README.rst index e32cc9537fa5..36b29020180e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentsTransport` is the ABC for all transports. -- public child `DocumentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentsTransport`` is the ABC for all transports. + +- public child ``DocumentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py index ea2978b82cd8..e42878e88204 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py index 73b12c48e2d5..bb291e72cd8d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py index b5cbcd7deb4e..de05e6e826e3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py index 1ab9882cbd12..a0fa3a320f1e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py @@ -654,6 +654,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/async_client.py index ab21fc9ba03a..ddf64ffede8b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> EncryptionSpecServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -570,7 +570,7 @@ async def sample_initialize_encryption_spec(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -596,8 +596,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -606,7 +610,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -614,7 +618,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -625,7 +629,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -651,8 +655,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -661,7 +669,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -669,7 +677,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -680,7 +688,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -709,8 +717,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -719,7 +731,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -727,7 +739,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -735,7 +747,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -761,8 +773,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -771,7 +787,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -779,7 +795,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -790,7 +806,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -816,8 +832,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -826,7 +846,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -834,7 +854,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/client.py index 8ea53be64333..6718622fc1f2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/client.py @@ -116,7 +116,7 @@ class EncryptionSpecServiceClient(metaclass=EncryptionSpecServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -439,7 +443,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -638,7 +642,7 @@ def __init__( self._universe_domain = EncryptionSpecServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1002,7 +1006,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1028,8 +1032,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1038,7 +1046,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1047,7 +1055,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1061,7 +1069,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1087,8 +1095,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1097,7 +1109,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1106,7 +1118,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1120,7 +1132,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1149,8 +1161,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1159,7 +1175,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1167,7 +1183,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1175,7 +1191,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1201,8 +1217,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1211,7 +1231,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1220,7 +1240,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1234,7 +1254,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1260,8 +1280,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1270,7 +1294,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1279,7 +1303,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/README.rst index 41b8af159e75..23d25732bff4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EncryptionSpecServiceTransport` is the ABC for all transports. -- public child `EncryptionSpecServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EncryptionSpecServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEncryptionSpecServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EncryptionSpecServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EncryptionSpecServiceTransport`` is the ABC for all transports. + +- public child ``EncryptionSpecServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EncryptionSpecServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEncryptionSpecServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EncryptionSpecServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/base.py index 8f82f6734e84..753ad4ac8045 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc.py index ad2b035c8485..4d7d168df6d5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc_asyncio.py index 3b096f55a2ce..584c92e8111b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/rest.py index 4a09112125fc..a6af919aa120 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/encryption_spec_service/transports/rest.py @@ -386,6 +386,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EncryptionSpecServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py index 58424a545943..e1a77c5aa107 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> EntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1812,7 +1812,7 @@ async def sample_batch_delete_entities(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1838,8 +1838,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1848,7 +1852,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1856,7 +1860,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1867,7 +1871,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1893,8 +1897,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1903,7 +1911,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1911,7 +1919,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1922,7 +1930,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1951,8 +1959,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1961,7 +1973,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1969,7 +1981,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1977,7 +1989,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2003,8 +2015,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2013,7 +2029,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2021,7 +2037,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2032,7 +2048,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2058,8 +2074,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2068,7 +2088,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2076,7 +2096,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py index 405fe3641938..23a36d5309bb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py @@ -120,7 +120,7 @@ class EntityTypesClient(metaclass=EntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = EntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2228,7 +2232,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2254,8 +2258,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2264,7 +2272,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2273,7 +2281,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2287,7 +2295,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2313,8 +2321,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2323,7 +2335,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2332,7 +2344,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2346,7 +2358,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2375,8 +2387,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2385,7 +2401,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2393,7 +2409,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2401,7 +2417,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2427,8 +2443,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2437,7 +2457,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2446,7 +2466,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2460,7 +2480,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2486,8 +2506,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2496,7 +2520,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2505,7 +2529,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/README.rst index b4d0b3fbe48a..8f527eecf449 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EntityTypesTransport` is the ABC for all transports. -- public child `EntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EntityTypesTransport`` is the ABC for all transports. + +- public child ``EntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py index 0b9d8e274fae..2aa82ad3ecb6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py index 8fd80c17fb51..0c85202c2742 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py index c390c991be36..edc60527c50f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py index e697b92d964f..3e7c9a21d63f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py @@ -799,6 +799,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py index 1958c4907e56..c800c4936b1a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> EnvironmentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -935,7 +935,7 @@ async def sample_get_environment_history(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -961,8 +961,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -971,7 +975,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -979,7 +983,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -990,7 +994,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1016,8 +1020,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1026,7 +1034,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1034,7 +1042,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1045,7 +1053,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1074,8 +1082,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1084,7 +1096,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1104,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1100,7 +1112,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1126,8 +1138,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1136,7 +1152,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1144,7 +1160,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1155,7 +1171,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1181,8 +1197,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1191,7 +1211,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1199,7 +1219,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py index 2caca4ab9e75..4c0a87860daf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py @@ -115,7 +115,7 @@ class EnvironmentsClient(metaclass=EnvironmentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -471,7 +475,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = EnvironmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1393,7 +1397,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1419,8 +1423,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1429,7 +1437,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1438,7 +1446,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1452,7 +1460,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1478,8 +1486,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1488,7 +1500,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1497,7 +1509,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1511,7 +1523,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1540,8 +1552,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1550,7 +1566,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1558,7 +1574,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1566,7 +1582,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1592,8 +1608,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1602,7 +1622,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1611,7 +1631,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1625,7 +1645,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1651,8 +1671,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1661,7 +1685,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1670,7 +1694,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/README.rst index bce85d4987a6..47903acc874a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EnvironmentsTransport` is the ABC for all transports. -- public child `EnvironmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EnvironmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEnvironmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EnvironmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EnvironmentsTransport`` is the ABC for all transports. + +- public child ``EnvironmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EnvironmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEnvironmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EnvironmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py index 5320f012343b..f4ece27c8a7b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py index 837bdecf1d90..67b62572cbd2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py index 836dc3be030c..f7faed3b3928 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py index e74c1a462754..e41eb24835c5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py @@ -573,6 +573,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EnvironmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py index 7ceea0348433..0f9b0dda998b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py @@ -187,7 +187,7 @@ def transport(self) -> FulfillmentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -557,7 +557,7 @@ async def sample_update_fulfillment(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -583,8 +583,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -593,7 +597,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -601,7 +605,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -612,7 +616,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -638,8 +642,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -648,7 +656,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -656,7 +664,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -667,7 +675,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -696,8 +704,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -706,7 +718,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -714,7 +726,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -722,7 +734,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -748,8 +760,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -758,7 +774,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -766,7 +782,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -777,7 +793,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -803,8 +819,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -813,7 +833,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -821,7 +841,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py index 49bc8b2526d9..6d3323b339b6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py @@ -115,7 +115,7 @@ class FulfillmentsClient(metaclass=FulfillmentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -530,7 +534,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( self._universe_domain = FulfillmentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -988,7 +992,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1014,8 +1018,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1024,7 +1032,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1033,7 +1041,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1047,7 +1055,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1073,8 +1081,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1083,7 +1095,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1104,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1106,7 +1118,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1135,8 +1147,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1145,7 +1161,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1153,7 +1169,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1161,7 +1177,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1187,8 +1203,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1197,7 +1217,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1206,7 +1226,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1220,7 +1240,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1246,8 +1266,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1256,7 +1280,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1265,7 +1289,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/README.rst index d805f3c8fe03..1a07951285d5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FulfillmentsTransport` is the ABC for all transports. -- public child `FulfillmentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FulfillmentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFulfillmentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FulfillmentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FulfillmentsTransport`` is the ABC for all transports. + +- public child ``FulfillmentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FulfillmentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFulfillmentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FulfillmentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py index 18658cca1f76..ccaa4d3004c7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py index 80d6ff899b00..2152d7744d85 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py index e05cb06c4c50..37d3d0accd8a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py index 25066baf5d40..34b7392afc02 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py @@ -385,6 +385,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FulfillmentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/async_client.py index 5f7211f98b6d..f1a0bdcf0d7c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/async_client.py @@ -208,7 +208,7 @@ def transport(self) -> GeneratorEvaluationsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -817,7 +817,7 @@ async def sample_delete_generator_evaluation(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -843,8 +843,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -853,7 +857,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -861,7 +865,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -872,7 +876,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -898,8 +902,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -908,7 +916,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -916,7 +924,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -927,7 +935,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -956,8 +964,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -966,7 +978,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -974,7 +986,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -982,7 +994,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1008,8 +1020,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1018,7 +1034,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1026,7 +1042,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1037,7 +1053,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1063,8 +1079,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1073,7 +1093,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1081,7 +1101,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/client.py index 4765c7891be0..d6abe20edb25 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/client.py @@ -122,7 +122,7 @@ class GeneratorEvaluationsClient(metaclass=GeneratorEvaluationsClientMeta): """Service for managing generator evaluations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -493,7 +497,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -590,7 +594,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -690,7 +694,7 @@ def __init__( self._universe_domain = GeneratorEvaluationsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1291,7 +1295,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1317,8 +1321,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1327,7 +1335,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1336,7 +1344,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1350,7 +1358,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1376,8 +1384,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1386,7 +1398,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1395,7 +1407,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1409,7 +1421,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1438,8 +1450,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1448,7 +1464,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1456,7 +1472,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1464,7 +1480,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1490,8 +1506,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1500,7 +1520,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1509,7 +1529,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1523,7 +1543,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1549,8 +1569,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1559,7 +1583,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1568,7 +1592,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/README.rst index d4d6f1446c83..9ef230eb18fb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeneratorEvaluationsTransport` is the ABC for all transports. -- public child `GeneratorEvaluationsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeneratorEvaluationsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeneratorEvaluationsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeneratorEvaluationsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeneratorEvaluationsTransport`` is the ABC for all transports. + +- public child ``GeneratorEvaluationsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeneratorEvaluationsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeneratorEvaluationsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeneratorEvaluationsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/base.py index 4a5093c7abc5..23bc32afc8a9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc.py index 6500c77e9762..0fe2c58ac63d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc_asyncio.py index 9903bfe41f51..89bfd990ee8d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/rest.py index 770ce503b11a..f34deb3a2901 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generator_evaluations/transports/rest.py @@ -470,6 +470,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeneratorEvaluationsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/async_client.py index 4400c345e837..5e1ac807480a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> GeneratorsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -902,7 +902,7 @@ async def sample_update_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -928,8 +928,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -938,7 +942,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -946,7 +950,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -957,7 +961,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -983,8 +987,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -993,7 +1001,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1001,7 +1009,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1012,7 +1020,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1041,8 +1049,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1051,7 +1063,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1059,7 +1071,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1067,7 +1079,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1093,8 +1105,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1103,7 +1119,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1111,7 +1127,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1138,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1148,8 +1164,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1158,7 +1178,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1166,7 +1186,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/client.py index 4e6d6f47d999..127c45a5f3c7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/client.py @@ -120,7 +120,7 @@ class GeneratorsClient(metaclass=GeneratorsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = GeneratorsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1353,7 +1357,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1379,8 +1383,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1389,7 +1397,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1398,7 +1406,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1412,7 +1420,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1438,8 +1446,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1448,7 +1460,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1457,7 +1469,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1471,7 +1483,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1500,8 +1512,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1510,7 +1526,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1518,7 +1534,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1526,7 +1542,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1552,8 +1568,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1562,7 +1582,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1571,7 +1591,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1585,7 +1605,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1611,8 +1631,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1621,7 +1645,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1630,7 +1654,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/README.rst index c234b834ba8e..e218647a5ad5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GeneratorsTransport` is the ABC for all transports. -- public child `GeneratorsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GeneratorsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGeneratorsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GeneratorsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GeneratorsTransport`` is the ABC for all transports. + +- public child ``GeneratorsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GeneratorsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGeneratorsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GeneratorsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/base.py index d0ec23924a15..b722d9dffcb1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc.py index 8c410dc94b14..ed1b3b4257e7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc_asyncio.py index 3cb6461ee90f..5017fbc56964 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/rest.py index 5a2d91e59162..18c798d25efa 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/generators/transports/rest.py @@ -516,6 +516,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GeneratorsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py index 3954ca8e0519..f767288f2b78 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> IntentsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1327,7 +1327,7 @@ async def sample_batch_delete_intents(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1353,8 +1353,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1363,7 +1367,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1371,7 +1375,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1382,7 +1386,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1408,8 +1412,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1418,7 +1426,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1426,7 +1434,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1437,7 +1445,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1466,8 +1474,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1476,7 +1488,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1484,7 +1496,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1492,7 +1504,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1518,8 +1530,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1528,7 +1544,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1536,7 +1552,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1547,7 +1563,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1573,8 +1589,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1583,7 +1603,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1591,7 +1611,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py index fbdbda682bd7..4c9845644a22 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py @@ -120,7 +120,7 @@ class IntentsClient(metaclass=IntentsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -462,7 +466,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -559,7 +563,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -655,7 +659,7 @@ def __init__( self._universe_domain = IntentsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1769,7 +1773,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1795,8 +1799,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1805,7 +1813,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1814,7 +1822,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1828,7 +1836,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1854,8 +1862,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1864,7 +1876,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1873,7 +1885,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1887,7 +1899,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1916,8 +1928,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1926,7 +1942,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1934,7 +1950,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1942,7 +1958,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1968,8 +1984,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1978,7 +1998,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1987,7 +2007,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2001,7 +2021,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2027,8 +2047,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2037,7 +2061,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2046,7 +2070,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/README.rst index 38d1ee740feb..9709e71cbb93 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IntentsTransport` is the ABC for all transports. -- public child `IntentsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IntentsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIntentsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IntentsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IntentsTransport`` is the ABC for all transports. + +- public child ``IntentsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IntentsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIntentsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IntentsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py index 05a31320d74b..bf80603c6f30 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py index b896a1544410..7dc58ea1a8b1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py index 8c8189e90828..3f2518674751 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py index faa174edc68b..4739d9dd89bb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py @@ -609,6 +609,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IntentsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py index 28c3d702b3de..365f2acc7ff0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py @@ -194,7 +194,7 @@ def transport(self) -> KnowledgeBasesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -947,7 +947,7 @@ async def sample_update_knowledge_base(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -973,8 +973,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -983,7 +987,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -991,7 +995,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1002,7 +1006,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1028,8 +1032,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1038,7 +1046,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1046,7 +1054,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1057,7 +1065,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1086,8 +1094,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1096,7 +1108,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1104,7 +1116,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1112,7 +1124,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1138,8 +1150,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1148,7 +1164,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1156,7 +1172,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1167,7 +1183,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1193,8 +1209,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1203,7 +1223,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1211,7 +1231,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py index 1742a07f1344..4d75c2f769e3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py @@ -116,7 +116,7 @@ class KnowledgeBasesClient(metaclass=KnowledgeBasesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -438,7 +442,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -535,7 +539,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -631,7 +635,7 @@ def __init__( self._universe_domain = KnowledgeBasesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1370,7 +1374,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1396,8 +1400,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1406,7 +1414,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1415,7 +1423,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1429,7 +1437,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1455,8 +1463,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1465,7 +1477,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1474,7 +1486,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1488,7 +1500,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1517,8 +1529,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1527,7 +1543,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1535,7 +1551,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1543,7 +1559,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1569,8 +1585,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1579,7 +1599,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1588,7 +1608,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1602,7 +1622,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1628,8 +1648,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1638,7 +1662,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1647,7 +1671,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/README.rst index 182c8054de2b..81589fc15d0a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`KnowledgeBasesTransport` is the ABC for all transports. -- public child `KnowledgeBasesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `KnowledgeBasesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseKnowledgeBasesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `KnowledgeBasesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``KnowledgeBasesTransport`` is the ABC for all transports. + +- public child ``KnowledgeBasesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``KnowledgeBasesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseKnowledgeBasesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``KnowledgeBasesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py index 6308633fa006..aed46d5a344a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py index b70302b48e88..c70a4e1e822f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py index a4a20044d500..39a1babf8536 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py index c8c94036ab3f..8c0d73803eeb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py @@ -526,6 +526,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[KnowledgeBasesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py index 68e0a381f1b2..ea752c961ac2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> ParticipantsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1880,7 +1880,7 @@ async def sample_compile_suggestion(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1906,8 +1906,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1916,7 +1920,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1924,7 +1928,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1935,7 +1939,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1961,8 +1965,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1971,7 +1979,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1979,7 +1987,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1990,7 +1998,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2019,8 +2027,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2029,7 +2041,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2037,7 +2049,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2045,7 +2057,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2071,8 +2083,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2081,7 +2097,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2089,7 +2105,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2100,7 +2116,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2126,8 +2142,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2136,7 +2156,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2144,7 +2164,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py index c3d54ead4803..9f72fefeec53 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py @@ -118,7 +118,7 @@ class ParticipantsClient(metaclass=ParticipantsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -613,7 +617,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -710,7 +714,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -806,7 +810,7 @@ def __init__( self._universe_domain = ParticipantsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2441,7 +2445,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2467,8 +2471,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2477,7 +2485,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2486,7 +2494,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2500,7 +2508,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2526,8 +2534,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2536,7 +2548,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2545,7 +2557,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2559,7 +2571,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2588,8 +2600,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2598,7 +2614,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2606,7 +2622,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2614,7 +2630,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2640,8 +2656,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2650,7 +2670,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2659,7 +2679,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2673,7 +2693,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2699,8 +2719,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2709,7 +2733,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2718,7 +2742,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/README.rst index 797199a35f26..93cb8a8c5845 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ParticipantsTransport` is the ABC for all transports. -- public child `ParticipantsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ParticipantsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseParticipantsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ParticipantsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ParticipantsTransport`` is the ABC for all transports. + +- public child ``ParticipantsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ParticipantsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseParticipantsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ParticipantsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py index 133e5770f167..909eec1506d0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py index 9d61cd261c26..38e837b20a4b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py index 5d730ecd0bd9..2ea8af056ac1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py index 91e6485bb5fc..59a1a04f8da4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py @@ -908,6 +908,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ParticipantsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/async_client.py index eb895a0444f0..1c48b6fb5b57 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> PhoneNumbersTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -795,7 +795,7 @@ async def sample_undelete_phone_number(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -821,8 +821,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -831,7 +835,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -839,7 +843,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -850,7 +854,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -876,8 +880,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -886,7 +894,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -894,7 +902,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -905,7 +913,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -934,8 +942,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -944,7 +956,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -952,7 +964,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -960,7 +972,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -986,8 +998,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -996,7 +1012,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1004,7 +1020,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1015,7 +1031,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1041,8 +1057,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1051,7 +1071,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1059,7 +1079,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/client.py index 4f3b25cc49c0..fa5f32da9a9f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/client.py @@ -116,7 +116,7 @@ class PhoneNumbersClient(metaclass=PhoneNumbersClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -438,7 +442,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -535,7 +539,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -631,7 +635,7 @@ def __init__( self._universe_domain = PhoneNumbersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1224,7 +1228,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1250,8 +1254,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1260,7 +1268,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1269,7 +1277,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1283,7 +1291,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1309,8 +1317,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1319,7 +1331,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1328,7 +1340,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1342,7 +1354,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1371,8 +1383,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1381,7 +1397,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1389,7 +1405,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1397,7 +1413,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1423,8 +1439,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1453,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1442,7 +1462,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1456,7 +1476,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1482,8 +1502,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1492,7 +1516,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1501,7 +1525,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/README.rst index 73e2d97fed8b..0475d80415d3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PhoneNumbersTransport` is the ABC for all transports. -- public child `PhoneNumbersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PhoneNumbersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePhoneNumbersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PhoneNumbersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PhoneNumbersTransport`` is the ABC for all transports. + +- public child ``PhoneNumbersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PhoneNumbersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePhoneNumbersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PhoneNumbersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/base.py index 4ba3e6038045..e0437fa62d9f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc.py index 9016bfe3cd16..5bc7c2add3c9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc_asyncio.py index ab92c6835756..6d328ff55b6c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/rest.py index 104b7d953592..44f7fd11a4e3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/phone_numbers/transports/rest.py @@ -499,6 +499,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PhoneNumbersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py index 4c60d247eac9..126c268f77d8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SessionEntityTypesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -994,7 +994,7 @@ async def sample_delete_session_entity_type(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1020,8 +1020,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1030,7 +1034,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1038,7 +1042,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1049,7 +1053,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1075,8 +1079,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1085,7 +1093,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1093,7 +1101,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1104,7 +1112,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1133,8 +1141,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1143,7 +1155,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1151,7 +1163,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1159,7 +1171,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1185,8 +1197,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1195,7 +1211,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1203,7 +1219,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1214,7 +1230,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1240,8 +1256,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1250,7 +1270,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1258,7 +1278,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py index 22e0ff7895c6..c0796d6a74ed 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py @@ -118,7 +118,7 @@ class SessionEntityTypesClient(metaclass=SessionEntityTypesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -640,7 +644,7 @@ def __init__( self._universe_domain = SessionEntityTypesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1425,7 +1429,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1451,8 +1455,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1461,7 +1469,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1470,7 +1478,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1484,7 +1492,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1510,8 +1518,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1520,7 +1532,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1529,7 +1541,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1543,7 +1555,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1572,8 +1584,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1582,7 +1598,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1590,7 +1606,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1598,7 +1614,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1624,8 +1640,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1634,7 +1654,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1643,7 +1663,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1657,7 +1677,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1683,8 +1703,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1693,7 +1717,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1702,7 +1726,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/README.rst index fa50039837f6..edbabf709074 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionEntityTypesTransport` is the ABC for all transports. -- public child `SessionEntityTypesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionEntityTypesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionEntityTypesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionEntityTypesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionEntityTypesTransport`` is the ABC for all transports. + +- public child ``SessionEntityTypesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionEntityTypesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionEntityTypesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionEntityTypesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py index 75a0fd748891..0437878f6d46 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py index 8d0565e3cdde..f31964bf0004 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py index ae69d0cb8e0b..d9e692885194 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py index 842a883e0f0e..3a16cc1d5ab7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py @@ -533,6 +533,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionEntityTypesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py index b48cc2cc815f..d8448dc4a8c9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SessionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +644,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -670,8 +670,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -680,7 +684,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -688,7 +692,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -699,7 +703,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -725,8 +729,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -735,7 +743,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -743,7 +751,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -754,7 +762,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -783,8 +791,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -793,7 +805,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -801,7 +813,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -809,7 +821,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -835,8 +847,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -845,7 +861,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -853,7 +869,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -864,7 +880,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -890,8 +906,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -900,7 +920,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -908,7 +928,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py index 36775457ebf9..ec093ed01662 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py @@ -119,7 +119,7 @@ class SessionsClient(metaclass=SessionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -546,7 +550,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -643,7 +647,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -739,7 +743,7 @@ def __init__( self._universe_domain = SessionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1176,7 +1180,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1202,8 +1206,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1212,7 +1220,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1221,7 +1229,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1235,7 +1243,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1261,8 +1269,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1271,7 +1283,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1280,7 +1292,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1294,7 +1306,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,8 +1335,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1333,7 +1349,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1341,7 +1357,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1349,7 +1365,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1375,8 +1391,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1385,7 +1405,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1394,7 +1414,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1408,7 +1428,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1434,8 +1454,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1444,7 +1468,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1453,7 +1477,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/README.rst index ff5ae65346f4..bff74be61084 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionsTransport` is the ABC for all transports. -- public child `SessionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionsTransport`` is the ABC for all transports. + +- public child ``SessionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py index 82d6284c179e..29efac0b53c8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py index 9e2a8640f9de..fdab8a3ae719 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py index ff3b959e5cdb..3fde1e92fea4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py index 723ff1a42cac..20002afde004 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py @@ -332,6 +332,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/async_client.py index a56b78ca73cb..d7c2a2a77dc4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> SipTrunksTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -888,7 +888,7 @@ async def sample_update_sip_trunk(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -914,8 +914,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -924,7 +928,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -932,7 +936,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -943,7 +947,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -969,8 +973,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -979,7 +987,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -987,7 +995,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -998,7 +1006,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1035,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1049,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1057,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1053,7 +1065,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1079,8 +1091,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1089,7 +1105,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1097,7 +1113,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1108,7 +1124,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1134,8 +1150,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1144,7 +1164,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1152,7 +1172,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/client.py index ffe0a08f18c7..a63c56b84221 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/client.py @@ -116,7 +116,7 @@ class SipTrunksClient(metaclass=SipTrunksClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -441,7 +445,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -634,7 +638,7 @@ def __init__( self._universe_domain = SipTrunksClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1319,7 +1323,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1345,8 +1349,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1355,7 +1363,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1364,7 +1372,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1378,7 +1386,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1404,8 +1412,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1414,7 +1426,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1423,7 +1435,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1437,7 +1449,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1466,8 +1478,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1476,7 +1492,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1484,7 +1500,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1492,7 +1508,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1518,8 +1534,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1528,7 +1548,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1537,7 +1557,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1551,7 +1571,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1577,8 +1597,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1587,7 +1611,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1596,7 +1620,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/README.rst index 8351a234d6f9..b7973953c8d4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SipTrunksTransport` is the ABC for all transports. -- public child `SipTrunksGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SipTrunksGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSipTrunksRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SipTrunksRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SipTrunksTransport`` is the ABC for all transports. + +- public child ``SipTrunksGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SipTrunksGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSipTrunksRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SipTrunksRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/base.py index e664572b3a3b..963889c81329 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc.py index a9fd7d9dce90..600ae9bcffd0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc_asyncio.py index 0bd72a806459..22f76bcb0418 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/rest.py index e99bd7634371..a032a2f3fb5b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sip_trunks/transports/rest.py @@ -511,6 +511,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SipTrunksRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/async_client.py index e684f25875e3..786a3c1eb50a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> ToolsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -896,7 +896,7 @@ async def sample_update_tool(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -922,8 +922,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -932,7 +936,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -940,7 +944,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -951,7 +955,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -977,8 +981,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -987,7 +995,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -995,7 +1003,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1006,7 +1014,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1035,8 +1043,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1045,7 +1057,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1053,7 +1065,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1061,7 +1073,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1087,8 +1099,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1097,7 +1113,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1105,7 +1121,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1116,7 +1132,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1142,8 +1158,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1152,7 +1172,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1160,7 +1180,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/client.py index b786e470c0d0..96f089811161 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/client.py @@ -118,7 +118,7 @@ class ToolsClient(metaclass=ToolsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -489,7 +493,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -586,7 +590,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -682,7 +686,7 @@ def __init__( self._universe_domain = ToolsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1375,7 +1379,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1401,8 +1405,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1411,7 +1419,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1420,7 +1428,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1434,7 +1442,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1460,8 +1468,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1470,7 +1482,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1479,7 +1491,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1493,7 +1505,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1522,8 +1534,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1532,7 +1548,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1540,7 +1556,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1548,7 +1564,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1574,8 +1590,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1584,7 +1604,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1593,7 +1613,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1607,7 +1627,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1633,8 +1653,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1643,7 +1667,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1652,7 +1676,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/README.rst index f7b77e1167bf..6a4417039c6e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ToolsTransport` is the ABC for all transports. -- public child `ToolsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ToolsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseToolsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ToolsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ToolsTransport`` is the ABC for all transports. + +- public child ``ToolsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ToolsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseToolsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ToolsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/base.py index f90447c40f18..e2448935bbae 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc.py index 177f1ff25270..77d27cecb33b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc_asyncio.py index bcd55d0cf0ed..4b1ec5ffc72e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/rest.py index 691a1a117571..89dd2217936b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/tools/transports/rest.py @@ -494,6 +494,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ToolsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py index 84924caec920..4ddfdb1a894d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> VersionsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -951,7 +951,7 @@ async def sample_delete_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -977,8 +977,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -987,7 +991,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -995,7 +999,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1006,7 +1010,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1032,8 +1036,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1042,7 +1050,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1050,7 +1058,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1061,7 +1069,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1090,8 +1098,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1100,7 +1112,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1108,7 +1120,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1116,7 +1128,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1142,8 +1154,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1152,7 +1168,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1160,7 +1176,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1171,7 +1187,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1197,8 +1213,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1207,7 +1227,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1215,7 +1235,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py index 95a3888be47e..26092ac7630b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py @@ -117,7 +117,7 @@ class VersionsClient(metaclass=VersionsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -439,7 +443,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -536,7 +540,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -632,7 +636,7 @@ def __init__( self._universe_domain = VersionsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1381,7 +1385,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1407,8 +1411,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1417,7 +1425,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1426,7 +1434,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1440,7 +1448,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1466,8 +1474,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1476,7 +1488,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1485,7 +1497,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1499,7 +1511,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1528,8 +1540,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1538,7 +1554,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1546,7 +1562,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1554,7 +1570,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1580,8 +1596,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1590,7 +1610,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1599,7 +1619,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1613,7 +1633,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1639,8 +1659,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1649,7 +1673,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1658,7 +1682,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/README.rst b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/README.rst index ac30fdf3d846..f820acfcbfa3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/README.rst +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`VersionsTransport` is the ABC for all transports. -- public child `VersionsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `VersionsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseVersionsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `VersionsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``VersionsTransport`` is the ABC for all transports. + +- public child ``VersionsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``VersionsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseVersionsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``VersionsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py index 274d7d9ee4ec..ca78ff295fd0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py index 049b4800c80b..dc6c99dabff0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py index 7ed4750c345c..3105094d98c4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py index 941d499f1a5c..b37558987ee9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py @@ -503,6 +503,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[VersionsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 242e1dbdb2c3..8d1c92ebc531 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dialogflow/setup.py b/packages/google-cloud-dialogflow/setup.py index 8f64de322239..2324a79805db 100644 --- a/packages/google-cloud-dialogflow/setup.py +++ b/packages/google-cloud-dialogflow/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dialogflow" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.7.txt b/packages/google-cloud-dialogflow/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-dialogflow/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.8.txt b/packages/google-cloud-dialogflow/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-dialogflow/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.9.txt b/packages/google-cloud-dialogflow/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-dialogflow/testing/constraints-3.9.txt +++ b/packages/google-cloud-dialogflow/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py index b04b95ad3217..226d67de276e 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AgentsClient._get_default_mtls_endpoint(None) is None assert AgentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AgentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AgentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1222,11 +1224,13 @@ def test_agents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6281,8 +6285,9 @@ def test_get_agent_rest_bad_request(request_type=agent.GetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6367,17 +6372,15 @@ def test_get_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_get_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_get_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6426,8 +6429,9 @@ def test_set_agent_rest_bad_request(request_type=gcd_agent.SetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6596,17 +6600,15 @@ def test_set_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_set_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_set_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_set_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_set_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_set_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_set_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6655,8 +6657,9 @@ def test_delete_agent_rest_bad_request(request_type=agent.DeleteAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6711,13 +6714,11 @@ def test_delete_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "pre_delete_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "pre_delete_agent") as pre, + ): pre.assert_not_called() pb_message = agent.DeleteAgentRequest.pb(agent.DeleteAgentRequest()) transcode.return_value = { @@ -6758,8 +6759,9 @@ def test_search_agents_rest_bad_request(request_type=agent.SearchAgentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6820,17 +6822,17 @@ def test_search_agents_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_search_agents" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_search_agents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_search_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_search_agents" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_search_agents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_search_agents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6879,8 +6881,9 @@ def test_train_agent_rest_bad_request(request_type=agent.TrainAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6935,19 +6938,16 @@ def test_train_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_train_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_train_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_train_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AgentsRestInterceptor, "post_train_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_train_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_train_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6996,8 +6996,9 @@ def test_export_agent_rest_bad_request(request_type=agent.ExportAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7052,19 +7053,18 @@ def test_export_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_export_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_export_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7113,8 +7113,9 @@ def test_import_agent_rest_bad_request(request_type=agent.ImportAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7169,19 +7170,18 @@ def test_import_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_import_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_import_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_import_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_import_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_import_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_import_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7230,8 +7230,9 @@ def test_restore_agent_rest_bad_request(request_type=agent.RestoreAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7286,19 +7287,18 @@ def test_restore_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_restore_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_restore_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7349,8 +7349,9 @@ def test_get_validation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7408,17 +7409,19 @@ def test_get_validation_result_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_validation_result" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_validation_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_validation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_validation_result" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_validation_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_get_validation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7473,8 +7476,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7533,8 +7537,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7595,8 +7600,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7657,8 +7663,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7717,8 +7724,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8043,11 +8051,14 @@ def test_agents_base_transport(): def test_agents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport( @@ -8067,9 +8078,12 @@ def test_agents_base_transport_with_credentials_file(): def test_agents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport() @@ -8147,11 +8161,12 @@ def test_agents_transport_auth_gdch_credentials(transport_class): def test_agents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8758,6 +8773,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8903,6 +8950,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9048,6 +9129,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9193,6 +9308,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9334,6 +9483,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py index 61f770dac5ff..eb4d7518a5d8 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AnswerRecordsClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( AnswerRecordsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AnswerRecordsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1291,11 +1296,13 @@ def test_answer_records_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2909,8 +2916,9 @@ def test_list_answer_records_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2973,18 +2981,20 @@ def test_list_answer_records_rest_interceptors(null_interceptor): ) client = AnswerRecordsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "post_list_answer_records" - ) as post, mock.patch.object( - transports.AnswerRecordsRestInterceptor, - "post_list_answer_records_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "pre_list_answer_records" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "post_list_answer_records" + ) as post, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, + "post_list_answer_records_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "pre_list_answer_records" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3042,8 +3052,9 @@ def test_update_answer_record_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3508,18 +3519,20 @@ def test_update_answer_record_rest_interceptors(null_interceptor): ) client = AnswerRecordsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "post_update_answer_record" - ) as post, mock.patch.object( - transports.AnswerRecordsRestInterceptor, - "post_update_answer_record_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "pre_update_answer_record" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "post_update_answer_record" + ) as post, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, + "post_update_answer_record_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "pre_update_answer_record" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3574,8 +3587,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3634,8 +3648,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3696,8 +3711,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3758,8 +3774,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3818,8 +3835,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3977,11 +3995,14 @@ def test_answer_records_base_transport(): def test_answer_records_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnswerRecordsTransport( @@ -4001,9 +4022,12 @@ def test_answer_records_base_transport_with_credentials_file(): def test_answer_records_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnswerRecordsTransport() @@ -4081,11 +4105,12 @@ def test_answer_records_transport_auth_gdch_credentials(transport_class): def test_answer_records_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4724,6 +4749,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4869,6 +4926,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5014,6 +5105,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5159,6 +5284,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5300,6 +5459,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py index 0faf1b5f2f3c..22965bfdf6c1 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContextsClient._get_default_mtls_endpoint(None) is None assert ContextsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ContextsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ContextsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_contexts_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4976,8 +4980,9 @@ def test_list_contexts_rest_bad_request(request_type=context.ListContextsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5038,17 +5043,19 @@ def test_list_contexts_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_list_contexts" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_list_contexts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_list_contexts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_list_contexts" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_list_contexts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_list_contexts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5099,8 +5106,9 @@ def test_get_context_rest_bad_request(request_type=context.GetContextRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5163,17 +5171,17 @@ def test_get_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_get_context" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_get_context_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_get_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_get_context" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_get_context_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ContextsRestInterceptor, "pre_get_context") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5222,8 +5230,9 @@ def test_create_context_rest_bad_request(request_type=gcd_context.CreateContextR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5358,17 +5367,19 @@ def test_create_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_create_context" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_create_context_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_create_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_create_context" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_create_context_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_create_context" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5421,8 +5432,9 @@ def test_update_context_rest_bad_request(request_type=gcd_context.UpdateContextR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5559,17 +5571,19 @@ def test_update_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_update_context" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_update_context_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_update_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_update_context" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_update_context_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_update_context" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5620,8 +5634,9 @@ def test_delete_context_rest_bad_request(request_type=context.DeleteContextReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5676,13 +5691,13 @@ def test_delete_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "pre_delete_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_delete_context" + ) as pre, + ): pre.assert_not_called() pb_message = context.DeleteContextRequest.pb(context.DeleteContextRequest()) transcode.return_value = { @@ -5725,8 +5740,9 @@ def test_delete_all_contexts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5781,13 +5797,13 @@ def test_delete_all_contexts_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "pre_delete_all_contexts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_delete_all_contexts" + ) as pre, + ): pre.assert_not_called() pb_message = context.DeleteAllContextsRequest.pb( context.DeleteAllContextsRequest() @@ -5832,8 +5848,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5892,8 +5909,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5954,8 +5972,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6016,8 +6035,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6076,8 +6096,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6317,11 +6338,14 @@ def test_contexts_base_transport(): def test_contexts_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContextsTransport( @@ -6341,9 +6365,12 @@ def test_contexts_base_transport_with_credentials_file(): def test_contexts_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContextsTransport() @@ -6421,11 +6448,12 @@ def test_contexts_transport_auth_gdch_credentials(transport_class): def test_contexts_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6995,6 +7023,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7140,6 +7200,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7285,6 +7379,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7430,6 +7558,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7571,6 +7733,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py index 4dc1cfe2be71..e46f3dc5315a 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationDatasetsClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): ConversationDatasetsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationDatasetsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1351,11 +1356,13 @@ def test_conversation_datasets_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4631,8 +4638,9 @@ def test_create_conversation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4771,22 +4779,23 @@ def test_create_conversation_dataset_rest_interceptors(null_interceptor): ) client = ConversationDatasetsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_create_conversation_dataset", - ) as post, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_create_conversation_dataset_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "pre_create_conversation_dataset", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_create_conversation_dataset", + ) as post, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_create_conversation_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "pre_create_conversation_dataset", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4839,8 +4848,9 @@ def test_get_conversation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4913,18 +4923,22 @@ def test_get_conversation_dataset_rest_interceptors(null_interceptor): ) client = ConversationDatasetsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, "post_get_conversation_dataset" - ) as post, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_get_conversation_dataset_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, "pre_get_conversation_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_get_conversation_dataset", + ) as post, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_get_conversation_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "pre_get_conversation_dataset", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4982,8 +4996,9 @@ def test_list_conversation_datasets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5048,19 +5063,22 @@ def test_list_conversation_datasets_rest_interceptors(null_interceptor): ) client = ConversationDatasetsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_list_conversation_datasets", - ) as post, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_list_conversation_datasets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, "pre_list_conversation_datasets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_list_conversation_datasets", + ) as post, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_list_conversation_datasets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "pre_list_conversation_datasets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5120,8 +5138,9 @@ def test_delete_conversation_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5180,22 +5199,23 @@ def test_delete_conversation_dataset_rest_interceptors(null_interceptor): ) client = ConversationDatasetsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_delete_conversation_dataset", - ) as post, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_delete_conversation_dataset_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "pre_delete_conversation_dataset", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_delete_conversation_dataset", + ) as post, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_delete_conversation_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "pre_delete_conversation_dataset", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5248,8 +5268,9 @@ def test_import_conversation_data_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5306,20 +5327,23 @@ def test_import_conversation_data_rest_interceptors(null_interceptor): ) client = ConversationDatasetsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationDatasetsRestInterceptor, "post_import_conversation_data" - ) as post, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, - "post_import_conversation_data_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationDatasetsRestInterceptor, "pre_import_conversation_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_import_conversation_data", + ) as post, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "post_import_conversation_data_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationDatasetsRestInterceptor, + "pre_import_conversation_data", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5372,8 +5396,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5432,8 +5457,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5494,8 +5520,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5556,8 +5583,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5616,8 +5644,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5866,11 +5895,14 @@ def test_conversation_datasets_base_transport(): def test_conversation_datasets_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.conversation_datasets.transports.ConversationDatasetsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.conversation_datasets.transports.ConversationDatasetsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationDatasetsTransport( @@ -5890,9 +5922,12 @@ def test_conversation_datasets_base_transport_with_credentials_file(): def test_conversation_datasets_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.conversation_datasets.transports.ConversationDatasetsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.conversation_datasets.transports.ConversationDatasetsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationDatasetsTransport() @@ -5970,11 +6005,12 @@ def test_conversation_datasets_transport_auth_gdch_credentials(transport_class): def test_conversation_datasets_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6590,6 +6626,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationDatasetsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationDatasetsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationDatasetsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6735,6 +6803,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationDatasetsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationDatasetsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationDatasetsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6880,6 +6982,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationDatasetsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationDatasetsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationDatasetsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7025,6 +7161,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationDatasetsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationDatasetsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationDatasetsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7168,6 +7338,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationDatasetsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationDatasetsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationDatasetsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py index 5f0f4e39167d..b8377d924895 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationModelsClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): ConversationModelsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationModelsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1333,11 +1338,13 @@ def test_conversation_models_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7128,8 +7135,9 @@ def test_create_conversation_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7267,20 +7275,23 @@ def test_create_conversation_model_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationModelsRestInterceptor, "post_create_conversation_model" - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_create_conversation_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, "pre_create_conversation_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_create_conversation_model", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_create_conversation_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_create_conversation_model", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7333,8 +7344,9 @@ def test_get_conversation_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7407,18 +7419,20 @@ def test_get_conversation_model_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationModelsRestInterceptor, "post_get_conversation_model" - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_get_conversation_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, "pre_get_conversation_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationModelsRestInterceptor, "post_get_conversation_model" + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_get_conversation_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, "pre_get_conversation_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7476,8 +7490,9 @@ def test_list_conversation_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7542,18 +7557,21 @@ def test_list_conversation_models_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationModelsRestInterceptor, "post_list_conversation_models" - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_list_conversation_models_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, "pre_list_conversation_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_list_conversation_models", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_list_conversation_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, "pre_list_conversation_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7611,8 +7629,9 @@ def test_delete_conversation_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7669,20 +7688,23 @@ def test_delete_conversation_model_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationModelsRestInterceptor, "post_delete_conversation_model" - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_delete_conversation_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, "pre_delete_conversation_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_delete_conversation_model", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_delete_conversation_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_delete_conversation_model", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7735,8 +7757,9 @@ def test_deploy_conversation_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7793,20 +7816,23 @@ def test_deploy_conversation_model_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationModelsRestInterceptor, "post_deploy_conversation_model" - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_deploy_conversation_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, "pre_deploy_conversation_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_deploy_conversation_model", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_deploy_conversation_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_deploy_conversation_model", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7859,8 +7885,9 @@ def test_undeploy_conversation_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7917,20 +7944,23 @@ def test_undeploy_conversation_model_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationModelsRestInterceptor, "post_undeploy_conversation_model" - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_undeploy_conversation_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, "pre_undeploy_conversation_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_undeploy_conversation_model", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_undeploy_conversation_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_undeploy_conversation_model", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7985,8 +8015,9 @@ def test_get_conversation_model_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8055,20 +8086,22 @@ def test_get_conversation_model_evaluation_rest_interceptors(null_interceptor): ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_get_conversation_model_evaluation", - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_get_conversation_model_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "pre_get_conversation_model_evaluation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_get_conversation_model_evaluation", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_get_conversation_model_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_get_conversation_model_evaluation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8126,8 +8159,9 @@ def test_list_conversation_model_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8192,20 +8226,22 @@ def test_list_conversation_model_evaluations_rest_interceptors(null_interceptor) ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_list_conversation_model_evaluations", - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_list_conversation_model_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "pre_list_conversation_model_evaluations", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_list_conversation_model_evaluations", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_list_conversation_model_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_list_conversation_model_evaluations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8269,8 +8305,9 @@ def test_create_conversation_model_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8329,22 +8366,23 @@ def test_create_conversation_model_evaluation_rest_interceptors(null_interceptor ) client = ConversationModelsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_create_conversation_model_evaluation", - ) as post, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "post_create_conversation_model_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationModelsRestInterceptor, - "pre_create_conversation_model_evaluation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_create_conversation_model_evaluation", + ) as post, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "post_create_conversation_model_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationModelsRestInterceptor, + "pre_create_conversation_model_evaluation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8397,8 +8435,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8457,8 +8496,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8519,8 +8559,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8581,8 +8622,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8641,8 +8683,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8983,11 +9026,14 @@ def test_conversation_models_base_transport(): def test_conversation_models_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.conversation_models.transports.ConversationModelsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.conversation_models.transports.ConversationModelsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationModelsTransport( @@ -9007,9 +9053,12 @@ def test_conversation_models_base_transport_with_credentials_file(): def test_conversation_models_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.conversation_models.transports.ConversationModelsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.conversation_models.transports.ConversationModelsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationModelsTransport() @@ -9087,11 +9136,12 @@ def test_conversation_models_transport_auth_gdch_credentials(transport_class): def test_conversation_models_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9801,6 +9851,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationModelsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationModelsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationModelsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9946,6 +10028,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationModelsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationModelsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationModelsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10091,6 +10207,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationModelsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationModelsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationModelsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10236,6 +10386,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationModelsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationModelsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationModelsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10377,6 +10561,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationModelsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationModelsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationModelsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py index ba380bde30a7..5943fbe7b2a1 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationProfilesClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): ConversationProfilesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationProfilesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1357,11 +1362,13 @@ def test_conversation_profiles_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6073,8 +6080,9 @@ def test_list_conversation_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6139,19 +6147,22 @@ def test_list_conversation_profiles_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_list_conversation_profiles", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_list_conversation_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, "pre_list_conversation_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_list_conversation_profiles", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_list_conversation_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_list_conversation_profiles", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6209,8 +6220,9 @@ def test_get_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6281,18 +6293,22 @@ def test_get_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, "post_get_conversation_profile" - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_get_conversation_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, "pre_get_conversation_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_get_conversation_profile", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_get_conversation_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_get_conversation_profile", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6350,8 +6366,9 @@ def test_create_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6611,20 +6628,22 @@ def test_create_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_create_conversation_profile", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_create_conversation_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_create_conversation_profile", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_create_conversation_profile", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_create_conversation_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_create_conversation_profile", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6686,8 +6705,9 @@ def test_update_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6951,20 +6971,22 @@ def test_update_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_update_conversation_profile", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_update_conversation_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_update_conversation_profile", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_update_conversation_profile", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_update_conversation_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_update_conversation_profile", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7022,8 +7044,9 @@ def test_delete_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7080,14 +7103,14 @@ def test_delete_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_delete_conversation_profile", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_delete_conversation_profile", + ) as pre, + ): pre.assert_not_called() pb_message = conversation_profile.DeleteConversationProfileRequest.pb( conversation_profile.DeleteConversationProfileRequest() @@ -7134,8 +7157,9 @@ def test_set_suggestion_feature_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7194,22 +7218,23 @@ def test_set_suggestion_feature_config_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_set_suggestion_feature_config", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_set_suggestion_feature_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_set_suggestion_feature_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_set_suggestion_feature_config", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_set_suggestion_feature_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_set_suggestion_feature_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7264,8 +7289,9 @@ def test_clear_suggestion_feature_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7324,22 +7350,23 @@ def test_clear_suggestion_feature_config_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_clear_suggestion_feature_config", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_clear_suggestion_feature_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_clear_suggestion_feature_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_clear_suggestion_feature_config", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_clear_suggestion_feature_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_clear_suggestion_feature_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7392,8 +7419,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7452,8 +7480,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7514,8 +7543,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7576,8 +7606,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7636,8 +7667,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7932,11 +7964,14 @@ def test_conversation_profiles_base_transport(): def test_conversation_profiles_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationProfilesTransport( @@ -7956,9 +7991,12 @@ def test_conversation_profiles_base_transport_with_credentials_file(): def test_conversation_profiles_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationProfilesTransport() @@ -8036,11 +8074,12 @@ def test_conversation_profiles_transport_auth_gdch_credentials(transport_class): def test_conversation_profiles_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8836,6 +8875,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8981,6 +9052,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9126,6 +9231,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9271,6 +9410,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9414,6 +9587,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py index eeaf2869918b..861494a5c48b 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( ConversationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1291,11 +1296,13 @@ def test_conversations_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8095,8 +8102,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8256,18 +8264,20 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_create_conversation" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_create_conversation" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_create_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8322,8 +8332,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8386,17 +8397,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_conversations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8454,8 +8468,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8529,17 +8544,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_get_conversation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8592,8 +8610,9 @@ def test_complete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8667,18 +8686,20 @@ def test_complete_conversation_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_complete_conversation" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_complete_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_complete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_complete_conversation" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_complete_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_complete_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8733,8 +8754,9 @@ def test_ingest_context_references_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8796,18 +8818,20 @@ def test_ingest_context_references_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_ingest_context_references" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_ingest_context_references_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_ingest_context_references" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_ingest_context_references" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_ingest_context_references_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_ingest_context_references" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8863,8 +8887,9 @@ def test_list_messages_rest_bad_request(request_type=conversation.ListMessagesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8927,17 +8952,19 @@ def test_list_messages_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_messages" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_messages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_list_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_list_messages" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_list_messages_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_list_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8992,8 +9019,9 @@ def test_suggest_conversation_summary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9060,18 +9088,20 @@ def test_suggest_conversation_summary_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_suggest_conversation_summary" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_suggest_conversation_summary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_suggest_conversation_summary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_suggest_conversation_summary" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_suggest_conversation_summary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_suggest_conversation_summary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9129,8 +9159,9 @@ def test_generate_stateless_summary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9195,18 +9226,20 @@ def test_generate_stateless_summary_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_generate_stateless_summary" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_generate_stateless_summary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_generate_stateless_summary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_generate_stateless_summary" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_stateless_summary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_generate_stateless_summary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9264,8 +9297,9 @@ def test_generate_stateless_suggestion_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9325,18 +9359,21 @@ def test_generate_stateless_suggestion_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_generate_stateless_suggestion" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_generate_stateless_suggestion_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_generate_stateless_suggestion" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_stateless_suggestion", + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_stateless_suggestion_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_generate_stateless_suggestion" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9394,8 +9431,9 @@ def test_search_knowledge_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9458,17 +9496,20 @@ def test_search_knowledge_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_search_knowledge" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_search_knowledge_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_search_knowledge" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_search_knowledge" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_search_knowledge_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_search_knowledge" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9526,8 +9567,9 @@ def test_generate_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9590,18 +9632,20 @@ def test_generate_suggestions_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_generate_suggestions" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_generate_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_generate_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_generate_suggestions" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_generate_suggestions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9659,8 +9703,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9719,8 +9764,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9781,8 +9827,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9843,8 +9890,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9903,8 +9951,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10263,11 +10312,14 @@ def test_conversations_base_transport(): def test_conversations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationsTransport( @@ -10287,9 +10339,12 @@ def test_conversations_base_transport_with_credentials_file(): def test_conversations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationsTransport() @@ -10367,11 +10422,12 @@ def test_conversations_transport_auth_gdch_credentials(transport_class): def test_conversations_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11272,6 +11328,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11417,6 +11505,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11562,6 +11684,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11707,6 +11863,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11848,6 +12038,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py index 5f928187b9ab..2ef271e07419 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentsClient._get_default_mtls_endpoint(None) is None assert DocumentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DocumentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DocumentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1247,11 +1251,13 @@ def test_documents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5891,8 +5897,9 @@ def test_list_documents_rest_bad_request(request_type=document.ListDocumentsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5953,17 +5960,19 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentsRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_list_documents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6014,8 +6023,9 @@ def test_get_document_rest_bad_request(request_type=document.GetDocumentRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6087,17 +6097,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentsRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6148,8 +6160,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6295,19 +6308,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_create_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6360,8 +6374,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6416,19 +6431,20 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_import_documents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6479,8 +6495,9 @@ def test_delete_document_rest_bad_request(request_type=document.DeleteDocumentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6535,19 +6552,20 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_delete_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_delete_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_delete_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_delete_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6602,8 +6620,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6753,19 +6772,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_update_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6816,8 +6836,9 @@ def test_reload_document_rest_bad_request(request_type=document.ReloadDocumentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6872,19 +6893,20 @@ def test_reload_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_reload_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_reload_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_reload_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_reload_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_reload_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_reload_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6933,8 +6955,9 @@ def test_export_document_rest_bad_request(request_type=document.ExportDocumentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6989,19 +7012,20 @@ def test_export_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_export_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_export_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_export_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_export_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_export_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_export_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7052,8 +7076,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7112,8 +7137,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7174,8 +7200,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7236,8 +7263,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7296,8 +7324,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7599,11 +7628,14 @@ def test_documents_base_transport(): def test_documents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentsTransport( @@ -7623,9 +7655,12 @@ def test_documents_base_transport_with_credentials_file(): def test_documents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentsTransport() @@ -7703,11 +7738,12 @@ def test_documents_transport_auth_gdch_credentials(transport_class): def test_documents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8317,6 +8353,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8462,6 +8530,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8607,6 +8709,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8752,6 +8888,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8893,6 +9063,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_encryption_spec_service.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_encryption_spec_service.py index e816bb41811b..6c03094ff655 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_encryption_spec_service.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_encryption_spec_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EncryptionSpecServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): EncryptionSpecServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EncryptionSpecServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1348,11 +1353,13 @@ def test_encryption_spec_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2671,8 +2678,9 @@ def test_get_encryption_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2737,18 +2745,20 @@ def test_get_encryption_spec_rest_interceptors(null_interceptor): ) client = EncryptionSpecServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, "post_get_encryption_spec" - ) as post, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "post_get_encryption_spec_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, "pre_get_encryption_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, "post_get_encryption_spec" + ) as post, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "post_get_encryption_spec_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, "pre_get_encryption_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2805,8 +2815,9 @@ def test_initialize_encryption_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2865,22 +2876,23 @@ def test_initialize_encryption_spec_rest_interceptors(null_interceptor): ) client = EncryptionSpecServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "post_initialize_encryption_spec", - ) as post, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "post_initialize_encryption_spec_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "pre_initialize_encryption_spec", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "post_initialize_encryption_spec", + ) as post, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "post_initialize_encryption_spec_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "pre_initialize_encryption_spec", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2933,8 +2945,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2993,8 +3006,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3055,8 +3069,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3117,8 +3132,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3177,8 +3193,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3358,11 +3375,14 @@ def test_encryption_spec_service_base_transport(): def test_encryption_spec_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EncryptionSpecServiceTransport( @@ -3382,9 +3402,12 @@ def test_encryption_spec_service_base_transport_with_credentials_file(): def test_encryption_spec_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EncryptionSpecServiceTransport() @@ -3464,11 +3487,12 @@ def test_encryption_spec_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4070,6 +4094,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4215,6 +4271,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4360,6 +4450,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4505,6 +4629,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4648,6 +4806,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py index fb0bcb627662..571a34814aa0 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EntityTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1253,11 +1257,13 @@ def test_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7585,8 +7591,9 @@ def test_list_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7649,17 +7656,20 @@ def test_list_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_list_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_list_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_list_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_list_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7717,8 +7727,9 @@ def test_get_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7792,17 +7803,19 @@ def test_get_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_get_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_get_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7855,8 +7868,9 @@ def test_create_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8007,17 +8021,20 @@ def test_create_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_create_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_create_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_create_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_create_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8072,8 +8089,9 @@ def test_update_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8226,17 +8244,20 @@ def test_update_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_update_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_update_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_update_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_update_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8289,8 +8310,9 @@ def test_delete_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8347,13 +8369,13 @@ def test_delete_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_delete_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_delete_entity_type" + ) as pre, + ): pre.assert_not_called() pb_message = entity_type.DeleteEntityTypeRequest.pb( entity_type.DeleteEntityTypeRequest() @@ -8398,8 +8420,9 @@ def test_batch_update_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8456,20 +8479,21 @@ def test_batch_update_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_update_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_update_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_update_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_update_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_update_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_update_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8522,8 +8546,9 @@ def test_batch_delete_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8580,20 +8605,21 @@ def test_batch_delete_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_delete_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_delete_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_delete_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_delete_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_delete_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_delete_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8646,8 +8672,9 @@ def test_batch_create_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8704,20 +8731,21 @@ def test_batch_create_entities_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_create_entities" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_create_entities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_create_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_create_entities" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_create_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_create_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8770,8 +8798,9 @@ def test_batch_update_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8828,20 +8857,21 @@ def test_batch_update_entities_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_update_entities" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_update_entities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_update_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_update_entities" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_update_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_update_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8894,8 +8924,9 @@ def test_batch_delete_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8952,20 +8983,21 @@ def test_batch_delete_entities_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_delete_entities" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_delete_entities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_delete_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_delete_entities" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_delete_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_delete_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9018,8 +9050,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9078,8 +9111,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9140,8 +9174,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9202,8 +9237,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9262,8 +9298,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9625,11 +9662,14 @@ def test_entity_types_base_transport(): def test_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport( @@ -9649,9 +9689,12 @@ def test_entity_types_base_transport_with_credentials_file(): def test_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport() @@ -9729,11 +9772,12 @@ def test_entity_types_transport_auth_gdch_credentials(transport_class): def test_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10346,6 +10390,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10491,6 +10567,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10636,6 +10746,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10781,6 +10925,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10922,6 +11100,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py index 7a7b5e211ec2..674962b5afa8 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EnvironmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EnvironmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EnvironmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1261,11 +1266,13 @@ def test_environments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4770,8 +4777,9 @@ def test_list_environments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4834,17 +4842,20 @@ def test_list_environments_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_list_environments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_list_environments" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_list_environments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_list_environments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4902,8 +4913,9 @@ def test_get_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4972,17 +4984,19 @@ def test_get_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_get_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_get_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5035,8 +5049,9 @@ def test_create_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5198,17 +5213,20 @@ def test_create_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_create_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_create_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_create_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_create_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5263,8 +5281,9 @@ def test_update_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5428,17 +5447,20 @@ def test_update_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_update_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_update_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_update_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_update_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5491,8 +5513,9 @@ def test_delete_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5549,13 +5572,13 @@ def test_delete_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_delete_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_delete_environment" + ) as pre, + ): pre.assert_not_called() pb_message = environment.DeleteEnvironmentRequest.pb( environment.DeleteEnvironmentRequest() @@ -5600,8 +5623,9 @@ def test_get_environment_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5666,18 +5690,20 @@ def test_get_environment_history_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment_history" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, - "post_get_environment_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_get_environment_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment_history" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_get_environment_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_get_environment_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5732,8 +5758,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5792,8 +5819,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5854,8 +5882,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5916,8 +5945,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5976,8 +6006,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6225,11 +6256,14 @@ def test_environments_base_transport(): def test_environments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport( @@ -6249,9 +6283,12 @@ def test_environments_base_transport_with_credentials_file(): def test_environments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport() @@ -6329,11 +6366,12 @@ def test_environments_transport_auth_gdch_credentials(transport_class): def test_environments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6943,6 +6981,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7088,6 +7158,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7233,6 +7337,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7378,6 +7516,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7519,6 +7691,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py index a0829cad8791..da85b5bdd20e 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FulfillmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FulfillmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FulfillmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1260,11 +1265,13 @@ def test_fulfillments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2585,8 +2592,9 @@ def test_get_fulfillment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2653,17 +2661,19 @@ def test_get_fulfillment_rest_interceptors(null_interceptor): ) client = FulfillmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_get_fulfillment" - ) as post, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_get_fulfillment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FulfillmentsRestInterceptor, "pre_get_fulfillment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "post_get_fulfillment" + ) as post, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "post_get_fulfillment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "pre_get_fulfillment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2716,8 +2726,9 @@ def test_update_fulfillment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2864,17 +2875,20 @@ def test_update_fulfillment_rest_interceptors(null_interceptor): ) client = FulfillmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_update_fulfillment" - ) as post, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_update_fulfillment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FulfillmentsRestInterceptor, "pre_update_fulfillment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "post_update_fulfillment" + ) as post, + mock.patch.object( + transports.FulfillmentsRestInterceptor, + "post_update_fulfillment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "pre_update_fulfillment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2929,8 +2943,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2989,8 +3004,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3051,8 +3067,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3113,8 +3130,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3173,8 +3191,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3330,11 +3349,14 @@ def test_fulfillments_base_transport(): def test_fulfillments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FulfillmentsTransport( @@ -3354,9 +3376,12 @@ def test_fulfillments_base_transport_with_credentials_file(): def test_fulfillments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FulfillmentsTransport() @@ -3434,11 +3459,12 @@ def test_fulfillments_transport_auth_gdch_credentials(transport_class): def test_fulfillments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3990,6 +4016,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4135,6 +4193,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4280,6 +4372,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4425,6 +4551,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4566,6 +4726,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generator_evaluations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generator_evaluations.py index 29511caf3f0c..bfd7170a00cc 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generator_evaluations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generator_evaluations.py @@ -138,6 +138,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeneratorEvaluationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -160,6 +161,10 @@ def test__get_default_mtls_endpoint(): GeneratorEvaluationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GeneratorEvaluationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1359,11 +1364,13 @@ def test_generator_evaluations_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4171,8 +4178,9 @@ def test_create_generator_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4535,22 +4543,23 @@ def test_create_generator_evaluation_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_create_generator_evaluation", - ) as post, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_create_generator_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "pre_create_generator_evaluation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_create_generator_evaluation", + ) as post, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_create_generator_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_create_generator_evaluation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4605,8 +4614,9 @@ def test_get_generator_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4677,18 +4687,22 @@ def test_get_generator_evaluation_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, "post_get_generator_evaluation" - ) as post, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_get_generator_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, "pre_get_generator_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_get_generator_evaluation", + ) as post, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_get_generator_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_get_generator_evaluation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4746,8 +4760,9 @@ def test_list_generator_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4812,19 +4827,22 @@ def test_list_generator_evaluations_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_list_generator_evaluations", - ) as post, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_list_generator_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, "pre_list_generator_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_list_generator_evaluations", + ) as post, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_list_generator_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_list_generator_evaluations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4884,8 +4902,9 @@ def test_delete_generator_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4944,14 +4963,14 @@ def test_delete_generator_evaluation_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "pre_delete_generator_evaluation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_delete_generator_evaluation", + ) as pre, + ): pre.assert_not_called() pb_message = generator_evaluation.DeleteGeneratorEvaluationRequest.pb( generator_evaluation.DeleteGeneratorEvaluationRequest() @@ -4996,8 +5015,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5056,8 +5076,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5118,8 +5139,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5180,8 +5202,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5240,8 +5263,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5467,11 +5491,14 @@ def test_generator_evaluations_base_transport(): def test_generator_evaluations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorEvaluationsTransport( @@ -5491,9 +5518,12 @@ def test_generator_evaluations_base_transport_with_credentials_file(): def test_generator_evaluations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorEvaluationsTransport() @@ -5571,11 +5601,12 @@ def test_generator_evaluations_transport_auth_gdch_credentials(transport_class): def test_generator_evaluations_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6243,6 +6274,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6388,6 +6451,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6533,6 +6630,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6678,6 +6809,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6821,6 +6986,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generators.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generators.py index 45b6af44efbb..bd8a0c9ee9fd 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generators.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_generators.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeneratorsClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GeneratorsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + GeneratorsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1249,11 +1253,13 @@ def test_generators_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4513,8 +4519,9 @@ def test_create_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4775,17 +4782,19 @@ def test_create_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_create_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_create_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4836,8 +4845,9 @@ def test_get_generator_rest_bad_request(request_type=generator.GetGeneratorReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4907,17 +4917,19 @@ def test_get_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_get_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_get_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4966,8 +4978,9 @@ def test_list_generators_rest_bad_request(request_type=generator.ListGeneratorsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5030,17 +5043,19 @@ def test_list_generators_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_list_generators" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_list_generators" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5095,8 +5110,9 @@ def test_delete_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5153,13 +5169,13 @@ def test_delete_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_delete_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_delete_generator" + ) as pre, + ): pre.assert_not_called() pb_message = generator.DeleteGeneratorRequest.pb( generator.DeleteGeneratorRequest() @@ -5206,8 +5222,9 @@ def test_update_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5470,17 +5487,19 @@ def test_update_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_update_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_update_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5533,8 +5552,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5593,8 +5613,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5655,8 +5676,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5717,8 +5739,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5777,8 +5800,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5995,11 +6019,14 @@ def test_generators_base_transport(): def test_generators_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport( @@ -6019,9 +6046,12 @@ def test_generators_base_transport_with_credentials_file(): def test_generators_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport() @@ -6099,11 +6129,12 @@ def test_generators_transport_auth_gdch_credentials(transport_class): def test_generators_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6696,6 +6727,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6841,6 +6904,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6986,6 +7083,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7131,6 +7262,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7272,6 +7437,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py index 46bd22e5c0c3..859a584ca92a 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IntentsClient._get_default_mtls_endpoint(None) is None assert IntentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert IntentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IntentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1223,11 +1225,13 @@ def test_intents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5928,8 +5932,9 @@ def test_list_intents_rest_bad_request(request_type=intent.ListIntentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5990,17 +5995,17 @@ def test_list_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_list_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_list_intents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6049,8 +6054,9 @@ def test_get_intent_rest_bad_request(request_type=intent.GetIntentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6141,17 +6147,15 @@ def test_get_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_get_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.IntentsRestInterceptor, "post_get_intent") as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_get_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_get_intent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6200,8 +6204,9 @@ def test_create_intent_rest_bad_request(request_type=gcd_intent.CreateIntentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6525,17 +6530,19 @@ def test_create_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_create_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_create_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6584,8 +6591,9 @@ def test_update_intent_rest_bad_request(request_type=gcd_intent.UpdateIntentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6909,17 +6917,19 @@ def test_update_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_update_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_update_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6968,8 +6978,9 @@ def test_delete_intent_rest_bad_request(request_type=intent.DeleteIntentRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7024,13 +7035,13 @@ def test_delete_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "pre_delete_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_delete_intent" + ) as pre, + ): pre.assert_not_called() pb_message = intent.DeleteIntentRequest.pb(intent.DeleteIntentRequest()) transcode.return_value = { @@ -7073,8 +7084,9 @@ def test_batch_update_intents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7129,19 +7141,20 @@ def test_batch_update_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_update_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_update_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_batch_update_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_update_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_update_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_batch_update_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7194,8 +7207,9 @@ def test_batch_delete_intents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7250,19 +7264,20 @@ def test_batch_delete_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_delete_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_delete_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_batch_delete_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_delete_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_delete_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_batch_delete_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7315,8 +7330,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7375,8 +7391,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7437,8 +7454,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7499,8 +7517,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7559,8 +7578,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7845,11 +7865,14 @@ def test_intents_base_transport(): def test_intents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport( @@ -7869,9 +7892,12 @@ def test_intents_base_transport_with_credentials_file(): def test_intents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport() @@ -7949,11 +7975,12 @@ def test_intents_transport_auth_gdch_credentials(transport_class): def test_intents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8583,6 +8610,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8728,6 +8787,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8873,6 +8966,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9018,6 +9145,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9159,6 +9320,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py index dbe55a239c10..f45a24618811 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert KnowledgeBasesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): assert ( KnowledgeBasesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + KnowledgeBasesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1284,11 +1289,13 @@ def test_knowledge_bases_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4654,8 +4661,9 @@ def test_list_knowledge_bases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4718,18 +4726,20 @@ def test_list_knowledge_bases_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_list_knowledge_bases" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_list_knowledge_bases_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_list_knowledge_bases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_list_knowledge_bases" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_list_knowledge_bases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_list_knowledge_bases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4787,8 +4797,9 @@ def test_get_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4855,18 +4866,20 @@ def test_get_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_get_knowledge_base" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_get_knowledge_base_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_get_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_get_knowledge_base" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_get_knowledge_base_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_get_knowledge_base" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4921,8 +4934,9 @@ def test_create_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5063,18 +5077,20 @@ def test_create_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_create_knowledge_base" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_create_knowledge_base_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_create_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_create_knowledge_base" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_create_knowledge_base_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_create_knowledge_base" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5129,8 +5145,9 @@ def test_delete_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5187,13 +5204,13 @@ def test_delete_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_delete_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_delete_knowledge_base" + ) as pre, + ): pre.assert_not_called() pb_message = knowledge_base.DeleteKnowledgeBaseRequest.pb( knowledge_base.DeleteKnowledgeBaseRequest() @@ -5240,8 +5257,9 @@ def test_update_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5384,18 +5402,20 @@ def test_update_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_update_knowledge_base" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_update_knowledge_base_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_update_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_update_knowledge_base" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_update_knowledge_base_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_update_knowledge_base" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5450,8 +5470,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5510,8 +5531,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5572,8 +5594,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5634,8 +5657,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5694,8 +5718,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5922,11 +5947,14 @@ def test_knowledge_bases_base_transport(): def test_knowledge_bases_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KnowledgeBasesTransport( @@ -5946,9 +5974,12 @@ def test_knowledge_bases_base_transport_with_credentials_file(): def test_knowledge_bases_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KnowledgeBasesTransport() @@ -6026,11 +6057,12 @@ def test_knowledge_bases_transport_auth_gdch_credentials(transport_class): def test_knowledge_bases_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6605,6 +6637,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6750,6 +6814,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6895,6 +6993,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7040,6 +7172,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7181,6 +7347,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py index 7b35daa64b16..962ac7ab2177 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ParticipantsClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ParticipantsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ParticipantsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1271,11 +1276,13 @@ def test_participants_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7072,8 +7079,9 @@ def test_create_participant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7222,17 +7230,20 @@ def test_create_participant_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_create_participant" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_create_participant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_create_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_create_participant" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_create_participant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_create_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7289,8 +7300,9 @@ def test_get_participant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7366,17 +7378,19 @@ def test_get_participant_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_get_participant" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_get_participant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_get_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_get_participant" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_get_participant_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_get_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7429,8 +7443,9 @@ def test_list_participants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7493,17 +7508,20 @@ def test_list_participants_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_list_participants" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_list_participants_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_list_participants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_list_participants" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_list_participants_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_list_participants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7565,8 +7583,9 @@ def test_update_participant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7719,17 +7738,20 @@ def test_update_participant_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_update_participant" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_update_participant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_update_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_update_participant" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_update_participant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_update_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7786,8 +7808,9 @@ def test_analyze_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7852,17 +7875,19 @@ def test_analyze_content_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_analyze_content" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_analyze_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_analyze_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_analyze_content" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_analyze_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_analyze_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7934,8 +7959,9 @@ def test_suggest_articles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8002,17 +8028,20 @@ def test_suggest_articles_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_articles" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_articles_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_articles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_articles" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_articles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_articles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8072,8 +8101,9 @@ def test_suggest_faq_answers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8140,17 +8170,20 @@ def test_suggest_faq_answers_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_faq_answers" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_faq_answers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_faq_answers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_faq_answers" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_faq_answers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_faq_answers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8210,8 +8243,9 @@ def test_suggest_smart_replies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8278,18 +8312,20 @@ def test_suggest_smart_replies_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_smart_replies" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, - "post_suggest_smart_replies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_smart_replies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_smart_replies" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_smart_replies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_smart_replies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8349,8 +8385,9 @@ def test_suggest_knowledge_assist_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8417,18 +8454,20 @@ def test_suggest_knowledge_assist_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_knowledge_assist" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, - "post_suggest_knowledge_assist_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_knowledge_assist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_knowledge_assist" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_knowledge_assist_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_knowledge_assist" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8486,8 +8525,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8546,8 +8586,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8608,8 +8649,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8670,8 +8712,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8730,8 +8773,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9045,11 +9089,14 @@ def test_participants_base_transport(): def test_participants_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ParticipantsTransport( @@ -9069,9 +9116,12 @@ def test_participants_base_transport_with_credentials_file(): def test_participants_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ParticipantsTransport() @@ -9149,11 +9199,12 @@ def test_participants_transport_auth_gdch_credentials(transport_class): def test_participants_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9915,6 +9966,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10060,6 +10143,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10205,6 +10322,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10350,6 +10501,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10491,6 +10676,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py index a2d4c7a4ee15..fd229ea7dfea 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionEntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): SessionEntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionEntityTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1328,11 +1333,13 @@ def test_session_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4751,8 +4758,9 @@ def test_list_session_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4817,18 +4825,22 @@ def test_list_session_entity_types_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_list_session_entity_types" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_list_session_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_list_session_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_list_session_entity_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4888,8 +4900,9 @@ def test_get_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4959,18 +4972,20 @@ def test_get_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_get_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_get_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5028,8 +5043,9 @@ def test_create_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5173,18 +5189,22 @@ def test_create_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_create_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_create_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_create_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_create_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5246,8 +5266,9 @@ def test_update_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5395,18 +5416,22 @@ def test_update_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_update_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_update_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_update_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_update_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5466,8 +5491,9 @@ def test_delete_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5526,13 +5552,14 @@ def test_delete_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_delete_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_delete_session_entity_type", + ) as pre, + ): pre.assert_not_called() pb_message = session_entity_type.DeleteSessionEntityTypeRequest.pb( session_entity_type.DeleteSessionEntityTypeRequest() @@ -5577,8 +5604,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5637,8 +5665,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5699,8 +5728,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5761,8 +5791,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5821,8 +5852,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6049,11 +6081,14 @@ def test_session_entity_types_base_transport(): def test_session_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport( @@ -6073,9 +6108,12 @@ def test_session_entity_types_base_transport_with_credentials_file(): def test_session_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport() @@ -6153,11 +6191,12 @@ def test_session_entity_types_transport_auth_gdch_credentials(transport_class): def test_session_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6741,6 +6780,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6886,6 +6957,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7031,6 +7136,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7176,6 +7315,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7317,6 +7490,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py index d8d2356e4bff..b0a40a1c4e80 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionsClient._get_default_mtls_endpoint(None) is None assert SessionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -147,6 +148,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SessionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert SessionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1236,11 +1238,13 @@ def test_sessions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2190,8 +2194,9 @@ def test_detect_intent_rest_bad_request(request_type=gcd_session.DetectIntentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2254,17 +2259,19 @@ def test_detect_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_detect_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_detect_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2331,8 +2338,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2391,8 +2399,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2453,8 +2462,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2515,8 +2525,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2575,8 +2586,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2710,11 +2722,14 @@ def test_sessions_base_transport(): def test_sessions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport( @@ -2734,9 +2749,12 @@ def test_sessions_base_transport_with_credentials_file(): def test_sessions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport() @@ -2814,11 +2832,12 @@ def test_sessions_transport_auth_gdch_credentials(transport_class): def test_sessions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3476,6 +3495,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3621,6 +3672,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3766,6 +3851,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3911,6 +4030,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4052,6 +4205,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sip_trunks.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sip_trunks.py index 053699d29c68..525c36ae2227 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sip_trunks.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sip_trunks.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SipTrunksClient._get_default_mtls_endpoint(None) is None assert SipTrunksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SipTrunksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SipTrunksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_sip_trunks_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4472,8 +4478,9 @@ def test_create_sip_trunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4621,17 +4628,19 @@ def test_create_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_create_sip_trunk" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_create_sip_trunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_create_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_create_sip_trunk" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_create_sip_trunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_create_sip_trunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4684,8 +4693,9 @@ def test_delete_sip_trunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4740,13 +4750,13 @@ def test_delete_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_delete_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_delete_sip_trunk" + ) as pre, + ): pre.assert_not_called() pb_message = sip_trunk.DeleteSipTrunkRequest.pb( sip_trunk.DeleteSipTrunkRequest() @@ -4789,8 +4799,9 @@ def test_list_sip_trunks_rest_bad_request(request_type=sip_trunk.ListSipTrunksRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4851,17 +4862,19 @@ def test_list_sip_trunks_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_list_sip_trunks" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_list_sip_trunks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_list_sip_trunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_list_sip_trunks" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_list_sip_trunks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_list_sip_trunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4912,8 +4925,9 @@ def test_get_sip_trunk_rest_bad_request(request_type=sip_trunk.GetSipTrunkReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4978,17 +4992,19 @@ def test_get_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_get_sip_trunk" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_get_sip_trunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_get_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_get_sip_trunk" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_get_sip_trunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_get_sip_trunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5041,8 +5057,9 @@ def test_update_sip_trunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5192,17 +5209,19 @@ def test_update_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_update_sip_trunk" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_update_sip_trunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_update_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_update_sip_trunk" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_update_sip_trunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_update_sip_trunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5255,8 +5274,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5315,8 +5335,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5377,8 +5398,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5439,8 +5461,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5499,8 +5522,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5717,11 +5741,14 @@ def test_sip_trunks_base_transport(): def test_sip_trunks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SipTrunksTransport( @@ -5741,9 +5768,12 @@ def test_sip_trunks_base_transport_with_credentials_file(): def test_sip_trunks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SipTrunksTransport() @@ -5821,11 +5851,12 @@ def test_sip_trunks_transport_auth_gdch_credentials(transport_class): def test_sip_trunks_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6392,6 +6423,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6537,6 +6600,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6682,6 +6779,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6827,6 +6958,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6968,6 +7133,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_tools.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_tools.py index a1926875f695..4ebc2d3c9993 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_tools.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_tools.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ToolsClient._get_default_mtls_endpoint(None) is None assert ToolsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ToolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ToolsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1214,11 +1216,13 @@ def test_tools_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4464,8 +4468,9 @@ def test_create_tool_rest_bad_request(request_type=gcd_tool.CreateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4664,17 +4669,15 @@ def test_create_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_create_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_create_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_create_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4723,8 +4726,9 @@ def test_get_tool_rest_bad_request(request_type=tool.GetToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4795,17 +4799,15 @@ def test_get_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_get_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_get_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_get_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4854,8 +4856,9 @@ def test_list_tools_rest_bad_request(request_type=tool.ListToolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4916,17 +4919,15 @@ def test_list_tools_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_list_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_list_tools") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_list_tools") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4975,8 +4976,9 @@ def test_delete_tool_rest_bad_request(request_type=tool.DeleteToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5031,13 +5033,11 @@ def test_delete_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "pre_delete_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "pre_delete_tool") as pre, + ): pre.assert_not_called() pb_message = tool.DeleteToolRequest.pb(tool.DeleteToolRequest()) transcode.return_value = { @@ -5080,8 +5080,9 @@ def test_update_tool_rest_bad_request(request_type=gcd_tool.UpdateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5282,17 +5283,15 @@ def test_update_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_update_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_update_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_update_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_update_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5343,8 +5342,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5403,8 +5403,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5465,8 +5466,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5527,8 +5529,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5587,8 +5590,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5805,11 +5809,14 @@ def test_tools_base_transport(): def test_tools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport( @@ -5829,9 +5836,12 @@ def test_tools_base_transport_with_credentials_file(): def test_tools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport() @@ -5909,11 +5919,12 @@ def test_tools_transport_auth_gdch_credentials(transport_class): def test_tools_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6531,6 +6542,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6676,6 +6719,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6821,6 +6898,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6966,6 +7077,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7107,6 +7252,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py index 8125f77fa6e6..c47c20c84a0e 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VersionsClient._get_default_mtls_endpoint(None) is None assert VersionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert VersionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_versions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4445,8 +4449,9 @@ def test_list_versions_rest_bad_request(request_type=version.ListVersionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4507,17 +4512,19 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4568,8 +4575,9 @@ def test_get_version_rest_bad_request(request_type=version.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4636,17 +4644,17 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VersionsRestInterceptor, "pre_get_version") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4695,8 +4703,9 @@ def test_create_version_rest_bad_request(request_type=gcd_version.CreateVersionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4837,17 +4846,19 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4898,8 +4909,9 @@ def test_update_version_rest_bad_request(request_type=gcd_version.UpdateVersionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5040,17 +5052,19 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5101,8 +5115,9 @@ def test_delete_version_rest_bad_request(request_type=version.DeleteVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5157,13 +5172,13 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() pb_message = version.DeleteVersionRequest.pb(version.DeleteVersionRequest()) transcode.return_value = { @@ -5206,8 +5221,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5266,8 +5282,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5328,8 +5345,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5390,8 +5408,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5450,8 +5469,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5668,11 +5688,14 @@ def test_versions_base_transport(): def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport( @@ -5692,9 +5715,12 @@ def test_versions_base_transport_with_credentials_file(): def test_versions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport() @@ -5772,11 +5798,12 @@ def test_versions_transport_auth_gdch_credentials(transport_class): def test_versions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6340,6 +6367,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6485,6 +6544,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6630,6 +6723,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6775,6 +6902,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6916,6 +7077,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py index e7758593e853..3d77be24d6eb 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AgentsClient._get_default_mtls_endpoint(None) is None assert AgentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AgentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AgentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1222,11 +1224,13 @@ def test_agents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6273,8 +6277,9 @@ def test_get_agent_rest_bad_request(request_type=agent.GetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6359,17 +6364,15 @@ def test_get_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_get_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_get_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6418,8 +6421,9 @@ def test_set_agent_rest_bad_request(request_type=gcd_agent.SetAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6588,17 +6592,15 @@ def test_set_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_set_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_set_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_set_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "post_set_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_set_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_set_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6647,8 +6649,9 @@ def test_delete_agent_rest_bad_request(request_type=agent.DeleteAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6703,13 +6706,11 @@ def test_delete_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "pre_delete_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AgentsRestInterceptor, "pre_delete_agent") as pre, + ): pre.assert_not_called() pb_message = agent.DeleteAgentRequest.pb(agent.DeleteAgentRequest()) transcode.return_value = { @@ -6750,8 +6751,9 @@ def test_search_agents_rest_bad_request(request_type=agent.SearchAgentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6812,17 +6814,17 @@ def test_search_agents_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_search_agents" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_search_agents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_search_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_search_agents" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_search_agents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_search_agents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6871,8 +6873,9 @@ def test_train_agent_rest_bad_request(request_type=agent.TrainAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6927,19 +6930,16 @@ def test_train_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_train_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_train_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_train_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AgentsRestInterceptor, "post_train_agent") as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_train_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_train_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6988,8 +6988,9 @@ def test_export_agent_rest_bad_request(request_type=agent.ExportAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7044,19 +7045,18 @@ def test_export_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_export_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_export_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_export_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_export_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7105,8 +7105,9 @@ def test_import_agent_rest_bad_request(request_type=agent.ImportAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7161,19 +7162,18 @@ def test_import_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_import_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_import_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_import_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_import_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_import_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_import_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7222,8 +7222,9 @@ def test_restore_agent_rest_bad_request(request_type=agent.RestoreAgentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7278,19 +7279,18 @@ def test_restore_agent_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_restore_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_restore_agent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AgentsRestInterceptor, "pre_restore_agent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7341,8 +7341,9 @@ def test_get_validation_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7400,17 +7401,19 @@ def test_get_validation_result_rest_interceptors(null_interceptor): ) client = AgentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_validation_result" - ) as post, mock.patch.object( - transports.AgentsRestInterceptor, "post_get_validation_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AgentsRestInterceptor, "pre_get_validation_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_validation_result" + ) as post, + mock.patch.object( + transports.AgentsRestInterceptor, "post_get_validation_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AgentsRestInterceptor, "pre_get_validation_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7465,8 +7468,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7525,8 +7529,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7587,8 +7592,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7649,8 +7655,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7709,8 +7716,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8035,11 +8043,14 @@ def test_agents_base_transport(): def test_agents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport( @@ -8059,9 +8070,12 @@ def test_agents_base_transport_with_credentials_file(): def test_agents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AgentsTransport() @@ -8139,11 +8153,12 @@ def test_agents_transport_auth_gdch_credentials(transport_class): def test_agents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8750,6 +8765,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8895,6 +8942,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9040,6 +9121,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9185,6 +9300,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9326,6 +9475,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AgentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AgentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AgentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py index 92a0556a5cba..521093b9d3b0 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AnswerRecordsClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( AnswerRecordsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AnswerRecordsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1291,11 +1296,13 @@ def test_answer_records_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3144,8 +3151,9 @@ def test_get_answer_record_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3208,17 +3216,20 @@ def test_get_answer_record_rest_interceptors(null_interceptor): ) client = AnswerRecordsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "post_get_answer_record" - ) as post, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "post_get_answer_record_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "pre_get_answer_record" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "post_get_answer_record" + ) as post, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, + "post_get_answer_record_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "pre_get_answer_record" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3271,8 +3282,9 @@ def test_list_answer_records_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3335,18 +3347,20 @@ def test_list_answer_records_rest_interceptors(null_interceptor): ) client = AnswerRecordsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "post_list_answer_records" - ) as post, mock.patch.object( - transports.AnswerRecordsRestInterceptor, - "post_list_answer_records_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "pre_list_answer_records" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "post_list_answer_records" + ) as post, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, + "post_list_answer_records_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "pre_list_answer_records" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3404,8 +3418,9 @@ def test_update_answer_record_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3927,18 +3942,20 @@ def test_update_answer_record_rest_interceptors(null_interceptor): ) client = AnswerRecordsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "post_update_answer_record" - ) as post, mock.patch.object( - transports.AnswerRecordsRestInterceptor, - "post_update_answer_record_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AnswerRecordsRestInterceptor, "pre_update_answer_record" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "post_update_answer_record" + ) as post, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, + "post_update_answer_record_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AnswerRecordsRestInterceptor, "pre_update_answer_record" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3993,8 +4010,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4053,8 +4071,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4115,8 +4134,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4177,8 +4197,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4237,8 +4258,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4419,11 +4441,14 @@ def test_answer_records_base_transport(): def test_answer_records_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnswerRecordsTransport( @@ -4443,9 +4468,12 @@ def test_answer_records_base_transport_with_credentials_file(): def test_answer_records_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AnswerRecordsTransport() @@ -4523,11 +4551,12 @@ def test_answer_records_transport_auth_gdch_credentials(transport_class): def test_answer_records_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5195,6 +5224,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5340,6 +5401,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5485,6 +5580,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5630,6 +5759,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5771,6 +5934,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AnswerRecordsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AnswerRecordsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AnswerRecordsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py index b30ada46e2f2..447e43a96fe6 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ContextsClient._get_default_mtls_endpoint(None) is None assert ContextsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ContextsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ContextsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_contexts_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4976,8 +4980,9 @@ def test_list_contexts_rest_bad_request(request_type=context.ListContextsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5038,17 +5043,19 @@ def test_list_contexts_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_list_contexts" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_list_contexts_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_list_contexts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_list_contexts" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_list_contexts_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_list_contexts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5099,8 +5106,9 @@ def test_get_context_rest_bad_request(request_type=context.GetContextRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5163,17 +5171,17 @@ def test_get_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_get_context" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_get_context_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_get_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_get_context" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_get_context_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ContextsRestInterceptor, "pre_get_context") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5222,8 +5230,9 @@ def test_create_context_rest_bad_request(request_type=gcd_context.CreateContextR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5358,17 +5367,19 @@ def test_create_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_create_context" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_create_context_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_create_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_create_context" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_create_context_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_create_context" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5421,8 +5432,9 @@ def test_update_context_rest_bad_request(request_type=gcd_context.UpdateContextR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5559,17 +5571,19 @@ def test_update_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "post_update_context" - ) as post, mock.patch.object( - transports.ContextsRestInterceptor, "post_update_context_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ContextsRestInterceptor, "pre_update_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "post_update_context" + ) as post, + mock.patch.object( + transports.ContextsRestInterceptor, "post_update_context_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_update_context" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5620,8 +5634,9 @@ def test_delete_context_rest_bad_request(request_type=context.DeleteContextReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5676,13 +5691,13 @@ def test_delete_context_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "pre_delete_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_delete_context" + ) as pre, + ): pre.assert_not_called() pb_message = context.DeleteContextRequest.pb(context.DeleteContextRequest()) transcode.return_value = { @@ -5725,8 +5740,9 @@ def test_delete_all_contexts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5781,13 +5797,13 @@ def test_delete_all_contexts_rest_interceptors(null_interceptor): ) client = ContextsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ContextsRestInterceptor, "pre_delete_all_contexts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ContextsRestInterceptor, "pre_delete_all_contexts" + ) as pre, + ): pre.assert_not_called() pb_message = context.DeleteAllContextsRequest.pb( context.DeleteAllContextsRequest() @@ -5832,8 +5848,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5892,8 +5909,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5954,8 +5972,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6016,8 +6035,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6076,8 +6096,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6317,11 +6338,14 @@ def test_contexts_base_transport(): def test_contexts_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContextsTransport( @@ -6341,9 +6365,12 @@ def test_contexts_base_transport_with_credentials_file(): def test_contexts_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ContextsTransport() @@ -6421,11 +6448,12 @@ def test_contexts_transport_auth_gdch_credentials(transport_class): def test_contexts_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6995,6 +7023,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7140,6 +7200,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7285,6 +7379,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7430,6 +7558,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7571,6 +7733,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ContextsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ContextsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ContextsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py index 4dd764490e65..5ab875a76843 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationProfilesClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): ConversationProfilesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationProfilesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1357,11 +1362,13 @@ def test_conversation_profiles_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6081,8 +6088,9 @@ def test_list_conversation_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6147,19 +6155,22 @@ def test_list_conversation_profiles_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_list_conversation_profiles", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_list_conversation_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, "pre_list_conversation_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_list_conversation_profiles", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_list_conversation_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_list_conversation_profiles", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6217,8 +6228,9 @@ def test_get_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6289,18 +6301,22 @@ def test_get_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, "post_get_conversation_profile" - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_get_conversation_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, "pre_get_conversation_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_get_conversation_profile", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_get_conversation_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_get_conversation_profile", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6358,8 +6374,9 @@ def test_create_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6619,20 +6636,22 @@ def test_create_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_create_conversation_profile", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_create_conversation_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_create_conversation_profile", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_create_conversation_profile", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_create_conversation_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_create_conversation_profile", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6694,8 +6713,9 @@ def test_update_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6959,20 +6979,22 @@ def test_update_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_update_conversation_profile", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_update_conversation_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_update_conversation_profile", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_update_conversation_profile", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_update_conversation_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_update_conversation_profile", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7030,8 +7052,9 @@ def test_delete_conversation_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7088,14 +7111,14 @@ def test_delete_conversation_profile_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_delete_conversation_profile", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_delete_conversation_profile", + ) as pre, + ): pre.assert_not_called() pb_message = conversation_profile.DeleteConversationProfileRequest.pb( conversation_profile.DeleteConversationProfileRequest() @@ -7142,8 +7165,9 @@ def test_set_suggestion_feature_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7202,22 +7226,23 @@ def test_set_suggestion_feature_config_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_set_suggestion_feature_config", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_set_suggestion_feature_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_set_suggestion_feature_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_set_suggestion_feature_config", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_set_suggestion_feature_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_set_suggestion_feature_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7272,8 +7297,9 @@ def test_clear_suggestion_feature_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7332,22 +7358,23 @@ def test_clear_suggestion_feature_config_rest_interceptors(null_interceptor): ) client = ConversationProfilesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_clear_suggestion_feature_config", - ) as post, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "post_clear_suggestion_feature_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationProfilesRestInterceptor, - "pre_clear_suggestion_feature_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_clear_suggestion_feature_config", + ) as post, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "post_clear_suggestion_feature_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationProfilesRestInterceptor, + "pre_clear_suggestion_feature_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7400,8 +7427,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7460,8 +7488,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7522,8 +7551,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7584,8 +7614,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7644,8 +7675,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7940,11 +7972,14 @@ def test_conversation_profiles_base_transport(): def test_conversation_profiles_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationProfilesTransport( @@ -7964,9 +7999,12 @@ def test_conversation_profiles_base_transport_with_credentials_file(): def test_conversation_profiles_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationProfilesTransport() @@ -8044,11 +8082,12 @@ def test_conversation_profiles_transport_auth_gdch_credentials(transport_class): def test_conversation_profiles_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8844,6 +8883,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8989,6 +9060,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9134,6 +9239,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9279,6 +9418,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9422,6 +9595,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationProfilesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationProfilesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationProfilesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py index bd0aa206e045..bdaf51c03f25 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( ConversationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1291,11 +1296,13 @@ def test_conversations_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8690,8 +8697,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8851,18 +8859,20 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_create_conversation" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_create_conversation" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_create_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8917,8 +8927,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8981,17 +8992,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_conversations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9049,8 +9063,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9124,17 +9139,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_get_conversation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9187,8 +9205,9 @@ def test_complete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9262,18 +9281,20 @@ def test_complete_conversation_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_complete_conversation" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_complete_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_complete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_complete_conversation" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_complete_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_complete_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9328,8 +9349,9 @@ def test_ingest_context_references_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9391,18 +9413,20 @@ def test_ingest_context_references_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_ingest_context_references" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_ingest_context_references_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_ingest_context_references" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_ingest_context_references" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_ingest_context_references_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_ingest_context_references" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9460,8 +9484,9 @@ def test_batch_create_messages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9521,18 +9546,20 @@ def test_batch_create_messages_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_batch_create_messages" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_batch_create_messages_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_batch_create_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_batch_create_messages" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_batch_create_messages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_batch_create_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9588,8 +9615,9 @@ def test_list_messages_rest_bad_request(request_type=conversation.ListMessagesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9652,17 +9680,19 @@ def test_list_messages_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_messages" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_list_messages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_list_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_list_messages" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_list_messages_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_list_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9717,8 +9747,9 @@ def test_suggest_conversation_summary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9785,18 +9816,20 @@ def test_suggest_conversation_summary_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_suggest_conversation_summary" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_suggest_conversation_summary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_suggest_conversation_summary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_suggest_conversation_summary" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_suggest_conversation_summary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_suggest_conversation_summary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9854,8 +9887,9 @@ def test_generate_stateless_summary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9920,18 +9954,20 @@ def test_generate_stateless_summary_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_generate_stateless_summary" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_generate_stateless_summary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_generate_stateless_summary" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_generate_stateless_summary" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_stateless_summary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_generate_stateless_summary" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9989,8 +10025,9 @@ def test_generate_stateless_suggestion_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10050,18 +10087,21 @@ def test_generate_stateless_suggestion_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_generate_stateless_suggestion" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_generate_stateless_suggestion_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_generate_stateless_suggestion" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_stateless_suggestion", + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_stateless_suggestion_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_generate_stateless_suggestion" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10119,8 +10159,9 @@ def test_search_knowledge_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10183,17 +10224,20 @@ def test_search_knowledge_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_search_knowledge" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, "post_search_knowledge_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_search_knowledge" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_search_knowledge" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_search_knowledge_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_search_knowledge" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10251,8 +10295,9 @@ def test_generate_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10315,18 +10360,20 @@ def test_generate_suggestions_rest_interceptors(null_interceptor): ) client = ConversationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationsRestInterceptor, "post_generate_suggestions" - ) as post, mock.patch.object( - transports.ConversationsRestInterceptor, - "post_generate_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationsRestInterceptor, "pre_generate_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationsRestInterceptor, "post_generate_suggestions" + ) as post, + mock.patch.object( + transports.ConversationsRestInterceptor, + "post_generate_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationsRestInterceptor, "pre_generate_suggestions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10384,8 +10431,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10444,8 +10492,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10506,8 +10555,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10568,8 +10618,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10628,8 +10679,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11011,11 +11063,14 @@ def test_conversations_base_transport(): def test_conversations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationsTransport( @@ -11035,9 +11090,12 @@ def test_conversations_base_transport_with_credentials_file(): def test_conversations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationsTransport() @@ -11115,11 +11173,12 @@ def test_conversations_transport_auth_gdch_credentials(transport_class): def test_conversations_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12023,6 +12082,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12168,6 +12259,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12313,6 +12438,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12458,6 +12617,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12599,6 +12792,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ConversationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ConversationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ConversationsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py index 989629a95184..87aedc55e725 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentsClient._get_default_mtls_endpoint(None) is None assert DocumentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DocumentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DocumentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1247,11 +1251,13 @@ def test_documents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5478,8 +5484,9 @@ def test_list_documents_rest_bad_request(request_type=document.ListDocumentsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5540,17 +5547,19 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentsRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_list_documents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5601,8 +5610,9 @@ def test_get_document_rest_bad_request(request_type=document.GetDocumentRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5674,17 +5684,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentsRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5735,8 +5747,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5883,19 +5896,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_create_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5948,8 +5962,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6004,19 +6019,20 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_import_documents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6067,8 +6083,9 @@ def test_delete_document_rest_bad_request(request_type=document.DeleteDocumentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6123,19 +6140,20 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_delete_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_delete_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_delete_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_delete_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6190,8 +6208,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6342,19 +6361,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_update_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6405,8 +6425,9 @@ def test_reload_document_rest_bad_request(request_type=document.ReloadDocumentRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6461,19 +6482,20 @@ def test_reload_document_rest_interceptors(null_interceptor): ) client = DocumentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentsRestInterceptor, "post_reload_document" - ) as post, mock.patch.object( - transports.DocumentsRestInterceptor, "post_reload_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentsRestInterceptor, "pre_reload_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentsRestInterceptor, "post_reload_document" + ) as post, + mock.patch.object( + transports.DocumentsRestInterceptor, "post_reload_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentsRestInterceptor, "pre_reload_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6524,8 +6546,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6584,8 +6607,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6646,8 +6670,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6708,8 +6733,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6768,8 +6794,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7050,11 +7077,14 @@ def test_documents_base_transport(): def test_documents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentsTransport( @@ -7074,9 +7104,12 @@ def test_documents_base_transport_with_credentials_file(): def test_documents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentsTransport() @@ -7154,11 +7187,12 @@ def test_documents_transport_auth_gdch_credentials(transport_class): def test_documents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7765,6 +7799,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7910,6 +7976,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8055,6 +8155,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8200,6 +8334,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8341,6 +8509,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DocumentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DocumentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DocumentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_encryption_spec_service.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_encryption_spec_service.py index ae9ced282b84..d86f148f5aed 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_encryption_spec_service.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_encryption_spec_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EncryptionSpecServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): EncryptionSpecServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EncryptionSpecServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1348,11 +1353,13 @@ def test_encryption_spec_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2671,8 +2678,9 @@ def test_get_encryption_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2737,18 +2745,20 @@ def test_get_encryption_spec_rest_interceptors(null_interceptor): ) client = EncryptionSpecServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, "post_get_encryption_spec" - ) as post, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "post_get_encryption_spec_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, "pre_get_encryption_spec" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, "post_get_encryption_spec" + ) as post, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "post_get_encryption_spec_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, "pre_get_encryption_spec" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2805,8 +2815,9 @@ def test_initialize_encryption_spec_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2865,22 +2876,23 @@ def test_initialize_encryption_spec_rest_interceptors(null_interceptor): ) client = EncryptionSpecServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "post_initialize_encryption_spec", - ) as post, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "post_initialize_encryption_spec_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EncryptionSpecServiceRestInterceptor, - "pre_initialize_encryption_spec", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "post_initialize_encryption_spec", + ) as post, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "post_initialize_encryption_spec_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EncryptionSpecServiceRestInterceptor, + "pre_initialize_encryption_spec", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2933,8 +2945,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2993,8 +3006,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3055,8 +3069,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3117,8 +3132,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3177,8 +3193,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3358,11 +3375,14 @@ def test_encryption_spec_service_base_transport(): def test_encryption_spec_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EncryptionSpecServiceTransport( @@ -3382,9 +3402,12 @@ def test_encryption_spec_service_base_transport_with_credentials_file(): def test_encryption_spec_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.encryption_spec_service.transports.EncryptionSpecServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EncryptionSpecServiceTransport() @@ -3464,11 +3487,12 @@ def test_encryption_spec_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4070,6 +4094,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4215,6 +4271,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4360,6 +4450,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4505,6 +4629,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4648,6 +4806,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EncryptionSpecServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EncryptionSpecServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EncryptionSpecServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py index a594f0b36329..443e9ab927ea 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EntityTypesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1253,11 +1257,13 @@ def test_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7597,8 +7603,9 @@ def test_list_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7661,17 +7668,20 @@ def test_list_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_list_entity_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_list_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_list_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_list_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_list_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7729,8 +7739,9 @@ def test_get_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7804,17 +7815,19 @@ def test_get_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_get_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_get_entity_type_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_get_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7867,8 +7880,9 @@ def test_create_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8019,17 +8033,20 @@ def test_create_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_create_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_create_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_create_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_create_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_create_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8084,8 +8101,9 @@ def test_update_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8238,17 +8256,20 @@ def test_update_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, "post_update_entity_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_update_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_update_entity_type" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_update_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_update_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8301,8 +8322,9 @@ def test_delete_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8359,13 +8381,13 @@ def test_delete_entity_type_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_delete_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_delete_entity_type" + ) as pre, + ): pre.assert_not_called() pb_message = entity_type.DeleteEntityTypeRequest.pb( entity_type.DeleteEntityTypeRequest() @@ -8410,8 +8432,9 @@ def test_batch_update_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8468,20 +8491,21 @@ def test_batch_update_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_update_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_update_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_update_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_update_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_update_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_update_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8534,8 +8558,9 @@ def test_batch_delete_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8592,20 +8617,21 @@ def test_batch_delete_entity_types_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_delete_entity_types" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_delete_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_delete_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_delete_entity_types" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_delete_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_delete_entity_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8658,8 +8684,9 @@ def test_batch_create_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8716,20 +8743,21 @@ def test_batch_create_entities_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_create_entities" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_create_entities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_create_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_create_entities" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_create_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_create_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8782,8 +8810,9 @@ def test_batch_update_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8840,20 +8869,21 @@ def test_batch_update_entities_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_update_entities" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_update_entities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_update_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_update_entities" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_update_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_update_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8906,8 +8936,9 @@ def test_batch_delete_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8964,20 +8995,21 @@ def test_batch_delete_entities_rest_interceptors(null_interceptor): ) client = EntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EntityTypesRestInterceptor, "post_batch_delete_entities" - ) as post, mock.patch.object( - transports.EntityTypesRestInterceptor, - "post_batch_delete_entities_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EntityTypesRestInterceptor, "pre_batch_delete_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EntityTypesRestInterceptor, "post_batch_delete_entities" + ) as post, + mock.patch.object( + transports.EntityTypesRestInterceptor, + "post_batch_delete_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EntityTypesRestInterceptor, "pre_batch_delete_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9030,8 +9062,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9090,8 +9123,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9152,8 +9186,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9214,8 +9249,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9274,8 +9310,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9637,11 +9674,14 @@ def test_entity_types_base_transport(): def test_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport( @@ -9661,9 +9701,12 @@ def test_entity_types_base_transport_with_credentials_file(): def test_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EntityTypesTransport() @@ -9741,11 +9784,12 @@ def test_entity_types_transport_auth_gdch_credentials(transport_class): def test_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10358,6 +10402,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10503,6 +10579,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10648,6 +10758,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10793,6 +10937,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10934,6 +11112,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py index 64e5df1d1749..7013c7a23dc5 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EnvironmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EnvironmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EnvironmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1261,11 +1266,13 @@ def test_environments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4771,8 +4778,9 @@ def test_list_environments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4835,17 +4843,20 @@ def test_list_environments_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_list_environments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_list_environments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_list_environments" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_list_environments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_list_environments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4903,8 +4914,9 @@ def test_get_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4973,17 +4985,19 @@ def test_get_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_get_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_get_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5036,8 +5050,9 @@ def test_create_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5199,17 +5214,20 @@ def test_create_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_create_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_create_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_create_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_create_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_create_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5264,8 +5282,9 @@ def test_update_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5429,17 +5448,20 @@ def test_update_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_update_environment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_update_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_update_environment" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_update_environment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_update_environment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5492,8 +5514,9 @@ def test_delete_environment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5550,13 +5573,13 @@ def test_delete_environment_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_delete_environment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_delete_environment" + ) as pre, + ): pre.assert_not_called() pb_message = environment.DeleteEnvironmentRequest.pb( environment.DeleteEnvironmentRequest() @@ -5601,8 +5624,9 @@ def test_get_environment_history_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5667,18 +5691,20 @@ def test_get_environment_history_rest_interceptors(null_interceptor): ) client = EnvironmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnvironmentsRestInterceptor, "post_get_environment_history" - ) as post, mock.patch.object( - transports.EnvironmentsRestInterceptor, - "post_get_environment_history_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnvironmentsRestInterceptor, "pre_get_environment_history" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "post_get_environment_history" + ) as post, + mock.patch.object( + transports.EnvironmentsRestInterceptor, + "post_get_environment_history_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnvironmentsRestInterceptor, "pre_get_environment_history" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5733,8 +5759,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5793,8 +5820,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5855,8 +5883,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5917,8 +5946,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5977,8 +6007,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6226,11 +6257,14 @@ def test_environments_base_transport(): def test_environments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport( @@ -6250,9 +6284,12 @@ def test_environments_base_transport_with_credentials_file(): def test_environments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnvironmentsTransport() @@ -6330,11 +6367,12 @@ def test_environments_transport_auth_gdch_credentials(transport_class): def test_environments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6944,6 +6982,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7089,6 +7159,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7234,6 +7338,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7379,6 +7517,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7520,6 +7692,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EnvironmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EnvironmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EnvironmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py index 0a83ae5e1258..f0233c67686d 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FulfillmentsClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FulfillmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FulfillmentsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1260,11 +1265,13 @@ def test_fulfillments_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2585,8 +2592,9 @@ def test_get_fulfillment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2653,17 +2661,19 @@ def test_get_fulfillment_rest_interceptors(null_interceptor): ) client = FulfillmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_get_fulfillment" - ) as post, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_get_fulfillment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FulfillmentsRestInterceptor, "pre_get_fulfillment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "post_get_fulfillment" + ) as post, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "post_get_fulfillment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "pre_get_fulfillment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2716,8 +2726,9 @@ def test_update_fulfillment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2864,17 +2875,20 @@ def test_update_fulfillment_rest_interceptors(null_interceptor): ) client = FulfillmentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_update_fulfillment" - ) as post, mock.patch.object( - transports.FulfillmentsRestInterceptor, "post_update_fulfillment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FulfillmentsRestInterceptor, "pre_update_fulfillment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "post_update_fulfillment" + ) as post, + mock.patch.object( + transports.FulfillmentsRestInterceptor, + "post_update_fulfillment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FulfillmentsRestInterceptor, "pre_update_fulfillment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2929,8 +2943,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2989,8 +3004,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3051,8 +3067,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3113,8 +3130,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3173,8 +3191,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3330,11 +3349,14 @@ def test_fulfillments_base_transport(): def test_fulfillments_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FulfillmentsTransport( @@ -3354,9 +3376,12 @@ def test_fulfillments_base_transport_with_credentials_file(): def test_fulfillments_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FulfillmentsTransport() @@ -3434,11 +3459,12 @@ def test_fulfillments_transport_auth_gdch_credentials(transport_class): def test_fulfillments_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3990,6 +4016,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4135,6 +4193,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4280,6 +4372,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4425,6 +4551,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4566,6 +4726,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = FulfillmentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = FulfillmentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = FulfillmentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generator_evaluations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generator_evaluations.py index 0b81ad83e091..b9aa48361e8b 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generator_evaluations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generator_evaluations.py @@ -138,6 +138,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeneratorEvaluationsClient._get_default_mtls_endpoint(None) is None assert ( @@ -160,6 +161,10 @@ def test__get_default_mtls_endpoint(): GeneratorEvaluationsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GeneratorEvaluationsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1359,11 +1364,13 @@ def test_generator_evaluations_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4171,8 +4178,9 @@ def test_create_generator_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4535,22 +4543,23 @@ def test_create_generator_evaluation_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_create_generator_evaluation", - ) as post, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_create_generator_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "pre_create_generator_evaluation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_create_generator_evaluation", + ) as post, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_create_generator_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_create_generator_evaluation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4605,8 +4614,9 @@ def test_get_generator_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4677,18 +4687,22 @@ def test_get_generator_evaluation_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, "post_get_generator_evaluation" - ) as post, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_get_generator_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, "pre_get_generator_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_get_generator_evaluation", + ) as post, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_get_generator_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_get_generator_evaluation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4746,8 +4760,9 @@ def test_list_generator_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4812,19 +4827,22 @@ def test_list_generator_evaluations_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_list_generator_evaluations", - ) as post, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "post_list_generator_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, "pre_list_generator_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_list_generator_evaluations", + ) as post, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "post_list_generator_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_list_generator_evaluations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4884,8 +4902,9 @@ def test_delete_generator_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4944,14 +4963,14 @@ def test_delete_generator_evaluation_rest_interceptors(null_interceptor): ) client = GeneratorEvaluationsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorEvaluationsRestInterceptor, - "pre_delete_generator_evaluation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorEvaluationsRestInterceptor, + "pre_delete_generator_evaluation", + ) as pre, + ): pre.assert_not_called() pb_message = generator_evaluation.DeleteGeneratorEvaluationRequest.pb( generator_evaluation.DeleteGeneratorEvaluationRequest() @@ -4996,8 +5015,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5056,8 +5076,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5118,8 +5139,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5180,8 +5202,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5240,8 +5263,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5467,11 +5491,14 @@ def test_generator_evaluations_base_transport(): def test_generator_evaluations_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorEvaluationsTransport( @@ -5491,9 +5518,12 @@ def test_generator_evaluations_base_transport_with_credentials_file(): def test_generator_evaluations_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.generator_evaluations.transports.GeneratorEvaluationsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorEvaluationsTransport() @@ -5571,11 +5601,12 @@ def test_generator_evaluations_transport_auth_gdch_credentials(transport_class): def test_generator_evaluations_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6243,6 +6274,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6388,6 +6451,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6533,6 +6630,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6678,6 +6809,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6821,6 +6986,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GeneratorEvaluationsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GeneratorEvaluationsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GeneratorEvaluationsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generators.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generators.py index 0df77e06df64..9ae10e043497 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generators.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_generators.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GeneratorsClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GeneratorsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + GeneratorsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1249,11 +1253,13 @@ def test_generators_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4517,8 +4523,9 @@ def test_create_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4779,17 +4786,19 @@ def test_create_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_create_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_create_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_create_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4840,8 +4849,9 @@ def test_get_generator_rest_bad_request(request_type=generator.GetGeneratorReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4911,17 +4921,19 @@ def test_get_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_get_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_get_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_get_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4970,8 +4982,9 @@ def test_list_generators_rest_bad_request(request_type=generator.ListGeneratorsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5034,17 +5047,19 @@ def test_list_generators_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_list_generators" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_list_generators_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_list_generators" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5099,8 +5114,9 @@ def test_delete_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5157,13 +5173,13 @@ def test_delete_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_delete_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_delete_generator" + ) as pre, + ): pre.assert_not_called() pb_message = generator.DeleteGeneratorRequest.pb( generator.DeleteGeneratorRequest() @@ -5210,8 +5226,9 @@ def test_update_generator_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5474,17 +5491,19 @@ def test_update_generator_rest_interceptors(null_interceptor): ) client = GeneratorsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator" - ) as post, mock.patch.object( - transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GeneratorsRestInterceptor, "pre_update_generator" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator" + ) as post, + mock.patch.object( + transports.GeneratorsRestInterceptor, "post_update_generator_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GeneratorsRestInterceptor, "pre_update_generator" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5537,8 +5556,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5597,8 +5617,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5659,8 +5680,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5721,8 +5743,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5781,8 +5804,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5999,11 +6023,14 @@ def test_generators_base_transport(): def test_generators_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport( @@ -6023,9 +6050,12 @@ def test_generators_base_transport_with_credentials_file(): def test_generators_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.generators.transports.GeneratorsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GeneratorsTransport() @@ -6103,11 +6133,12 @@ def test_generators_transport_auth_gdch_credentials(transport_class): def test_generators_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6700,6 +6731,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6845,6 +6908,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6990,6 +7087,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7135,6 +7266,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7276,6 +7441,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GeneratorsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GeneratorsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GeneratorsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py index 28ed8f5d6b9a..299674f31f95 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IntentsClient._get_default_mtls_endpoint(None) is None assert IntentsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert IntentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IntentsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1223,11 +1225,13 @@ def test_intents_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5948,8 +5952,9 @@ def test_list_intents_rest_bad_request(request_type=intent.ListIntentsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6010,17 +6015,17 @@ def test_list_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_list_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_list_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_list_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_list_intents") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6069,8 +6074,9 @@ def test_get_intent_rest_bad_request(request_type=intent.GetIntentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6163,17 +6169,15 @@ def test_get_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_get_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_get_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.IntentsRestInterceptor, "post_get_intent") as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_get_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IntentsRestInterceptor, "pre_get_intent") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6222,8 +6226,9 @@ def test_create_intent_rest_bad_request(request_type=gcd_intent.CreateIntentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6589,17 +6594,19 @@ def test_create_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_create_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_create_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_create_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_create_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6648,8 +6655,9 @@ def test_update_intent_rest_bad_request(request_type=gcd_intent.UpdateIntentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7015,17 +7023,19 @@ def test_update_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_update_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_update_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_update_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_update_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7074,8 +7084,9 @@ def test_delete_intent_rest_bad_request(request_type=intent.DeleteIntentRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7130,13 +7141,13 @@ def test_delete_intent_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IntentsRestInterceptor, "pre_delete_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_delete_intent" + ) as pre, + ): pre.assert_not_called() pb_message = intent.DeleteIntentRequest.pb(intent.DeleteIntentRequest()) transcode.return_value = { @@ -7179,8 +7190,9 @@ def test_batch_update_intents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7235,19 +7247,20 @@ def test_batch_update_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_update_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_update_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_batch_update_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_update_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_update_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_batch_update_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7300,8 +7313,9 @@ def test_batch_delete_intents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7356,19 +7370,20 @@ def test_batch_delete_intents_rest_interceptors(null_interceptor): ) client = IntentsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_delete_intents" - ) as post, mock.patch.object( - transports.IntentsRestInterceptor, "post_batch_delete_intents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IntentsRestInterceptor, "pre_batch_delete_intents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_delete_intents" + ) as post, + mock.patch.object( + transports.IntentsRestInterceptor, "post_batch_delete_intents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IntentsRestInterceptor, "pre_batch_delete_intents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7421,8 +7436,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7481,8 +7497,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7543,8 +7560,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7605,8 +7623,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7665,8 +7684,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7951,11 +7971,14 @@ def test_intents_base_transport(): def test_intents_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport( @@ -7975,9 +7998,12 @@ def test_intents_base_transport_with_credentials_file(): def test_intents_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IntentsTransport() @@ -8055,11 +8081,12 @@ def test_intents_transport_auth_gdch_credentials(transport_class): def test_intents_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8689,6 +8716,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8834,6 +8893,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8979,6 +9072,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9124,6 +9251,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9265,6 +9426,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = IntentsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = IntentsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = IntentsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py index e0d530f10a3b..4173f859cdbc 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert KnowledgeBasesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): assert ( KnowledgeBasesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + KnowledgeBasesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1284,11 +1289,13 @@ def test_knowledge_bases_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4658,8 +4665,9 @@ def test_list_knowledge_bases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4722,18 +4730,20 @@ def test_list_knowledge_bases_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_list_knowledge_bases" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_list_knowledge_bases_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_list_knowledge_bases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_list_knowledge_bases" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_list_knowledge_bases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_list_knowledge_bases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4791,8 +4801,9 @@ def test_get_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4859,18 +4870,20 @@ def test_get_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_get_knowledge_base" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_get_knowledge_base_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_get_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_get_knowledge_base" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_get_knowledge_base_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_get_knowledge_base" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4925,8 +4938,9 @@ def test_create_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5067,18 +5081,20 @@ def test_create_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_create_knowledge_base" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_create_knowledge_base_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_create_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_create_knowledge_base" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_create_knowledge_base_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_create_knowledge_base" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5133,8 +5149,9 @@ def test_delete_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5191,13 +5208,13 @@ def test_delete_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_delete_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_delete_knowledge_base" + ) as pre, + ): pre.assert_not_called() pb_message = knowledge_base.DeleteKnowledgeBaseRequest.pb( knowledge_base.DeleteKnowledgeBaseRequest() @@ -5244,8 +5261,9 @@ def test_update_knowledge_base_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5388,18 +5406,20 @@ def test_update_knowledge_base_rest_interceptors(null_interceptor): ) client = KnowledgeBasesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "post_update_knowledge_base" - ) as post, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, - "post_update_knowledge_base_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KnowledgeBasesRestInterceptor, "pre_update_knowledge_base" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "post_update_knowledge_base" + ) as post, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, + "post_update_knowledge_base_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KnowledgeBasesRestInterceptor, "pre_update_knowledge_base" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5454,8 +5474,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5514,8 +5535,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5576,8 +5598,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5638,8 +5661,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5698,8 +5722,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5926,11 +5951,14 @@ def test_knowledge_bases_base_transport(): def test_knowledge_bases_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KnowledgeBasesTransport( @@ -5950,9 +5978,12 @@ def test_knowledge_bases_base_transport_with_credentials_file(): def test_knowledge_bases_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KnowledgeBasesTransport() @@ -6030,11 +6061,12 @@ def test_knowledge_bases_transport_auth_gdch_credentials(transport_class): def test_knowledge_bases_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6609,6 +6641,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6754,6 +6818,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6899,6 +6997,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7044,6 +7176,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7185,6 +7351,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = KnowledgeBasesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = KnowledgeBasesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = KnowledgeBasesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py index a688b0556048..856c7716eec0 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ParticipantsClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ParticipantsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ParticipantsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1273,11 +1278,13 @@ def test_participants_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8183,8 +8190,9 @@ def test_create_participant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8330,17 +8338,20 @@ def test_create_participant_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_create_participant" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_create_participant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_create_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_create_participant" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_create_participant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_create_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8397,8 +8408,9 @@ def test_get_participant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8472,17 +8484,19 @@ def test_get_participant_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_get_participant" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_get_participant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_get_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_get_participant" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_get_participant_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_get_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8535,8 +8549,9 @@ def test_list_participants_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8599,17 +8614,20 @@ def test_list_participants_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_list_participants" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_list_participants_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_list_participants" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_list_participants" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_list_participants_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_list_participants" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8671,8 +8689,9 @@ def test_update_participant_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8822,17 +8841,20 @@ def test_update_participant_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_update_participant" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_update_participant_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_update_participant" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_update_participant" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_update_participant_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_update_participant" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8889,8 +8911,9 @@ def test_analyze_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8955,17 +8978,19 @@ def test_analyze_content_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_analyze_content" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_analyze_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_analyze_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_analyze_content" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_analyze_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_analyze_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9050,8 +9075,9 @@ def test_suggest_articles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9118,17 +9144,20 @@ def test_suggest_articles_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_articles" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_articles_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_articles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_articles" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_articles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_articles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9188,8 +9217,9 @@ def test_suggest_faq_answers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9256,17 +9286,20 @@ def test_suggest_faq_answers_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_faq_answers" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_faq_answers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_faq_answers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_faq_answers" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_faq_answers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_faq_answers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9326,8 +9359,9 @@ def test_suggest_smart_replies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9394,18 +9428,20 @@ def test_suggest_smart_replies_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_smart_replies" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, - "post_suggest_smart_replies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_smart_replies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_smart_replies" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_smart_replies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_smart_replies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9465,8 +9501,9 @@ def test_suggest_knowledge_assist_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9533,18 +9570,20 @@ def test_suggest_knowledge_assist_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_suggest_knowledge_assist" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, - "post_suggest_knowledge_assist_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_suggest_knowledge_assist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_suggest_knowledge_assist" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_suggest_knowledge_assist_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_suggest_knowledge_assist" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9604,8 +9643,9 @@ def test_list_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9670,17 +9710,20 @@ def test_list_suggestions_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_list_suggestions" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_list_suggestions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_list_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_list_suggestions" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_list_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_list_suggestions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9740,8 +9783,9 @@ def test_compile_suggestion_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9808,17 +9852,20 @@ def test_compile_suggestion_rest_interceptors(null_interceptor): ) client = ParticipantsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_compile_suggestion" - ) as post, mock.patch.object( - transports.ParticipantsRestInterceptor, "post_compile_suggestion_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ParticipantsRestInterceptor, "pre_compile_suggestion" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ParticipantsRestInterceptor, "post_compile_suggestion" + ) as post, + mock.patch.object( + transports.ParticipantsRestInterceptor, + "post_compile_suggestion_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ParticipantsRestInterceptor, "pre_compile_suggestion" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9876,8 +9923,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9936,8 +9984,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9998,8 +10047,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10060,8 +10110,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10120,8 +10171,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -10480,11 +10532,14 @@ def test_participants_base_transport(): def test_participants_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ParticipantsTransport( @@ -10504,9 +10559,12 @@ def test_participants_base_transport_with_credentials_file(): def test_participants_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ParticipantsTransport() @@ -10584,11 +10642,12 @@ def test_participants_transport_auth_gdch_credentials(transport_class): def test_participants_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11385,6 +11444,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11530,6 +11621,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11675,6 +11800,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11820,6 +11979,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11961,6 +12154,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ParticipantsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ParticipantsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ParticipantsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_phone_numbers.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_phone_numbers.py index e290a7e69ba0..e797629dbffb 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_phone_numbers.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_phone_numbers.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PhoneNumbersClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PhoneNumbersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + PhoneNumbersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1261,11 +1266,13 @@ def test_phone_numbers_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4072,8 +4079,9 @@ def test_list_phone_numbers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4136,17 +4144,20 @@ def test_list_phone_numbers_rest_interceptors(null_interceptor): ) client = PhoneNumbersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_list_phone_numbers" - ) as post, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_list_phone_numbers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "pre_list_phone_numbers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "post_list_phone_numbers" + ) as post, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, + "post_list_phone_numbers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "pre_list_phone_numbers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4204,8 +4215,9 @@ def test_update_phone_number_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4349,17 +4361,20 @@ def test_update_phone_number_rest_interceptors(null_interceptor): ) client = PhoneNumbersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_update_phone_number" - ) as post, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_update_phone_number_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "pre_update_phone_number" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "post_update_phone_number" + ) as post, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, + "post_update_phone_number_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "pre_update_phone_number" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4414,8 +4429,9 @@ def test_delete_phone_number_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4484,17 +4500,20 @@ def test_delete_phone_number_rest_interceptors(null_interceptor): ) client = PhoneNumbersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_delete_phone_number" - ) as post, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_delete_phone_number_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "pre_delete_phone_number" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "post_delete_phone_number" + ) as post, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, + "post_delete_phone_number_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "pre_delete_phone_number" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4547,8 +4566,9 @@ def test_undelete_phone_number_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4617,18 +4637,20 @@ def test_undelete_phone_number_rest_interceptors(null_interceptor): ) client = PhoneNumbersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "post_undelete_phone_number" - ) as post, mock.patch.object( - transports.PhoneNumbersRestInterceptor, - "post_undelete_phone_number_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PhoneNumbersRestInterceptor, "pre_undelete_phone_number" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "post_undelete_phone_number" + ) as post, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, + "post_undelete_phone_number_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PhoneNumbersRestInterceptor, "pre_undelete_phone_number" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4681,8 +4703,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4741,8 +4764,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4803,8 +4827,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4865,8 +4890,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4925,8 +4951,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5130,11 +5157,14 @@ def test_phone_numbers_base_transport(): def test_phone_numbers_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.phone_numbers.transports.PhoneNumbersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.phone_numbers.transports.PhoneNumbersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PhoneNumbersTransport( @@ -5154,9 +5184,12 @@ def test_phone_numbers_base_transport_with_credentials_file(): def test_phone_numbers_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.phone_numbers.transports.PhoneNumbersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.phone_numbers.transports.PhoneNumbersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PhoneNumbersTransport() @@ -5234,11 +5267,12 @@ def test_phone_numbers_transport_auth_gdch_credentials(transport_class): def test_phone_numbers_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5799,6 +5833,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = PhoneNumbersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = PhoneNumbersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = PhoneNumbersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5944,6 +6010,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PhoneNumbersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PhoneNumbersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = PhoneNumbersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6089,6 +6189,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = PhoneNumbersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = PhoneNumbersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = PhoneNumbersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6234,6 +6368,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = PhoneNumbersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = PhoneNumbersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = PhoneNumbersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6375,6 +6543,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = PhoneNumbersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = PhoneNumbersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = PhoneNumbersClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py index b5783ea76f4f..76ec861bd4b1 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionEntityTypesClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): SessionEntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionEntityTypesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1328,11 +1333,13 @@ def test_session_entity_types_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4751,8 +4758,9 @@ def test_list_session_entity_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4817,18 +4825,22 @@ def test_list_session_entity_types_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_list_session_entity_types" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_list_session_entity_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_list_session_entity_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_list_session_entity_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_list_session_entity_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4888,8 +4900,9 @@ def test_get_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4959,18 +4972,20 @@ def test_get_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_get_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "post_get_session_entity_type" + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_get_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, "pre_get_session_entity_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5028,8 +5043,9 @@ def test_create_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5173,18 +5189,22 @@ def test_create_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_create_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_create_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_create_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_create_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_create_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5246,8 +5266,9 @@ def test_update_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5395,18 +5416,22 @@ def test_update_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "post_update_session_entity_type" - ) as post, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, - "post_update_session_entity_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_update_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type", + ) as post, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "post_update_session_entity_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_update_session_entity_type", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5466,8 +5491,9 @@ def test_delete_session_entity_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5526,13 +5552,14 @@ def test_delete_session_entity_type_rest_interceptors(null_interceptor): ) client = SessionEntityTypesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionEntityTypesRestInterceptor, "pre_delete_session_entity_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionEntityTypesRestInterceptor, + "pre_delete_session_entity_type", + ) as pre, + ): pre.assert_not_called() pb_message = session_entity_type.DeleteSessionEntityTypeRequest.pb( session_entity_type.DeleteSessionEntityTypeRequest() @@ -5577,8 +5604,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5637,8 +5665,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5699,8 +5728,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5761,8 +5791,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5821,8 +5852,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6049,11 +6081,14 @@ def test_session_entity_types_base_transport(): def test_session_entity_types_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport( @@ -6073,9 +6108,12 @@ def test_session_entity_types_base_transport_with_credentials_file(): def test_session_entity_types_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionEntityTypesTransport() @@ -6153,11 +6191,12 @@ def test_session_entity_types_transport_auth_gdch_credentials(transport_class): def test_session_entity_types_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6741,6 +6780,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6886,6 +6957,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7031,6 +7136,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7176,6 +7315,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7317,6 +7490,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionEntityTypesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionEntityTypesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionEntityTypesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py index 7f4359a2797e..fce0cf866292 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionsClient._get_default_mtls_endpoint(None) is None assert SessionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -149,6 +150,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SessionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert SessionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1238,11 +1240,13 @@ def test_sessions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2192,8 +2196,9 @@ def test_detect_intent_rest_bad_request(request_type=gcd_session.DetectIntentReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2256,17 +2261,19 @@ def test_detect_intent_rest_interceptors(null_interceptor): ) client = SessionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent" - ) as post, mock.patch.object( - transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionsRestInterceptor, "pre_detect_intent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent" + ) as post, + mock.patch.object( + transports.SessionsRestInterceptor, "post_detect_intent_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionsRestInterceptor, "pre_detect_intent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2333,8 +2340,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2393,8 +2401,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2455,8 +2464,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2517,8 +2527,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2577,8 +2588,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2712,11 +2724,14 @@ def test_sessions_base_transport(): def test_sessions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport( @@ -2736,9 +2751,12 @@ def test_sessions_base_transport_with_credentials_file(): def test_sessions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionsTransport() @@ -2816,11 +2834,12 @@ def test_sessions_transport_auth_gdch_credentials(transport_class): def test_sessions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3504,6 +3523,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3649,6 +3700,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3794,6 +3879,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3939,6 +4058,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4080,6 +4233,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SessionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SessionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SessionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sip_trunks.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sip_trunks.py index e9ae46ac2cd6..bf047d85e5d6 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sip_trunks.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sip_trunks.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SipTrunksClient._get_default_mtls_endpoint(None) is None assert SipTrunksClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert SipTrunksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + SipTrunksClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_sip_trunks_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4476,8 +4482,9 @@ def test_create_sip_trunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4625,17 +4632,19 @@ def test_create_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_create_sip_trunk" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_create_sip_trunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_create_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_create_sip_trunk" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_create_sip_trunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_create_sip_trunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4688,8 +4697,9 @@ def test_delete_sip_trunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4744,13 +4754,13 @@ def test_delete_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_delete_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_delete_sip_trunk" + ) as pre, + ): pre.assert_not_called() pb_message = sip_trunk.DeleteSipTrunkRequest.pb( sip_trunk.DeleteSipTrunkRequest() @@ -4793,8 +4803,9 @@ def test_list_sip_trunks_rest_bad_request(request_type=sip_trunk.ListSipTrunksRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4855,17 +4866,19 @@ def test_list_sip_trunks_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_list_sip_trunks" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_list_sip_trunks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_list_sip_trunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_list_sip_trunks" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_list_sip_trunks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_list_sip_trunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4916,8 +4929,9 @@ def test_get_sip_trunk_rest_bad_request(request_type=sip_trunk.GetSipTrunkReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4982,17 +4996,19 @@ def test_get_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_get_sip_trunk" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_get_sip_trunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_get_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_get_sip_trunk" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_get_sip_trunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_get_sip_trunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5045,8 +5061,9 @@ def test_update_sip_trunk_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5196,17 +5213,19 @@ def test_update_sip_trunk_rest_interceptors(null_interceptor): ) client = SipTrunksClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_update_sip_trunk" - ) as post, mock.patch.object( - transports.SipTrunksRestInterceptor, "post_update_sip_trunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SipTrunksRestInterceptor, "pre_update_sip_trunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_update_sip_trunk" + ) as post, + mock.patch.object( + transports.SipTrunksRestInterceptor, "post_update_sip_trunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SipTrunksRestInterceptor, "pre_update_sip_trunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5259,8 +5278,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5319,8 +5339,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5381,8 +5402,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5443,8 +5465,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5503,8 +5526,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5721,11 +5745,14 @@ def test_sip_trunks_base_transport(): def test_sip_trunks_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SipTrunksTransport( @@ -5745,9 +5772,12 @@ def test_sip_trunks_base_transport_with_credentials_file(): def test_sip_trunks_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.sip_trunks.transports.SipTrunksTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SipTrunksTransport() @@ -5825,11 +5855,12 @@ def test_sip_trunks_transport_auth_gdch_credentials(transport_class): def test_sip_trunks_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6396,6 +6427,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6541,6 +6604,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6686,6 +6783,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6831,6 +6962,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6972,6 +7137,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = SipTrunksClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = SipTrunksAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = SipTrunksClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_tools.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_tools.py index 56dace9b4298..dc7d53a46703 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_tools.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_tools.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ToolsClient._get_default_mtls_endpoint(None) is None assert ToolsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ToolsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ToolsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1214,11 +1216,13 @@ def test_tools_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4465,8 +4469,9 @@ def test_create_tool_rest_bad_request(request_type=gcd_tool.CreateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4665,17 +4670,15 @@ def test_create_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_create_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_create_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_create_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_create_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_create_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4724,8 +4727,9 @@ def test_get_tool_rest_bad_request(request_type=tool.GetToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4796,17 +4800,15 @@ def test_get_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_get_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_get_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_get_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_get_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_get_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4855,8 +4857,9 @@ def test_list_tools_rest_bad_request(request_type=tool.ListToolsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4917,17 +4920,15 @@ def test_list_tools_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_list_tools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_list_tools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_list_tools") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_list_tools_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_list_tools") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4976,8 +4977,9 @@ def test_delete_tool_rest_bad_request(request_type=tool.DeleteToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5032,13 +5034,11 @@ def test_delete_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "pre_delete_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "pre_delete_tool") as pre, + ): pre.assert_not_called() pb_message = tool.DeleteToolRequest.pb(tool.DeleteToolRequest()) transcode.return_value = { @@ -5081,8 +5081,9 @@ def test_update_tool_rest_bad_request(request_type=gcd_tool.UpdateToolRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5283,17 +5284,15 @@ def test_update_tool_rest_interceptors(null_interceptor): ) client = ToolsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool" - ) as post, mock.patch.object( - transports.ToolsRestInterceptor, "post_update_tool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ToolsRestInterceptor, "pre_update_tool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.ToolsRestInterceptor, "post_update_tool") as post, + mock.patch.object( + transports.ToolsRestInterceptor, "post_update_tool_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ToolsRestInterceptor, "pre_update_tool") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5344,8 +5343,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5404,8 +5404,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5466,8 +5467,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5528,8 +5530,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5588,8 +5591,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5806,11 +5810,14 @@ def test_tools_base_transport(): def test_tools_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport( @@ -5830,9 +5837,12 @@ def test_tools_base_transport_with_credentials_file(): def test_tools_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.tools.transports.ToolsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ToolsTransport() @@ -5910,11 +5920,12 @@ def test_tools_transport_auth_gdch_credentials(transport_class): def test_tools_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6532,6 +6543,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6677,6 +6720,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6822,6 +6899,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6967,6 +7078,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7108,6 +7253,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ToolsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ToolsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ToolsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py index a8f9cc5d70b0..f0874ad831b3 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert VersionsClient._get_default_mtls_endpoint(None) is None assert VersionsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert VersionsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1229,11 +1231,13 @@ def test_versions_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4450,8 +4454,9 @@ def test_list_versions_rest_bad_request(request_type=version.ListVersionsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4512,17 +4517,19 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_list_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_list_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4573,8 +4580,9 @@ def test_get_version_rest_bad_request(request_type=version.GetVersionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4641,17 +4649,17 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_get_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_get_version_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.VersionsRestInterceptor, "pre_get_version") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4700,8 +4708,9 @@ def test_create_version_rest_bad_request(request_type=gcd_version.CreateVersionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4842,17 +4851,19 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_create_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_create_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4903,8 +4914,9 @@ def test_update_version_rest_bad_request(request_type=gcd_version.UpdateVersionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5045,17 +5057,19 @@ def test_update_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version" - ) as post, mock.patch.object( - transports.VersionsRestInterceptor, "post_update_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.VersionsRestInterceptor, "pre_update_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version" + ) as post, + mock.patch.object( + transports.VersionsRestInterceptor, "post_update_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_update_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5106,8 +5120,9 @@ def test_delete_version_rest_bad_request(request_type=version.DeleteVersionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5162,13 +5177,13 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = VersionsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.VersionsRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.VersionsRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() pb_message = version.DeleteVersionRequest.pb(version.DeleteVersionRequest()) transcode.return_value = { @@ -5211,8 +5226,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5271,8 +5287,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5333,8 +5350,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5395,8 +5413,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5455,8 +5474,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5673,11 +5693,14 @@ def test_versions_base_transport(): def test_versions_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport( @@ -5697,9 +5720,12 @@ def test_versions_base_transport_with_credentials_file(): def test_versions_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VersionsTransport() @@ -5777,11 +5803,12 @@ def test_versions_transport_auth_gdch_credentials(transport_class): def test_versions_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6345,6 +6372,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6490,6 +6549,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6635,6 +6728,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6780,6 +6907,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6921,6 +7082,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = VersionsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = VersionsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = VersionsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/async_client.py index 1792cec71938..e1d39c761537 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> AssistantServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -402,7 +402,7 @@ async def sample_stream_assist(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -428,8 +428,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -438,7 +442,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -446,7 +450,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -457,7 +461,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -483,8 +487,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -493,7 +501,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -501,7 +509,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -512,7 +520,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -541,8 +549,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -551,7 +563,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -559,7 +571,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/client.py index f7f1ad501920..768574a3e635 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/client.py @@ -114,7 +114,7 @@ class AssistantServiceClient(metaclass=AssistantServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -543,7 +547,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -640,7 +644,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -738,7 +742,7 @@ def __init__( self._universe_domain = AssistantServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -937,7 +941,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -963,8 +967,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -973,7 +981,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -982,7 +990,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -996,7 +1004,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1022,8 +1030,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1032,7 +1044,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1041,7 +1053,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1055,7 +1067,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1084,8 +1096,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1094,7 +1110,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1102,7 +1118,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/README.rst index 1307b08c52f3..098d53ed8fdd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AssistantServiceTransport` is the ABC for all transports. -- public child `AssistantServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AssistantServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAssistantServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AssistantServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AssistantServiceTransport`` is the ABC for all transports. + +- public child ``AssistantServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AssistantServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAssistantServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AssistantServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/base.py index 05e08e82a3c1..e83a7a47774e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc.py index b2493d8febcd..37a42ba8ea44 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc_asyncio.py index a69d350cc2ab..5f0e3f7de00a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/rest.py index eb3c52e21c77..9940aa921e05 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/assistant_service/transports/rest.py @@ -279,6 +279,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AssistantServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/async_client.py index 0eded8e525c3..336e5cb047b4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> CmekConfigServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -834,7 +834,7 @@ async def sample_delete_cmek_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -860,8 +860,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -870,7 +874,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -878,7 +882,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -889,7 +893,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -915,8 +919,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -925,7 +933,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -933,7 +941,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -944,7 +952,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -973,8 +981,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -983,7 +995,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -991,7 +1003,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/client.py index a5e8394dda2c..0f1e40c074e9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/client.py @@ -114,7 +114,7 @@ class CmekConfigServiceClient(metaclass=CmekConfigServiceClientMeta): """Service for managing CMEK related tasks""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -503,7 +507,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -600,7 +604,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -700,7 +704,7 @@ def __init__( self._universe_domain = CmekConfigServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1316,7 +1320,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1342,8 +1346,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1352,7 +1360,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1361,7 +1369,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1375,7 +1383,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1401,8 +1409,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1411,7 +1423,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1420,7 +1432,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1434,7 +1446,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1463,8 +1475,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1473,7 +1489,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1481,7 +1497,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/README.rst index 055d4169ac61..73b18b7192ed 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CmekConfigServiceTransport` is the ABC for all transports. -- public child `CmekConfigServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CmekConfigServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCmekConfigServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CmekConfigServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CmekConfigServiceTransport`` is the ABC for all transports. + +- public child ``CmekConfigServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CmekConfigServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCmekConfigServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CmekConfigServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/base.py index ef74c8a7b35b..ac65430a166b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc.py index 2d0bea4de25f..7797f1c38c40 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc_asyncio.py index 9cad7fc13f34..a4478898a0b7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/rest.py index d5108659ab8f..3cbb3e69f5a9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/cmek_config_service/transports/rest.py @@ -451,6 +451,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CmekConfigServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py index 25b51d0d2f93..09f7556fa4de 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> CompletionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -838,7 +838,7 @@ async def sample_purge_completion_suggestions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -864,8 +864,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -874,7 +878,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -882,7 +886,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -893,7 +897,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -919,8 +923,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -929,7 +937,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -937,7 +945,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -948,7 +956,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -977,8 +985,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -987,7 +999,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -995,7 +1007,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py index a4c086bd9bf3..57e3991c646f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py @@ -117,7 +117,7 @@ class CompletionServiceClient(metaclass=CompletionServiceClientMeta): """Service for Auto-Completion.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = CompletionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1280,7 +1284,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1306,8 +1310,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1316,7 +1324,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1325,7 +1333,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1339,7 +1347,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1365,8 +1373,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1375,7 +1387,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1384,7 +1396,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1398,7 +1410,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1427,8 +1439,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1437,7 +1453,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1445,7 +1461,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/README.rst index 3f71883905ca..3d1e4e840e1a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CompletionServiceTransport` is the ABC for all transports. -- public child `CompletionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CompletionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCompletionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CompletionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CompletionServiceTransport`` is the ABC for all transports. + +- public child ``CompletionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CompletionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCompletionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CompletionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py index 7f7e2a219285..42f11d5a325d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py index ce558fb78d68..3e0a87706a7b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py index 178eb05b2aa0..aba149518c17 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py index 6a27e58d7445..21455c8c17a4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py @@ -511,6 +511,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CompletionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/async_client.py index 6eaeed48bb72..13be4edf0a93 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> ControlServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -945,7 +945,7 @@ async def sample_list_controls(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -971,8 +971,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -981,7 +985,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -989,7 +993,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1000,7 +1004,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1026,8 +1030,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1036,7 +1044,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1044,7 +1052,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1055,7 +1063,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1084,8 +1092,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1094,7 +1106,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1102,7 +1114,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/client.py index e1ecbee20753..38323a441af0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/client.py @@ -118,7 +118,7 @@ class ControlServiceClient(metaclass=ControlServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -493,7 +497,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -590,7 +594,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -686,7 +690,7 @@ def __init__( self._universe_domain = ControlServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1419,7 +1423,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1445,8 +1449,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1455,7 +1463,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1464,7 +1472,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1478,7 +1486,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1504,8 +1512,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1514,7 +1526,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1523,7 +1535,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1537,7 +1549,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1566,8 +1578,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1576,7 +1592,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1584,7 +1600,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/README.rst index ee9c627694ad..099231a14c2f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ControlServiceTransport` is the ABC for all transports. -- public child `ControlServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ControlServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseControlServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ControlServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ControlServiceTransport`` is the ABC for all transports. + +- public child ``ControlServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ControlServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseControlServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ControlServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/base.py index e615c03753df..31ef20483bc3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc.py index ce68de8a060b..0d0aee91cc84 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc_asyncio.py index fd32e13b0024..5feaa8644dca 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/rest.py index e0d00f32cf75..dbcf29597c66 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/control_service/transports/rest.py @@ -463,6 +463,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ControlServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py index 0de773f0e739..6e2541e54be4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py @@ -251,7 +251,7 @@ def transport(self) -> ConversationalSearchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2015,7 +2015,7 @@ async def sample_list_sessions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2041,8 +2041,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2051,7 +2055,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2059,7 +2063,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2070,7 +2074,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2096,8 +2100,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2106,7 +2114,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2114,7 +2122,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2125,7 +2133,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2154,8 +2162,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2164,7 +2176,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2172,7 +2184,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py index 5271d777a6f3..9a176cdf20c7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py @@ -130,7 +130,7 @@ class ConversationalSearchServiceClient( """Service for conversational search.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -635,7 +639,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -734,7 +738,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -836,7 +840,7 @@ def __init__( self._universe_domain = ConversationalSearchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2560,7 +2564,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2586,8 +2590,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2596,7 +2604,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2605,7 +2613,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2619,7 +2627,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2645,8 +2653,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2655,7 +2667,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2664,7 +2676,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2678,7 +2690,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2707,8 +2719,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2717,7 +2733,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2725,7 +2741,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/README.rst index f8f6d58a0c64..99a63d05709f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationalSearchServiceTransport` is the ABC for all transports. -- public child `ConversationalSearchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationalSearchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationalSearchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationalSearchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationalSearchServiceTransport`` is the ABC for all transports. + +- public child ``ConversationalSearchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationalSearchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationalSearchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationalSearchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py index e67d297970d1..4c4d586f4bfc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py index 8cf4d2787c8f..06a9aea1b427 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py index a6e2effdae50..71456052275c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py index 31a6a5551dfc..a1125edcd78e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py @@ -956,6 +956,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationalSearchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/async_client.py index ee2664ae589f..cce984f8e413 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/async_client.py @@ -230,7 +230,7 @@ def transport(self) -> DataStoreServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1064,7 +1064,7 @@ async def sample_update_data_store(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1090,8 +1090,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1100,7 +1104,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1108,7 +1112,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1119,7 +1123,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1145,8 +1149,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1155,7 +1163,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1163,7 +1171,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1174,7 +1182,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1203,8 +1211,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1213,7 +1225,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1221,7 +1233,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/client.py index 5345e9b3404f..20be9ea5bb30 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/client.py @@ -128,7 +128,7 @@ class DataStoreServiceClient(metaclass=DataStoreServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -614,7 +618,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -711,7 +715,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -809,7 +813,7 @@ def __init__( self._universe_domain = DataStoreServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1628,7 +1632,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1654,8 +1658,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1664,7 +1672,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1673,7 +1681,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1687,7 +1695,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1713,8 +1721,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1723,7 +1735,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1732,7 +1744,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1746,7 +1758,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1775,8 +1787,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1785,7 +1801,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1793,7 +1809,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/README.rst index 7b7cd44d7eab..aaa93b7f76f6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataStoreServiceTransport` is the ABC for all transports. -- public child `DataStoreServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataStoreServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataStoreServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataStoreServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataStoreServiceTransport`` is the ABC for all transports. + +- public child ``DataStoreServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataStoreServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataStoreServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataStoreServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/base.py index 3bc0c9b6e3ad..22b3cf773ca6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc.py index 2fe1a734933f..19f5df9ef593 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc_asyncio.py index 497b9e11a8d0..839ef6dfec29 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/rest.py index 2bf7ac133a82..6f20054b3626 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/data_store_service/transports/rest.py @@ -510,6 +510,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataStoreServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py index 405d08724dca..1d3ed751c765 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> DocumentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1337,7 +1337,7 @@ async def sample_batch_get_documents_metadata(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1363,8 +1363,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1377,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1381,7 +1385,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1392,7 +1396,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1418,8 +1422,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1428,7 +1436,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1436,7 +1444,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1447,7 +1455,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1476,8 +1484,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1486,7 +1498,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1494,7 +1506,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py index 88f3dac83526..4379e7dad0cd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py @@ -126,7 +126,7 @@ class DocumentServiceClient(metaclass=DocumentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -531,7 +535,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -628,7 +632,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -726,7 +730,7 @@ def __init__( self._universe_domain = DocumentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1832,7 +1836,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1858,8 +1862,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1868,7 +1876,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1877,7 +1885,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1891,7 +1899,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1917,8 +1925,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1927,7 +1939,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1936,7 +1948,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1950,7 +1962,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1979,8 +1991,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1989,7 +2005,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1997,7 +2013,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/README.rst index 4aabee4652ef..765422bd31c7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentServiceTransport` is the ABC for all transports. -- public child `DocumentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentServiceTransport`` is the ABC for all transports. + +- public child ``DocumentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py index 8d1f5fcb3e71..91f1c8b018f7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py index 65601cd70459..abf08af0c07e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py index 9ad5ad6b3ae3..feda9cca2ddb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py index 204304b0e2ec..9c0fc8b8ced3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py @@ -643,6 +643,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/async_client.py index aab7c08407b3..80cd01d6dd6e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> EngineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -997,7 +997,7 @@ async def sample_list_engines(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1023,8 +1023,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1033,7 +1037,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1041,7 +1045,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1052,7 +1056,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1078,8 +1082,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1088,7 +1096,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1096,7 +1104,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1107,7 +1115,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1136,8 +1144,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1146,7 +1158,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1154,7 +1166,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/client.py index a6861a2271c8..4f38ece14910 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/client.py @@ -120,7 +120,7 @@ class EngineServiceClient(metaclass=EngineServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -471,7 +475,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = EngineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1449,7 +1453,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1475,8 +1479,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1485,7 +1493,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1494,7 +1502,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1508,7 +1516,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1534,8 +1542,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1544,7 +1556,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1553,7 +1565,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1567,7 +1579,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1596,8 +1608,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1606,7 +1622,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1614,7 +1630,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/README.rst index e23db35aec58..746aff382ff2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EngineServiceTransport` is the ABC for all transports. -- public child `EngineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EngineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEngineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EngineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EngineServiceTransport`` is the ABC for all transports. + +- public child ``EngineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EngineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEngineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EngineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/base.py index 59b321a6a6ab..f74d8bf43e1d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc.py index ae59f995c113..aba2457204be 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc_asyncio.py index 1194c88d4b74..3874dc9998a6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/rest.py index 81b53c2226d3..784a3645575e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/engine_service/transports/rest.py @@ -498,6 +498,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EngineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/async_client.py index 96d8346668a9..7346a1c2a0ce 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> GroundedGenerationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -604,7 +604,7 @@ async def sample_check_grounding(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -630,8 +630,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -640,7 +644,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -648,7 +652,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -659,7 +663,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -685,8 +689,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -695,7 +703,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -703,7 +711,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -714,7 +722,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -743,8 +751,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -753,7 +765,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -761,7 +773,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/client.py index 50769f2988e8..a6df28241829 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/client.py @@ -113,7 +113,7 @@ class GroundedGenerationServiceClient(metaclass=GroundedGenerationServiceClientM """Service for grounded generation.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -479,7 +483,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -578,7 +582,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -680,7 +684,7 @@ def __init__( self._universe_domain = GroundedGenerationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1062,7 +1066,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1088,8 +1092,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1098,7 +1106,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1107,7 +1115,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1121,7 +1129,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1147,8 +1155,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1157,7 +1169,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1166,7 +1178,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1180,7 +1192,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1209,8 +1221,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1219,7 +1235,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1227,7 +1243,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/README.rst index 5975f92cd7d1..ab3f17900b7f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GroundedGenerationServiceTransport` is the ABC for all transports. -- public child `GroundedGenerationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GroundedGenerationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGroundedGenerationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GroundedGenerationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GroundedGenerationServiceTransport`` is the ABC for all transports. + +- public child ``GroundedGenerationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GroundedGenerationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGroundedGenerationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GroundedGenerationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/base.py index 07c5dbe5db1a..6445e7a6d271 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc.py index ae1fff974da5..9deab83a327f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc_asyncio.py index 0392fa66d9f8..1672b07d2100 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/rest.py index d7b921d00915..9a38d53e4cb9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/grounded_generation_service/transports/rest.py @@ -342,6 +342,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GroundedGenerationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/async_client.py index 36773f509876..a7a791ecca04 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/async_client.py @@ -236,7 +236,7 @@ def transport(self) -> IdentityMappingStoreServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1225,7 +1225,7 @@ async def sample_list_identity_mapping_stores(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1251,8 +1251,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1261,7 +1265,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1269,7 +1273,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1280,7 +1284,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1306,8 +1310,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1316,7 +1324,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1324,7 +1332,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1335,7 +1343,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1364,8 +1372,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1374,7 +1386,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1382,7 +1394,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/client.py index 7fddef8d7e95..bacf1908adef 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/client.py @@ -128,7 +128,7 @@ class IdentityMappingStoreServiceClient( """Service for managing Identity Mapping Stores.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -539,7 +543,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -638,7 +642,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -740,7 +744,7 @@ def __init__( self._universe_domain = IdentityMappingStoreServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1719,7 +1723,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1745,8 +1749,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1755,7 +1763,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1764,7 +1772,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1778,7 +1786,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1804,8 +1812,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1814,7 +1826,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1823,7 +1835,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1837,7 +1849,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1866,8 +1878,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1876,7 +1892,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1884,7 +1900,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/README.rst index c9f43c0d0c29..a9970eb8e2e8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IdentityMappingStoreServiceTransport` is the ABC for all transports. -- public child `IdentityMappingStoreServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IdentityMappingStoreServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIdentityMappingStoreServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IdentityMappingStoreServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IdentityMappingStoreServiceTransport`` is the ABC for all transports. + +- public child ``IdentityMappingStoreServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IdentityMappingStoreServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIdentityMappingStoreServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IdentityMappingStoreServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/base.py index 608e9031cfcd..12569fbab892 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc.py index 4f7a306d9f12..791176a71e4b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc_asyncio.py index 31630b32346e..4df79485efbc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/rest.py index 730252fde194..c6aaec743e6b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/identity_mapping_store_service/transports/rest.py @@ -639,6 +639,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IdentityMappingStoreServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/async_client.py index ec4558bb9cd1..f12a1cf563c0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> ProjectServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -438,7 +438,7 @@ async def sample_provision_project(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -464,8 +464,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -474,7 +478,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -482,7 +486,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -493,7 +497,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -519,8 +523,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -529,7 +537,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -537,7 +545,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -548,7 +556,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -577,8 +585,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -587,7 +599,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -595,7 +607,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/client.py index fadb617598a3..5c21e387aa70 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/client.py @@ -115,7 +115,7 @@ class ProjectServiceClient(metaclass=ProjectServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -530,7 +534,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( self._universe_domain = ProjectServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -871,7 +875,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -897,8 +901,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -907,7 +915,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -916,7 +924,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -930,7 +938,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -956,8 +964,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -966,7 +978,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -975,7 +987,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -989,7 +1001,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1018,8 +1030,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1028,7 +1044,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1036,7 +1052,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/README.rst index e8af52d6e307..f5907a88e7e8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProjectServiceTransport` is the ABC for all transports. -- public child `ProjectServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProjectServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProjectServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProjectServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProjectServiceTransport`` is the ABC for all transports. + +- public child ``ProjectServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProjectServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProjectServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProjectServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/base.py index 46aed4832d39..a5fa4948dc14 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc.py index 20180a1891c8..a0d863e71a90 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc_asyncio.py index 8f554808682f..018ddfcdd404 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/rest.py index 10d1aedea0ec..bc3972dd60bd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/project_service/transports/rest.py @@ -277,6 +277,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProjectServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/async_client.py index c991a562dda4..2090791e9f83 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> RankServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -384,7 +384,7 @@ async def sample_rank(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -410,8 +410,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -420,7 +424,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -428,7 +432,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -439,7 +443,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -465,8 +469,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -475,7 +483,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -483,7 +491,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -494,7 +502,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -523,8 +531,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -533,7 +545,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -541,7 +553,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/client.py index eb2ec6938f87..932672c51b55 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/client.py @@ -111,7 +111,7 @@ class RankServiceClient(metaclass=RankServiceClientMeta): """Service for ranking text records.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -436,7 +440,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -533,7 +537,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -629,7 +633,7 @@ def __init__( self._universe_domain = RankServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -826,7 +830,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -852,8 +856,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -862,7 +870,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -871,7 +879,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -885,7 +893,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -911,8 +919,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -921,7 +933,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -930,7 +942,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -944,7 +956,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -973,8 +985,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -983,7 +999,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -991,7 +1007,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/README.rst index 5103092608ec..01379c3e3dc3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RankServiceTransport` is the ABC for all transports. -- public child `RankServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RankServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRankServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RankServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RankServiceTransport`` is the ABC for all transports. + +- public child ``RankServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RankServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRankServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RankServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/base.py index 8ec782153d25..2cf1faca60f9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc.py index 40c03d1a0a98..083441e4f496 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc_asyncio.py index 27b8c1f06443..011b83ef08d1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/rest.py index 17f3ba62efaf..d36d8d11e1af 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/rank_service/transports/rest.py @@ -274,6 +274,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RankServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/async_client.py index f96da53cefe5..815955021af0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> RecommendationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -408,7 +408,7 @@ async def sample_recommend(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -434,8 +434,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -444,7 +448,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -452,7 +456,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -463,7 +467,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -489,8 +493,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -499,7 +507,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -507,7 +515,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -518,7 +526,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -547,8 +555,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -557,7 +569,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -565,7 +577,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/client.py index 3e76334c85b9..dfee4b60e769 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/client.py @@ -111,7 +111,7 @@ class RecommendationServiceClient(metaclass=RecommendationServiceClientMeta): """Service for making recommendations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -510,7 +514,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -609,7 +613,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -709,7 +713,7 @@ def __init__( self._universe_domain = RecommendationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -912,7 +916,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -938,8 +942,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -948,7 +956,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -957,7 +965,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -971,7 +979,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -997,8 +1005,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1007,7 +1019,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1016,7 +1028,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1030,7 +1042,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1071,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1085,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1077,7 +1093,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/README.rst index 07e52e0896bb..9dff1804700e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RecommendationServiceTransport` is the ABC for all transports. -- public child `RecommendationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RecommendationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRecommendationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RecommendationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RecommendationServiceTransport`` is the ABC for all transports. + +- public child ``RecommendationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RecommendationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRecommendationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RecommendationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/base.py index 8c76810dd732..4f429b8eb811 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc.py index 32fd9d9d20d3..6222363675a7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc_asyncio.py index 00c1040d1029..6367cccacae2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/rest.py index e121d2ad9933..764f9e36ae81 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/recommendation_service/transports/rest.py @@ -279,6 +279,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RecommendationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py index fdd8ae5b03a8..e2df1f459dea 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> SchemaServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -946,7 +946,7 @@ async def sample_delete_schema(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -972,8 +972,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -982,7 +986,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -990,7 +994,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1001,7 +1005,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1031,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1045,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1053,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1056,7 +1064,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1085,8 +1093,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1095,7 +1107,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1103,7 +1115,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py index 28984a8521dc..b08c4080a09a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py @@ -119,7 +119,7 @@ class SchemaServiceClient(metaclass=SchemaServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = SchemaServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1397,7 +1401,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1423,8 +1427,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1441,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1442,7 +1450,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1456,7 +1464,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1482,8 +1490,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1492,7 +1504,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1501,7 +1513,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1515,7 +1527,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1544,8 +1556,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1554,7 +1570,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1562,7 +1578,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/README.rst index a0a06949e679..a3c2df942aa3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SchemaServiceTransport` is the ABC for all transports. -- public child `SchemaServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SchemaServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSchemaServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SchemaServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SchemaServiceTransport`` is the ABC for all transports. + +- public child ``SchemaServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SchemaServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSchemaServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SchemaServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py index a656c50a5828..365bcc40441a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py index 0f6f919718cd..b24a79920e20 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py index 910c630c5f69..fc37ce95b207 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py index f0361cf358f4..0ff1456011fb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py @@ -499,6 +499,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SchemaServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py index d273b69f6045..b09dbef466df 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SearchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -532,7 +532,7 @@ async def sample_search_lite(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -558,8 +558,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -568,7 +572,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -576,7 +580,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -587,7 +591,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -613,8 +617,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -623,7 +631,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -631,7 +639,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -642,7 +650,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -671,8 +679,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -681,7 +693,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -689,7 +701,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py index 33daab8ddab5..2f501e3dd1b9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py @@ -112,7 +112,7 @@ class SearchServiceClient(metaclass=SearchServiceClientMeta): """Service for search.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -563,7 +567,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -660,7 +664,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -756,7 +760,7 @@ def __init__( self._universe_domain = SearchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1087,7 +1091,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1113,8 +1117,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1123,7 +1131,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1132,7 +1140,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1146,7 +1154,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1172,8 +1180,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1182,7 +1194,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1191,7 +1203,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1205,7 +1217,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1234,8 +1246,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1244,7 +1260,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1252,7 +1268,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/README.rst index 8ef0891e3c25..9f2873332607 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SearchServiceTransport` is the ABC for all transports. -- public child `SearchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SearchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSearchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SearchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SearchServiceTransport`` is the ABC for all transports. + +- public child ``SearchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SearchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSearchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SearchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py index cb311690d5f3..3fe5e7bc84cb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py index 6f2b0a432c19..ce5c68852f02 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py index 023fa53f0633..e715f0e16d93 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py index db80fada9e9d..bc2d8a5bbd78 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py @@ -328,6 +328,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SearchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/async_client.py index 83c98590e4bc..19bdee246310 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> SearchTuningServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -515,7 +515,7 @@ async def sample_list_custom_models(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -541,8 +541,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -551,7 +555,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -559,7 +563,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -570,7 +574,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -596,8 +600,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -606,7 +614,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -614,7 +622,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -625,7 +633,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -654,8 +662,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -664,7 +676,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -672,7 +684,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/client.py index cb42d45e0b35..07d4ff805ffd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/client.py @@ -116,7 +116,7 @@ class SearchTuningServiceClient(metaclass=SearchTuningServiceClientMeta): """Service for search tuning.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -562,7 +566,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = SearchTuningServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -969,7 +973,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -995,8 +999,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1005,7 +1013,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1014,7 +1022,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1028,7 +1036,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1062,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1076,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1073,7 +1085,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1087,7 +1099,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1116,8 +1128,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1126,7 +1142,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1134,7 +1150,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/README.rst index eef506f0f655..774bfa0d9ce6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SearchTuningServiceTransport` is the ABC for all transports. -- public child `SearchTuningServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SearchTuningServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSearchTuningServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SearchTuningServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SearchTuningServiceTransport`` is the ABC for all transports. + +- public child ``SearchTuningServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SearchTuningServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSearchTuningServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SearchTuningServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/base.py index a3a89e0763b5..8b6d5afb7eb3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc.py index 661c6737fc1e..4a6b3b173f9b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc_asyncio.py index e5d052c9dfa5..5c90530063b9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/rest.py index b1d581e030b3..3f8c9fd1d17c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_tuning_service/transports/rest.py @@ -337,6 +337,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SearchTuningServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/async_client.py index 452559dfff23..f664596c6472 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ServingConfigServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -451,7 +451,7 @@ async def sample_update_serving_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -477,8 +477,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -487,7 +491,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -495,7 +499,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -506,7 +510,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -532,8 +536,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -542,7 +550,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -550,7 +558,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -561,7 +569,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -590,8 +598,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -600,7 +612,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -608,7 +620,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/client.py index 0e7e6692e1ed..d04c6711a8ef 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/client.py @@ -116,7 +116,7 @@ class ServingConfigServiceClient(metaclass=ServingConfigServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -640,7 +644,7 @@ def __init__( self._universe_domain = ServingConfigServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -890,7 +894,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -916,8 +920,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -926,7 +934,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -935,7 +943,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -949,7 +957,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -975,8 +983,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -985,7 +997,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -994,7 +1006,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1008,7 +1020,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1037,8 +1049,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1047,7 +1063,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1055,7 +1071,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/README.rst index 0581bb81c691..5641722cda1e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServingConfigServiceTransport` is the ABC for all transports. -- public child `ServingConfigServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServingConfigServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServingConfigServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServingConfigServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServingConfigServiceTransport`` is the ABC for all transports. + +- public child ``ServingConfigServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServingConfigServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServingConfigServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServingConfigServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/base.py index e521dfb1fadb..f9c7ad1bc33c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc.py index 018b75549665..adcb36669cd0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc_asyncio.py index e8093083ed15..a8ccd0f71c13 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/rest.py index 8f87ea9e4109..be5ed35c894c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/serving_config_service/transports/rest.py @@ -281,6 +281,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ServingConfigServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/async_client.py index a576f1ed2e81..5156ae43cad9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> SessionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -907,7 +907,7 @@ async def sample_list_sessions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -933,8 +933,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -943,7 +947,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -951,7 +955,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -962,7 +966,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -988,8 +992,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -998,7 +1006,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1006,7 +1014,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1017,7 +1025,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1046,8 +1054,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1056,7 +1068,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1064,7 +1076,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/client.py index 5341a08f7337..9df854ff8881 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/client.py @@ -115,7 +115,7 @@ class SessionServiceClient(metaclass=SessionServiceClientMeta): """Service for managing Sessions and Session-related resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -572,7 +576,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -669,7 +673,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -765,7 +769,7 @@ def __init__( self._universe_domain = SessionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1455,7 +1459,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1481,8 +1485,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1491,7 +1499,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1500,7 +1508,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1514,7 +1522,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1540,8 +1548,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1550,7 +1562,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1559,7 +1571,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1573,7 +1585,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1602,8 +1614,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1612,7 +1628,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1620,7 +1636,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/README.rst index f67320e75a5d..ec396d9ed40d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionServiceTransport` is the ABC for all transports. -- public child `SessionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionServiceTransport`` is the ABC for all transports. + +- public child ``SessionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/base.py index e445d62f61a1..e7bbaee18c75 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc.py index 61404f493c9d..d038a7c7180a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc_asyncio.py index a8421d84a150..cfb5c96850bd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/rest.py index 9a4bfb27f61c..4c8cc1cc4b52 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/session_service/transports/rest.py @@ -466,6 +466,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/async_client.py index 217a15961051..fab93324c66b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> SiteSearchEngineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2227,7 +2227,7 @@ async def sample_fetch_domain_verification_status(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2253,8 +2253,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2263,7 +2267,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2271,7 +2275,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2282,7 +2286,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2308,8 +2312,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2318,7 +2326,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2326,7 +2334,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2337,7 +2345,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2366,8 +2374,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2376,7 +2388,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2384,7 +2396,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/client.py index 9e3469155f67..e08cd35d4def 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/client.py @@ -119,7 +119,7 @@ class SiteSearchEngineServiceClient(metaclass=SiteSearchEngineServiceClientMeta) """Service for managing site search related resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -492,7 +496,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -591,7 +595,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -693,7 +697,7 @@ def __init__( self._universe_domain = SiteSearchEngineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2674,7 +2678,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2700,8 +2704,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2710,7 +2718,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2719,7 +2727,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2733,7 +2741,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2759,8 +2767,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2769,7 +2781,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2778,7 +2790,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2792,7 +2804,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2821,8 +2833,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2831,7 +2847,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2839,7 +2855,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/README.rst index 2a7b3fa91582..9c4a098942bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SiteSearchEngineServiceTransport` is the ABC for all transports. -- public child `SiteSearchEngineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SiteSearchEngineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSiteSearchEngineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SiteSearchEngineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SiteSearchEngineServiceTransport`` is the ABC for all transports. + +- public child ``SiteSearchEngineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SiteSearchEngineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSiteSearchEngineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SiteSearchEngineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/base.py index 02c7c6d992ff..e20a792ba423 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc.py index e2da5052cbc1..14d7b8355dae 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc_asyncio.py index dccb9b396db2..85ed0b2368b5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/rest.py index 527de9a148bb..61dd484aaf7f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/site_search_engine_service/transports/rest.py @@ -1089,6 +1089,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SiteSearchEngineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py index 56af79286ffa..6547d6cd5dbe 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> UserEventServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -764,7 +764,7 @@ async def sample_import_user_events(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -790,8 +790,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -800,7 +804,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -808,7 +812,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -819,7 +823,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -845,8 +849,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -855,7 +863,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -863,7 +871,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -874,7 +882,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -903,8 +911,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -913,7 +925,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -921,7 +933,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py index b4a078faf4b4..b0edbd9310d3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py @@ -124,7 +124,7 @@ class UserEventServiceClient(metaclass=UserEventServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -499,7 +503,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -596,7 +600,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -694,7 +698,7 @@ def __init__( self._universe_domain = UserEventServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1246,7 +1250,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1276,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1290,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1291,7 +1299,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1305,7 +1313,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1331,8 +1339,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1341,7 +1353,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1350,7 +1362,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1376,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1393,8 +1405,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,7 +1419,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1411,7 +1427,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/README.rst index 45f0ef746528..c6e23fe5f03f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserEventServiceTransport` is the ABC for all transports. -- public child `UserEventServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserEventServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserEventServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserEventServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserEventServiceTransport`` is the ABC for all transports. + +- public child ``UserEventServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserEventServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserEventServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserEventServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py index 7448f018ff22..8c186793b1cb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py index 5625f87121bc..19194c91fcde 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py index 7c9fff2fd578..e84c3502ce7c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py index 0ff07b94bbd1..859aa831a26f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py @@ -453,6 +453,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserEventServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/async_client.py index 6ce7728210a3..0ed0b4bf4f34 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> UserLicenseServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -549,7 +549,7 @@ async def sample_batch_update_user_licenses(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -575,8 +575,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -585,7 +589,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -593,7 +597,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -604,7 +608,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -630,8 +634,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -640,7 +648,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -648,7 +656,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -659,7 +667,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -688,8 +696,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -698,7 +710,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -706,7 +718,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/client.py index 6b489f39880b..f943cd1c398a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/client.py @@ -114,7 +114,7 @@ class UserLicenseServiceClient(metaclass=UserLicenseServiceClientMeta): """Service for managing User Licenses.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -658,7 +662,7 @@ def __init__( self._universe_domain = UserLicenseServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1006,7 +1010,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1032,8 +1036,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1042,7 +1050,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1051,7 +1059,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1065,7 +1073,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,8 +1099,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1101,7 +1113,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1122,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1136,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1153,8 +1165,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,7 +1179,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1171,7 +1187,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/README.rst index ce69293eb16d..41c3b098d77d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserLicenseServiceTransport` is the ABC for all transports. -- public child `UserLicenseServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserLicenseServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserLicenseServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserLicenseServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserLicenseServiceTransport`` is the ABC for all transports. + +- public child ``UserLicenseServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserLicenseServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserLicenseServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserLicenseServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/base.py index 7a0c399209d9..f23fff30b700 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc.py index 15c1c4876943..e2868ce8e2de 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc_asyncio.py index 044f9c0d47a4..6c485144417a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/rest.py index 10725af4b2cc..8921ba9e6dff 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_license_service/transports/rest.py @@ -337,6 +337,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserLicenseServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/async_client.py index ceba61a2cf62..787f5b6fbc35 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> AclConfigServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -509,7 +509,7 @@ async def sample_get_acl_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -535,8 +535,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -545,7 +549,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -553,7 +557,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -564,7 +568,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -590,8 +594,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -600,7 +608,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -608,7 +616,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -619,7 +627,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -648,8 +656,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -658,7 +670,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -666,7 +678,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/client.py index 91736c1b5c07..9a1e95232ef1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/client.py @@ -115,7 +115,7 @@ class AclConfigServiceClient(metaclass=AclConfigServiceClientMeta): """Service for managing Acl Configuration.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -632,7 +636,7 @@ def __init__( self._universe_domain = AclConfigServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -945,7 +949,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -971,8 +975,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -981,7 +989,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -990,7 +998,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1004,7 +1012,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1030,8 +1038,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1040,7 +1052,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1049,7 +1061,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1063,7 +1075,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1092,8 +1104,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1102,7 +1118,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1126,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/README.rst index bf9203b9ab2c..27930d4db5ee 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AclConfigServiceTransport` is the ABC for all transports. -- public child `AclConfigServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AclConfigServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAclConfigServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AclConfigServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AclConfigServiceTransport`` is the ABC for all transports. + +- public child ``AclConfigServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AclConfigServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAclConfigServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AclConfigServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/base.py index cedd0381f98c..3ae93beb73d9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc.py index 690f9177c77b..1039f8c7ca6e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc_asyncio.py index 4360f2c52f9c..c7eac9cfe08f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/rest.py index 1384e40ffc6d..1306aebe3e50 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/acl_config_service/transports/rest.py @@ -333,6 +333,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AclConfigServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/async_client.py index 3c36e6d33fd5..999d533bd924 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/async_client.py @@ -190,7 +190,7 @@ def transport(self) -> ChunkServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -560,7 +560,7 @@ async def sample_list_chunks(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -586,8 +586,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -596,7 +600,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -604,7 +608,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -615,7 +619,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -641,8 +645,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -651,7 +659,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -659,7 +667,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -670,7 +678,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -699,8 +707,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -709,7 +721,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -717,7 +729,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/client.py index 675ff0ed9644..49d315ef646e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/client.py @@ -116,7 +116,7 @@ class ChunkServiceClient(metaclass=ChunkServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -473,7 +477,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -570,7 +574,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -666,7 +670,7 @@ def __init__( self._universe_domain = ChunkServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1028,7 +1032,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1058,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1072,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1073,7 +1081,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1087,7 +1095,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1113,8 +1121,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1123,7 +1135,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1132,7 +1144,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1146,7 +1158,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1175,8 +1187,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1185,7 +1201,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1193,7 +1209,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/README.rst index bab28c9c32e4..bad929b1ef6e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ChunkServiceTransport` is the ABC for all transports. -- public child `ChunkServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ChunkServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseChunkServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ChunkServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ChunkServiceTransport`` is the ABC for all transports. + +- public child ``ChunkServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ChunkServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseChunkServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ChunkServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/base.py index c336bae22563..c713240c3752 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc.py index ca6d1de32de6..f91661111cfa 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc_asyncio.py index 0875a3d6df2d..23e84f5ff7c4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/rest.py index e0a991595fb3..e237318a9c77 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/chunk_service/transports/rest.py @@ -330,6 +330,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ChunkServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py index c117654ed551..1cff616b6347 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> CompletionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -838,7 +838,7 @@ async def sample_purge_completion_suggestions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -864,8 +864,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -874,7 +878,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -882,7 +886,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -893,7 +897,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -919,8 +923,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -929,7 +937,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -937,7 +945,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -948,7 +956,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -977,8 +985,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -987,7 +999,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -995,7 +1007,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py index 13d60b45a582..fc8fe0911298 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py @@ -117,7 +117,7 @@ class CompletionServiceClient(metaclass=CompletionServiceClientMeta): """Service for Auto-Completion.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -539,7 +543,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = CompletionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1280,7 +1284,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1306,8 +1310,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1316,7 +1324,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1325,7 +1333,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1339,7 +1347,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1365,8 +1373,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1375,7 +1387,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1384,7 +1396,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1398,7 +1410,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1427,8 +1439,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1437,7 +1453,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1445,7 +1461,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/README.rst index 3f71883905ca..3d1e4e840e1a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CompletionServiceTransport` is the ABC for all transports. -- public child `CompletionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CompletionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCompletionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CompletionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CompletionServiceTransport`` is the ABC for all transports. + +- public child ``CompletionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CompletionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCompletionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CompletionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py index 4397648dd17a..723847389821 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py index 7ea49500c0d4..c2df6e2b60ad 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py index 66deca2f1c41..b4313b7c1549 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py index f37365589020..332e70995880 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py @@ -511,6 +511,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CompletionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/async_client.py index df0da30b48fb..de527f3a6f5c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ControlServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -943,7 +943,7 @@ async def sample_list_controls(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -969,8 +969,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -979,7 +983,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -987,7 +991,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -998,7 +1002,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1024,8 +1028,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1034,7 +1042,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1042,7 +1050,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1053,7 +1061,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1082,8 +1090,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1092,7 +1104,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1100,7 +1112,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/client.py index 230553ce1773..eb8efd098955 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/client.py @@ -118,7 +118,7 @@ class ControlServiceClient(metaclass=ControlServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = ControlServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1393,7 +1397,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1419,8 +1423,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1429,7 +1437,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1438,7 +1446,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1452,7 +1460,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1478,8 +1486,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1488,7 +1500,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1497,7 +1509,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1511,7 +1523,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1540,8 +1552,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1550,7 +1566,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1558,7 +1574,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/README.rst index ee9c627694ad..099231a14c2f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ControlServiceTransport` is the ABC for all transports. -- public child `ControlServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ControlServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseControlServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ControlServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ControlServiceTransport`` is the ABC for all transports. + +- public child ``ControlServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ControlServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseControlServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ControlServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/base.py index 2703ee92ec4e..dfc15e8038e8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc.py index 5f6c6044992a..57c9c57301b4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc_asyncio.py index 5d3090593277..18955b9e7a89 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/rest.py index 57cae66c0172..cfd2851655a5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/control_service/transports/rest.py @@ -463,6 +463,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ControlServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py index 1ce86cdeec12..804b8ced1d55 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py @@ -242,7 +242,7 @@ def transport(self) -> ConversationalSearchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1903,7 +1903,7 @@ async def sample_list_sessions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1929,8 +1929,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1939,7 +1943,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1947,7 +1951,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1958,7 +1962,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1984,8 +1988,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1994,7 +2002,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2002,7 +2010,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2013,7 +2021,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2042,8 +2050,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2052,7 +2064,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2060,7 +2072,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py index b4446bcfa866..504d5261f9ca 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py @@ -128,7 +128,7 @@ class ConversationalSearchServiceClient( """Service for conversational search.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -605,7 +609,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -704,7 +708,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -806,7 +810,7 @@ def __init__( self._universe_domain = ConversationalSearchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2429,7 +2433,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2455,8 +2459,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2465,7 +2473,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2474,7 +2482,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2488,7 +2496,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2514,8 +2522,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2524,7 +2536,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2533,7 +2545,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2547,7 +2559,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2576,8 +2588,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2586,7 +2602,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2594,7 +2610,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/README.rst index f8f6d58a0c64..99a63d05709f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationalSearchServiceTransport` is the ABC for all transports. -- public child `ConversationalSearchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationalSearchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationalSearchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationalSearchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationalSearchServiceTransport`` is the ABC for all transports. + +- public child ``ConversationalSearchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationalSearchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationalSearchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationalSearchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py index c564d0802694..3fa187bc9e3a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py index c565de9a8d36..cde7e98fbe6d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py index 7524be43cabd..07b0a942daeb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py index 8eb38647eaa8..ad00953dd16e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py @@ -897,6 +897,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationalSearchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py index 7ca137f76370..716e4359dfa5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> DataStoreServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1337,7 +1337,7 @@ async def sample_update_document_processing_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1363,8 +1363,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1377,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1381,7 +1385,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1392,7 +1396,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1418,8 +1422,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1428,7 +1436,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1436,7 +1444,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1447,7 +1455,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1476,8 +1484,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1486,7 +1498,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1494,7 +1506,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py index 8551cd2c1488..10dfebce3bd2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py @@ -130,7 +130,7 @@ class DataStoreServiceClient(metaclass=DataStoreServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -525,7 +529,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -622,7 +626,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -720,7 +724,7 @@ def __init__( self._universe_domain = DataStoreServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1824,7 +1828,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1850,8 +1854,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1860,7 +1868,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1869,7 +1877,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1883,7 +1891,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1909,8 +1917,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1919,7 +1931,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1928,7 +1940,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1942,7 +1954,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1971,8 +1983,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1981,7 +1997,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1989,7 +2005,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/README.rst index 7b7cd44d7eab..aaa93b7f76f6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataStoreServiceTransport` is the ABC for all transports. -- public child `DataStoreServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataStoreServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataStoreServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataStoreServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataStoreServiceTransport`` is the ABC for all transports. + +- public child ``DataStoreServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataStoreServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataStoreServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataStoreServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py index 08c03b56c711..ebe73ba4be26 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py index 19a29af2ff9a..3d086ed943a6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py index a7e0993e1559..af35584920bd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py index 411dc4a9ca40..b9b7bc4fa244 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py @@ -637,6 +637,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataStoreServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py index 0ca03fcdde9a..c6a1b4d50f1b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py @@ -206,7 +206,7 @@ def transport(self) -> DocumentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1466,7 +1466,7 @@ async def sample_batch_get_documents_metadata(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1492,8 +1492,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1502,7 +1506,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1510,7 +1514,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1521,7 +1525,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1547,8 +1551,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1557,7 +1565,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1565,7 +1573,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1576,7 +1584,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1605,8 +1613,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1615,7 +1627,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1623,7 +1635,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py index 5090002c5738..10b49b2aeda5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py @@ -126,7 +126,7 @@ class DocumentServiceClient(metaclass=DocumentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -503,7 +507,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -600,7 +604,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -698,7 +702,7 @@ def __init__( self._universe_domain = DocumentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1934,7 +1938,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1960,8 +1964,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1970,7 +1978,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1979,7 +1987,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1993,7 +2001,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2019,8 +2027,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2029,7 +2041,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2038,7 +2050,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2052,7 +2064,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2081,8 +2093,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2091,7 +2107,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2099,7 +2115,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/README.rst index 4aabee4652ef..765422bd31c7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentServiceTransport` is the ABC for all transports. -- public child `DocumentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentServiceTransport`` is the ABC for all transports. + +- public child ``DocumentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py index 603833a7777d..27bbc5e1137d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py index 4c53ec3ef7f0..46ba692fa236 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py index 50adb6c7009c..57947294e089 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py index a7f3adf0932b..eb29bdbeba09 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py @@ -700,6 +700,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py index d1c35b4be7d0..01466a870c3f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> EngineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1360,7 +1360,7 @@ async def sample_tune_engine(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1386,8 +1386,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1396,7 +1400,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1404,7 +1408,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1415,7 +1419,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1441,8 +1445,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1451,7 +1459,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1459,7 +1467,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1470,7 +1478,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1499,8 +1507,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1509,7 +1521,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1517,7 +1529,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py index fa598f001590..353756913ce3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py @@ -120,7 +120,7 @@ class EngineServiceClient(metaclass=EngineServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -471,7 +475,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = EngineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1803,7 +1807,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1829,8 +1833,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1839,7 +1847,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1848,7 +1856,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1862,7 +1870,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1888,8 +1896,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1898,7 +1910,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1907,7 +1919,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1921,7 +1933,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1950,8 +1962,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1960,7 +1976,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1968,7 +1984,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/README.rst index e23db35aec58..746aff382ff2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EngineServiceTransport` is the ABC for all transports. -- public child `EngineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EngineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEngineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EngineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EngineServiceTransport`` is the ABC for all transports. + +- public child ``EngineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EngineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEngineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EngineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py index 451a8ce6ce18..10fcde36ae27 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py index 565fb01e454c..a6cfc99e71b2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py index bd1a08c71af9..a38438eac874 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py index 0c37c8eabd6d..6564846a4ed2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py @@ -658,6 +658,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EngineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/async_client.py index d19e3c8658d8..78b70048dabc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> EstimateBillingServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -415,7 +415,7 @@ async def sample_estimate_data_size(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -441,8 +441,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -451,7 +455,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -459,7 +463,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -470,7 +474,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -496,8 +500,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -506,7 +514,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -514,7 +522,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -525,7 +533,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -554,8 +562,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -564,7 +576,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -572,7 +584,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/client.py index 6e70990a880a..cb76f41eab9c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/client.py @@ -113,7 +113,7 @@ class EstimateBillingServiceClient(metaclass=EstimateBillingServiceClientMeta): """Service for managing billing estimations resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -532,7 +536,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -632,7 +636,7 @@ def __init__( self._universe_domain = EstimateBillingServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -848,7 +852,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -874,8 +878,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -884,7 +892,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -893,7 +901,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -907,7 +915,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -933,8 +941,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -943,7 +955,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -952,7 +964,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -966,7 +978,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -995,8 +1007,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1005,7 +1021,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1013,7 +1029,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/README.rst index 1b83b6658481..35f9575389d0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EstimateBillingServiceTransport` is the ABC for all transports. -- public child `EstimateBillingServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EstimateBillingServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEstimateBillingServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EstimateBillingServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EstimateBillingServiceTransport`` is the ABC for all transports. + +- public child ``EstimateBillingServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EstimateBillingServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEstimateBillingServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EstimateBillingServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/base.py index 8b3a0394d23f..0c0b23b1d313 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc.py index 1511693abd37..2bb52d36c952 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc_asyncio.py index 940de33439ee..31812b9e03c0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/rest.py index 291156325f30..49202f011421 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/estimate_billing_service/transports/rest.py @@ -277,6 +277,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EstimateBillingServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/async_client.py index aba58e33d8b3..e42a4b87d339 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> EvaluationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -879,7 +879,7 @@ async def sample_list_evaluation_results(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -905,8 +905,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -915,7 +919,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -923,7 +927,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -934,7 +938,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -960,8 +964,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -970,7 +978,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -978,7 +986,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -989,7 +997,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1018,8 +1026,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1028,7 +1040,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1036,7 +1048,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/client.py index 9902123196f9..7d1bbb2bbee2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/client.py @@ -119,7 +119,7 @@ class EvaluationServiceClient(metaclass=EvaluationServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -603,7 +607,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -700,7 +704,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -800,7 +804,7 @@ def __init__( self._universe_domain = EvaluationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1450,7 +1454,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1476,8 +1480,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1486,7 +1494,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1495,7 +1503,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1509,7 +1517,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1535,8 +1543,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1545,7 +1557,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1554,7 +1566,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1568,7 +1580,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1597,8 +1609,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1607,7 +1623,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1615,7 +1631,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/README.rst index b012f0c5c184..21b6cc6a5fa7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EvaluationServiceTransport` is the ABC for all transports. -- public child `EvaluationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EvaluationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEvaluationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EvaluationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EvaluationServiceTransport`` is the ABC for all transports. + +- public child ``EvaluationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EvaluationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEvaluationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EvaluationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/base.py index 66e3da41d100..71db674af65a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc.py index abe9bef6ecbf..4904335a5d5c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc_asyncio.py index 9b67b710af3f..601a10550e45 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/rest.py index 247582add31f..2bfd7c83c79f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/evaluation_service/transports/rest.py @@ -454,6 +454,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EvaluationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/async_client.py index 3740033a93d7..fd7807a187a6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/async_client.py @@ -206,7 +206,7 @@ def transport(self) -> GroundedGenerationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -412,7 +412,7 @@ async def sample_check_grounding(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -438,8 +438,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -448,7 +452,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -456,7 +460,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -467,7 +471,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -493,8 +497,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -503,7 +511,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -511,7 +519,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -522,7 +530,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -551,8 +559,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -561,7 +573,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -569,7 +581,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/client.py index e2284f1c9c4b..9105cab68471 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/client.py @@ -114,7 +114,7 @@ class GroundedGenerationServiceClient(metaclass=GroundedGenerationServiceClientM """Service for grounded generation.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -439,7 +443,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -538,7 +542,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -640,7 +644,7 @@ def __init__( self._universe_domain = GroundedGenerationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -842,7 +846,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -868,8 +872,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -878,7 +886,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -887,7 +895,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -901,7 +909,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -927,8 +935,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -937,7 +949,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -946,7 +958,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -960,7 +972,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -989,8 +1001,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -999,7 +1015,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1007,7 +1023,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/README.rst index 5975f92cd7d1..ab3f17900b7f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GroundedGenerationServiceTransport` is the ABC for all transports. -- public child `GroundedGenerationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GroundedGenerationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGroundedGenerationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GroundedGenerationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GroundedGenerationServiceTransport`` is the ABC for all transports. + +- public child ``GroundedGenerationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GroundedGenerationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGroundedGenerationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GroundedGenerationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/base.py index 5758b88d33d4..0c0ed913360f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc.py index 6a93c5ba06b9..d37162a5af68 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc_asyncio.py index 32f5a99fa861..68108a1fe238 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/rest.py index 1eb5255ef26d..0b2e513faf0a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/grounded_generation_service/transports/rest.py @@ -282,6 +282,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GroundedGenerationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/async_client.py index 90b2132cffe2..d3411a2026d8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> ProjectServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -724,7 +724,7 @@ async def sample_report_consent_change(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -750,8 +750,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -760,7 +764,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -768,7 +772,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -779,7 +783,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -805,8 +809,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -815,7 +823,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -823,7 +831,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -834,7 +842,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -863,8 +871,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -873,7 +885,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -881,7 +893,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/client.py index 6f6a50731aeb..6a70773e9d4e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/client.py @@ -117,7 +117,7 @@ class ProjectServiceClient(metaclass=ProjectServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -435,7 +439,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -532,7 +536,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = ProjectServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1151,7 +1155,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1177,8 +1181,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1187,7 +1195,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1196,7 +1204,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1210,7 +1218,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1236,8 +1244,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1246,7 +1258,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1255,7 +1267,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1269,7 +1281,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1298,8 +1310,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1308,7 +1324,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1316,7 +1332,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/README.rst index e8af52d6e307..f5907a88e7e8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProjectServiceTransport` is the ABC for all transports. -- public child `ProjectServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProjectServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProjectServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProjectServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProjectServiceTransport`` is the ABC for all transports. + +- public child ``ProjectServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProjectServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProjectServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProjectServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/base.py index 980aaa827b57..f449f48fba0d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc.py index 3f02be789d03..53ba2504bfcf 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc_asyncio.py index f745047a47bd..397c4579ae9e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/rest.py index 5347c4252566..d0b85e89bdb6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/project_service/transports/rest.py @@ -389,6 +389,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProjectServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/async_client.py index 6e22b2f91e2c..3d435b73d821 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> RankServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -384,7 +384,7 @@ async def sample_rank(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -410,8 +410,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -420,7 +424,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -428,7 +432,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -439,7 +443,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -465,8 +469,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -475,7 +483,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -483,7 +491,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -494,7 +502,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -523,8 +531,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -533,7 +545,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -541,7 +553,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/client.py index 4ad7eb0234c3..c2ccb3215867 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/client.py @@ -111,7 +111,7 @@ class RankServiceClient(metaclass=RankServiceClientMeta): """Service for ranking text records.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -436,7 +440,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -533,7 +537,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -629,7 +633,7 @@ def __init__( self._universe_domain = RankServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -826,7 +830,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -852,8 +856,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -862,7 +870,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -871,7 +879,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -885,7 +893,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -911,8 +919,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -921,7 +933,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -930,7 +942,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -944,7 +956,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -973,8 +985,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -983,7 +999,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -991,7 +1007,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/README.rst index 5103092608ec..01379c3e3dc3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RankServiceTransport` is the ABC for all transports. -- public child `RankServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RankServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRankServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RankServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RankServiceTransport`` is the ABC for all transports. + +- public child ``RankServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RankServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRankServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RankServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/base.py index baae369fab4e..ebf12918209d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc.py index 6d31de27a950..cd07706c1122 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc_asyncio.py index a179765257b6..1672dfa87bb6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/rest.py index b2f2cabb22ed..5f0e37f646e4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/rank_service/transports/rest.py @@ -274,6 +274,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RankServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py index cd2572a50ff5..e69dcb0901d9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> RecommendationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -408,7 +408,7 @@ async def sample_recommend(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -434,8 +434,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -444,7 +448,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -452,7 +456,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -463,7 +467,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -489,8 +493,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -499,7 +507,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -507,7 +515,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -518,7 +526,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -547,8 +555,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -557,7 +569,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -565,7 +577,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py index 67462f7442a5..5d7bd3332c60 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py @@ -111,7 +111,7 @@ class RecommendationServiceClient(metaclass=RecommendationServiceClientMeta): """Service for making recommendations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -510,7 +514,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -609,7 +613,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -709,7 +713,7 @@ def __init__( self._universe_domain = RecommendationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -912,7 +916,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -938,8 +942,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -948,7 +956,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -957,7 +965,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -971,7 +979,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -997,8 +1005,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1007,7 +1019,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1016,7 +1028,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1030,7 +1042,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1071,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1085,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1077,7 +1093,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/README.rst index 07e52e0896bb..9dff1804700e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RecommendationServiceTransport` is the ABC for all transports. -- public child `RecommendationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RecommendationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRecommendationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RecommendationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RecommendationServiceTransport`` is the ABC for all transports. + +- public child ``RecommendationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RecommendationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRecommendationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RecommendationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py index 8d3ef10867de..db541caa3d13 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py index 5a24c9e2674c..277ee4c1bd6b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py index 76baf925f206..9cb442f93c9a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py index 1af2e9dfaccf..c08472f986b6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py @@ -279,6 +279,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RecommendationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/async_client.py index ee4bb2588382..ce5a151c9958 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> SampleQueryServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1115,7 +1115,7 @@ async def sample_import_sample_queries(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1141,8 +1141,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1151,7 +1155,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1159,7 +1163,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1170,7 +1174,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1196,8 +1200,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1206,7 +1214,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1214,7 +1222,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1225,7 +1233,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1254,8 +1262,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1264,7 +1276,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1272,7 +1284,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/client.py index 721f8c8536da..19f41d19efd7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/client.py @@ -123,7 +123,7 @@ class SampleQueryServiceClient(metaclass=SampleQueryServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = SampleQueryServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1558,7 +1562,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1584,8 +1588,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1594,7 +1602,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1603,7 +1611,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1617,7 +1625,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1643,8 +1651,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1653,7 +1665,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1662,7 +1674,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1676,7 +1688,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1705,8 +1717,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1715,7 +1731,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1723,7 +1739,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/README.rst index cda772a83bf7..467c4878cb8a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SampleQueryServiceTransport` is the ABC for all transports. -- public child `SampleQueryServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SampleQueryServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSampleQueryServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SampleQueryServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SampleQueryServiceTransport`` is the ABC for all transports. + +- public child ``SampleQueryServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SampleQueryServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSampleQueryServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SampleQueryServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/base.py index 0f1c2ef8ab9e..ab14c1e1dc51 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc.py index 8175e39c922f..fb49a7134578 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc_asyncio.py index 738275902907..89cd45acf196 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/rest.py index 62758dd41387..817dc2cd754c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_service/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SampleQueryServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/async_client.py index faf9de8a50af..2070461834a2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> SampleQuerySetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1014,7 +1014,7 @@ async def sample_delete_sample_query_set(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1040,8 +1040,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1050,7 +1054,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1058,7 +1062,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1069,7 +1073,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1095,8 +1099,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1105,7 +1113,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1113,7 +1121,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1132,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1153,8 +1161,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,7 +1175,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1171,7 +1183,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/client.py index 0cbec5a71ac6..22536fa2e878 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/client.py @@ -124,7 +124,7 @@ class SampleQuerySetServiceClient(metaclass=SampleQuerySetServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -466,7 +470,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = SampleQuerySetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1452,7 +1456,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1478,8 +1482,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1488,7 +1496,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1497,7 +1505,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1511,7 +1519,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1537,8 +1545,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1547,7 +1559,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1556,7 +1568,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1570,7 +1582,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1599,8 +1611,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1609,7 +1625,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1617,7 +1633,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/README.rst index a5764323aeac..0015b1d55ea5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SampleQuerySetServiceTransport` is the ABC for all transports. -- public child `SampleQuerySetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SampleQuerySetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSampleQuerySetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SampleQuerySetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SampleQuerySetServiceTransport`` is the ABC for all transports. + +- public child ``SampleQuerySetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SampleQuerySetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSampleQuerySetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SampleQuerySetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/base.py index 8730e751611b..0633c307c300 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc.py index c2feda6f2bff..78042bae9a03 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc_asyncio.py index 5f3ff2d31ecc..0d0e2ae8bd0d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/rest.py index 77f1ce6ed248..64ecabb962b1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/sample_query_set_service/transports/rest.py @@ -484,6 +484,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SampleQuerySetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py index 7e0aa37f4d7c..a4ba56841150 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> SchemaServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -946,7 +946,7 @@ async def sample_delete_schema(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -972,8 +972,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -982,7 +986,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -990,7 +994,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1001,7 +1005,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1031,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1045,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1053,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1056,7 +1064,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1085,8 +1093,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1095,7 +1107,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1103,7 +1115,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py index eb31e4308986..b0544f3cd324 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py @@ -119,7 +119,7 @@ class SchemaServiceClient(metaclass=SchemaServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = SchemaServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1397,7 +1401,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1423,8 +1427,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1441,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1442,7 +1450,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1456,7 +1464,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1482,8 +1490,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1492,7 +1504,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1501,7 +1513,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1515,7 +1527,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1544,8 +1556,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1554,7 +1570,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1562,7 +1578,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/README.rst index a0a06949e679..a3c2df942aa3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SchemaServiceTransport` is the ABC for all transports. -- public child `SchemaServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SchemaServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSchemaServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SchemaServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SchemaServiceTransport`` is the ABC for all transports. + +- public child ``SchemaServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SchemaServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSchemaServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SchemaServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py index 279eb7b45647..69a7976de369 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py index 80d03a65b75a..e582748b3175 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py index 65edb1a2d5d4..71ed4d10db91 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py index f84ed363b954..82b89d9b0115 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py @@ -499,6 +499,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SchemaServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py index c04663ba1942..83bdd4cd3936 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SearchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -413,7 +413,7 @@ async def sample_search(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -439,8 +439,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -449,7 +453,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -457,7 +461,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -468,7 +472,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -494,8 +498,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -504,7 +512,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -512,7 +520,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -523,7 +531,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -552,8 +560,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -562,7 +574,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -570,7 +582,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py index 1b0dd833ea79..3e5cde7a578b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py @@ -112,7 +112,7 @@ class SearchServiceClient(metaclass=SearchServiceClientMeta): """Service for search.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -563,7 +567,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -660,7 +664,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -756,7 +760,7 @@ def __init__( self._universe_domain = SearchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -970,7 +974,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -996,8 +1000,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1006,7 +1014,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1015,7 +1023,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1029,7 +1037,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1055,8 +1063,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1065,7 +1077,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1074,7 +1086,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1088,7 +1100,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1117,8 +1129,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1127,7 +1143,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1135,7 +1151,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/README.rst index 8ef0891e3c25..9f2873332607 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SearchServiceTransport` is the ABC for all transports. -- public child `SearchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SearchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSearchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SearchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SearchServiceTransport`` is the ABC for all transports. + +- public child ``SearchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SearchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSearchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SearchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py index 8742a35a76bf..38b6fcfdf34b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py index 3d74e1a3ea1b..2373a25be5ff 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py index 60c2f8107bcf..caae79b0faef 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py index a866396e7505..487e3cea885c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py @@ -274,6 +274,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SearchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py index 93a83a182084..c75c13ff558a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> SearchTuningServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -515,7 +515,7 @@ async def sample_list_custom_models(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -541,8 +541,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -551,7 +555,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -559,7 +563,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -570,7 +574,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -596,8 +600,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -606,7 +614,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -614,7 +622,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -625,7 +633,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -654,8 +662,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -664,7 +676,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -672,7 +684,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py index de88d9d2e3f2..3c5a334fe83b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py @@ -116,7 +116,7 @@ class SearchTuningServiceClient(metaclass=SearchTuningServiceClientMeta): """Service for search tuning.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -562,7 +566,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = SearchTuningServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -969,7 +973,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -995,8 +999,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1005,7 +1013,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1014,7 +1022,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1028,7 +1036,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1062,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1076,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1073,7 +1085,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1087,7 +1099,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1116,8 +1128,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1126,7 +1142,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1134,7 +1150,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/README.rst index eef506f0f655..774bfa0d9ce6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SearchTuningServiceTransport` is the ABC for all transports. -- public child `SearchTuningServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SearchTuningServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSearchTuningServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SearchTuningServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SearchTuningServiceTransport`` is the ABC for all transports. + +- public child ``SearchTuningServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SearchTuningServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSearchTuningServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SearchTuningServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py index 68c4c3f38f2a..46530872cf0e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py index e9e841d2d6fc..c4fd36d8893a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py index 6f5b376ef66e..b8ffad8f06db 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py index 7f23ece525f4..4e7d047d2a47 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py @@ -337,6 +337,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SearchTuningServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/async_client.py index b73963647cde..eab5882f01e1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> ServingConfigServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -707,7 +707,7 @@ async def sample_list_serving_configs(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -733,8 +733,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -743,7 +747,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -751,7 +755,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -762,7 +766,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -788,8 +792,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -798,7 +806,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -806,7 +814,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -817,7 +825,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -846,8 +854,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -856,7 +868,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -864,7 +876,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/client.py index 96de7b3d47f4..e9744feabf37 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/client.py @@ -123,7 +123,7 @@ class ServingConfigServiceClient(metaclass=ServingConfigServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -450,7 +454,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -547,7 +551,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = ServingConfigServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1140,7 +1144,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1166,8 +1170,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1176,7 +1184,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1185,7 +1193,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1199,7 +1207,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1225,8 +1233,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1235,7 +1247,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1244,7 +1256,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1258,7 +1270,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1287,8 +1299,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1297,7 +1313,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1305,7 +1321,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/README.rst index 0581bb81c691..5641722cda1e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServingConfigServiceTransport` is the ABC for all transports. -- public child `ServingConfigServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServingConfigServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServingConfigServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServingConfigServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServingConfigServiceTransport`` is the ABC for all transports. + +- public child ``ServingConfigServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServingConfigServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServingConfigServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServingConfigServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/base.py index 76337c5d454c..18370197cafd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc.py index 9679ff61f295..45837fd9da4e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc_asyncio.py index 2cbd5722f858..647143c39d95 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/rest.py index 3cce427fd89d..8f555933bbb9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/serving_config_service/transports/rest.py @@ -403,6 +403,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ServingConfigServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/async_client.py index 7711613ec57f..ee1a65f3ca53 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> SessionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1036,7 +1036,7 @@ async def sample_list_files(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1062,8 +1062,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1072,7 +1076,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1080,7 +1084,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1091,7 +1095,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1117,8 +1121,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1127,7 +1135,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1135,7 +1143,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1146,7 +1154,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1175,8 +1183,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1185,7 +1197,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1193,7 +1205,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/client.py index c1d0956bf9d1..d33acdecb797 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/client.py @@ -119,7 +119,7 @@ class SessionServiceClient(metaclass=SessionServiceClientMeta): """Service for managing Sessions and Session-related resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -548,7 +552,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -645,7 +649,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -741,7 +745,7 @@ def __init__( self._universe_domain = SessionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1557,7 +1561,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1583,8 +1587,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1593,7 +1601,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1602,7 +1610,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1616,7 +1624,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1642,8 +1650,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1652,7 +1664,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1661,7 +1673,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1675,7 +1687,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1704,8 +1716,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1714,7 +1730,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1722,7 +1738,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/README.rst index f67320e75a5d..ec396d9ed40d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionServiceTransport` is the ABC for all transports. -- public child `SessionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionServiceTransport`` is the ABC for all transports. + +- public child ``SessionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/base.py index 61d249491785..81323d442948 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc.py index 6ad3cfb2dad2..fb19396a96ec 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc_asyncio.py index 92699cea3b1e..460b293ba056 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/rest.py index aa82db74c96d..f09a290c058a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/session_service/transports/rest.py @@ -528,6 +528,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py index 10a77246976e..d08590cbfe9a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> SiteSearchEngineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2026,7 +2026,7 @@ async def sample_get_uri_pattern_document_data(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2052,8 +2052,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2062,7 +2066,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2070,7 +2074,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2081,7 +2085,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2107,8 +2111,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2117,7 +2125,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2125,7 +2133,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2136,7 +2144,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2165,8 +2173,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2175,7 +2187,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2183,7 +2195,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py index eead5f824949..61f61f45df27 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py @@ -121,7 +121,7 @@ class SiteSearchEngineServiceClient(metaclass=SiteSearchEngineServiceClientMeta) """Service for managing site search related resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -470,7 +474,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -671,7 +675,7 @@ def __init__( self._universe_domain = SiteSearchEngineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2460,7 +2464,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2486,8 +2490,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2496,7 +2504,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2505,7 +2513,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2519,7 +2527,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2545,8 +2553,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2555,7 +2567,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2564,7 +2576,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2578,7 +2590,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2607,8 +2619,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2617,7 +2633,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2625,7 +2641,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/README.rst index 2a7b3fa91582..9c4a098942bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SiteSearchEngineServiceTransport` is the ABC for all transports. -- public child `SiteSearchEngineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SiteSearchEngineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSiteSearchEngineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SiteSearchEngineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SiteSearchEngineServiceTransport`` is the ABC for all transports. + +- public child ``SiteSearchEngineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SiteSearchEngineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSiteSearchEngineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SiteSearchEngineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py index d5dfd6f8358c..27d6de1648e8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py index 390023833684..1b2a9abb4757 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py index c2d953c2421f..d7d64c08fcea 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py index 234ca1eeec56..088275d20df4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py @@ -1032,6 +1032,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SiteSearchEngineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py index 5d13caa28702..2a62f719e83d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> UserEventServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -764,7 +764,7 @@ async def sample_import_user_events(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -790,8 +790,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -800,7 +804,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -808,7 +812,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -819,7 +823,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -845,8 +849,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -855,7 +863,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -863,7 +871,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -874,7 +882,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -903,8 +911,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -913,7 +925,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -921,7 +933,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py index ae5e5b13f801..69929eabcc47 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py @@ -124,7 +124,7 @@ class UserEventServiceClient(metaclass=UserEventServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -499,7 +503,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -596,7 +600,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -694,7 +698,7 @@ def __init__( self._universe_domain = UserEventServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1246,7 +1250,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1276,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1290,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1291,7 +1299,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1305,7 +1313,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1331,8 +1339,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1341,7 +1353,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1350,7 +1362,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1376,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1393,8 +1405,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,7 +1419,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1411,7 +1427,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/README.rst index 45f0ef746528..c6e23fe5f03f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserEventServiceTransport` is the ABC for all transports. -- public child `UserEventServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserEventServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserEventServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserEventServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserEventServiceTransport`` is the ABC for all transports. + +- public child ``UserEventServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserEventServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserEventServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserEventServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py index 58082410998c..0cfe3d93fb12 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py index 9cd0d70e75dc..53cfef22a5d0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py index b0ce463918f5..d0f7c8395d33 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py index 279ad70e4e65..5fc2685824bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py @@ -453,6 +453,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserEventServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py index 87bd617b6d5b..a26320e37ba9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> CompletionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -940,7 +940,7 @@ async def sample_purge_completion_suggestions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -966,8 +966,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -976,7 +980,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -984,7 +988,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -995,7 +999,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1021,8 +1025,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1031,7 +1039,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1039,7 +1047,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1050,7 +1058,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1079,8 +1087,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1089,7 +1101,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1097,7 +1109,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py index 0e62e82d9ecd..1ccbc1486a60 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py @@ -117,7 +117,7 @@ class CompletionServiceClient(metaclass=CompletionServiceClientMeta): """Service for Auto-Completion.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -490,7 +494,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -587,7 +591,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -687,7 +691,7 @@ def __init__( self._universe_domain = CompletionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1420,7 +1424,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1446,8 +1450,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1456,7 +1464,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1465,7 +1473,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1479,7 +1487,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1505,8 +1513,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1515,7 +1527,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1524,7 +1536,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1538,7 +1550,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1567,8 +1579,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1577,7 +1593,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1585,7 +1601,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/README.rst index 3f71883905ca..3d1e4e840e1a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CompletionServiceTransport` is the ABC for all transports. -- public child `CompletionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CompletionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCompletionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CompletionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CompletionServiceTransport`` is the ABC for all transports. + +- public child ``CompletionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CompletionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCompletionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CompletionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py index 9690f72838bb..b594731b190c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py index ad04b9d2a39b..c38966cbe24c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py index 589f60c73ee6..b40369d6b693 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py index 7ea9dbba3d93..8ee5075041da 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py @@ -571,6 +571,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CompletionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/async_client.py index 2f6a16a9563d..c40a6b41283c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/async_client.py @@ -196,7 +196,7 @@ def transport(self) -> ControlServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -943,7 +943,7 @@ async def sample_list_controls(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -969,8 +969,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -979,7 +983,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -987,7 +991,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -998,7 +1002,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1024,8 +1028,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1034,7 +1042,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1042,7 +1050,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1053,7 +1061,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1082,8 +1090,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1092,7 +1104,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1100,7 +1112,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/client.py index 8cd1ede63fdc..555d0419bffb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/client.py @@ -118,7 +118,7 @@ class ControlServiceClient(metaclass=ControlServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -467,7 +471,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -564,7 +568,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = ControlServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1393,7 +1397,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1419,8 +1423,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1429,7 +1437,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1438,7 +1446,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1452,7 +1460,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1478,8 +1486,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1488,7 +1500,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1497,7 +1509,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1511,7 +1523,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1540,8 +1552,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1550,7 +1566,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1558,7 +1574,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/README.rst index ee9c627694ad..099231a14c2f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ControlServiceTransport` is the ABC for all transports. -- public child `ControlServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ControlServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseControlServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ControlServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ControlServiceTransport`` is the ABC for all transports. + +- public child ``ControlServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ControlServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseControlServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ControlServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/base.py index ef2e74ddbe68..69e3e7e88ba1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/base.py @@ -84,6 +84,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -133,6 +137,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc.py index d626996d62a9..8c994bae7f93 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc_asyncio.py index 21d160d7470a..4d10e95c7b86 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/rest.py index ebb12c0cdd0b..be5fe9572645 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/control_service/transports/rest.py @@ -463,6 +463,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ControlServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py index 141a7198f7f6..058d17d25e65 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py @@ -242,7 +242,7 @@ def transport(self) -> ConversationalSearchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1903,7 +1903,7 @@ async def sample_list_sessions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1929,8 +1929,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1939,7 +1943,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1947,7 +1951,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1958,7 +1962,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1984,8 +1988,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1994,7 +2002,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2002,7 +2010,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2013,7 +2021,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2042,8 +2050,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2052,7 +2064,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2060,7 +2072,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py index 3c9668666458..ec768b660352 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py @@ -128,7 +128,7 @@ class ConversationalSearchServiceClient( """Service for conversational search.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -605,7 +609,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -704,7 +708,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -806,7 +810,7 @@ def __init__( self._universe_domain = ConversationalSearchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2429,7 +2433,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2455,8 +2459,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2465,7 +2473,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2474,7 +2482,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2488,7 +2496,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2514,8 +2522,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2524,7 +2536,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2533,7 +2545,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2547,7 +2559,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2576,8 +2588,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2586,7 +2602,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2594,7 +2610,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/README.rst index f8f6d58a0c64..99a63d05709f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConversationalSearchServiceTransport` is the ABC for all transports. -- public child `ConversationalSearchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConversationalSearchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConversationalSearchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConversationalSearchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConversationalSearchServiceTransport`` is the ABC for all transports. + +- public child ``ConversationalSearchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConversationalSearchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConversationalSearchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConversationalSearchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py index b2adcab11e71..adf946097646 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py index 7ee8e2903b3b..931d07b95d4f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py index aa4b5feee6d3..ae41a5df0a5d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py index 6cb5da9cc7cd..c157d7a60c1e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py @@ -897,6 +897,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ConversationalSearchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/async_client.py index 6f09e5bdc3df..ac664a0d81d7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/async_client.py @@ -213,7 +213,7 @@ def transport(self) -> DataStoreServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1048,7 +1048,7 @@ async def sample_update_data_store(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1074,8 +1074,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1084,7 +1088,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1092,7 +1096,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1103,7 +1107,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1129,8 +1133,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1139,7 +1147,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1147,7 +1155,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1158,7 +1166,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1187,8 +1195,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1197,7 +1209,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1205,7 +1217,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/client.py index 8796ede3c9b0..adc40504989e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/client.py @@ -127,7 +127,7 @@ class DataStoreServiceClient(metaclass=DataStoreServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -522,7 +526,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -619,7 +623,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -717,7 +721,7 @@ def __init__( self._universe_domain = DataStoreServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1537,7 +1541,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1563,8 +1567,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1573,7 +1581,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1582,7 +1590,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1596,7 +1604,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1622,8 +1630,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1632,7 +1644,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1641,7 +1653,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1655,7 +1667,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1684,8 +1696,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1694,7 +1710,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1702,7 +1718,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/README.rst index 7b7cd44d7eab..aaa93b7f76f6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataStoreServiceTransport` is the ABC for all transports. -- public child `DataStoreServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataStoreServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataStoreServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataStoreServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataStoreServiceTransport`` is the ABC for all transports. + +- public child ``DataStoreServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataStoreServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataStoreServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataStoreServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/base.py index df3a68ea8188..6674f59aa323 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc.py index 9c05846646b0..9699699082fc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc_asyncio.py index d993960945e6..faa3754f13e3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/rest.py index 6f5fb50a4708..341396eb80ad 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/data_store_service/transports/rest.py @@ -510,6 +510,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataStoreServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py index bdf75ed7dc31..572706912781 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> DocumentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1341,7 +1341,7 @@ async def sample_batch_get_documents_metadata(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1367,8 +1367,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1377,7 +1381,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1385,7 +1389,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1396,7 +1400,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1422,8 +1426,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1432,7 +1440,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1440,7 +1448,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1451,7 +1459,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1480,8 +1488,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1490,7 +1502,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1498,7 +1510,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py index ce9251261e92..bb2616e22780 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py @@ -126,7 +126,7 @@ class DocumentServiceClient(metaclass=DocumentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -134,7 +134,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -144,6 +144,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -531,7 +535,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -628,7 +632,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -726,7 +730,7 @@ def __init__( self._universe_domain = DocumentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1836,7 +1840,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1862,8 +1866,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1872,7 +1880,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1881,7 +1889,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1895,7 +1903,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1921,8 +1929,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1931,7 +1943,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1940,7 +1952,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1954,7 +1966,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1983,8 +1995,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1993,7 +2009,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2001,7 +2017,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/README.rst index 4aabee4652ef..765422bd31c7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentServiceTransport` is the ABC for all transports. -- public child `DocumentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentServiceTransport`` is the ABC for all transports. + +- public child ``DocumentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py index 4110007f482c..3d225954d3d3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py index 943d36bda1d1..493273bc1238 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py index 5d6d7f48764e..fa392c354a01 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py index 5e75dafb28be..264f12b31d77 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py @@ -643,6 +643,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/async_client.py index ab061c4a243b..49a3b05727dd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> EngineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1360,7 +1360,7 @@ async def sample_tune_engine(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1386,8 +1386,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1396,7 +1400,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1404,7 +1408,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1415,7 +1419,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1441,8 +1445,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1451,7 +1459,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1459,7 +1467,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1470,7 +1478,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1499,8 +1507,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1509,7 +1521,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1517,7 +1529,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/client.py index 1b153c4424ac..9968260ac998 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/client.py @@ -120,7 +120,7 @@ class EngineServiceClient(metaclass=EngineServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -471,7 +475,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -568,7 +572,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -664,7 +668,7 @@ def __init__( self._universe_domain = EngineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1803,7 +1807,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1829,8 +1833,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1839,7 +1847,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1848,7 +1856,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1862,7 +1870,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1888,8 +1896,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1898,7 +1910,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1907,7 +1919,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1921,7 +1933,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1950,8 +1962,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1960,7 +1976,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1968,7 +1984,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/README.rst index e23db35aec58..746aff382ff2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EngineServiceTransport` is the ABC for all transports. -- public child `EngineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EngineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEngineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EngineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EngineServiceTransport`` is the ABC for all transports. + +- public child ``EngineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EngineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEngineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EngineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/base.py index b025a1e084a7..b392d75479dd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc.py index 056a3bf26a58..54bed805ccba 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc_asyncio.py index 7b6304851f7b..7583496d024d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/rest.py index de4f6ba8f389..23825710c132 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/engine_service/transports/rest.py @@ -658,6 +658,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EngineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/async_client.py index 584a6b5ff3ab..398d31ca162c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> EvaluationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -879,7 +879,7 @@ async def sample_list_evaluation_results(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -905,8 +905,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -915,7 +919,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -923,7 +927,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -934,7 +938,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -960,8 +964,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -970,7 +978,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -978,7 +986,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -989,7 +997,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1018,8 +1026,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1028,7 +1040,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1036,7 +1048,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/client.py index fcb46b6b0025..457a9f23ac37 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/client.py @@ -119,7 +119,7 @@ class EvaluationServiceClient(metaclass=EvaluationServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -603,7 +607,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -700,7 +704,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -800,7 +804,7 @@ def __init__( self._universe_domain = EvaluationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1450,7 +1454,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1476,8 +1480,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1486,7 +1494,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1495,7 +1503,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1509,7 +1517,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1535,8 +1543,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1545,7 +1557,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1554,7 +1566,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1568,7 +1580,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1597,8 +1609,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1607,7 +1623,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1615,7 +1631,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/README.rst index b012f0c5c184..21b6cc6a5fa7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EvaluationServiceTransport` is the ABC for all transports. -- public child `EvaluationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EvaluationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEvaluationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EvaluationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EvaluationServiceTransport`` is the ABC for all transports. + +- public child ``EvaluationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EvaluationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEvaluationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EvaluationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/base.py index 08b73c0cc991..64e61202cc77 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc.py index d74df80b4541..cab2dd73c31e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc_asyncio.py index 8b5d8c2b41f6..9a485ca41b75 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/rest.py index f915ce2dfa94..e7d356f8bb1b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/evaluation_service/transports/rest.py @@ -454,6 +454,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EvaluationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/async_client.py index b10dfc898e77..33bee06f5657 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/async_client.py @@ -219,7 +219,7 @@ def transport(self) -> GroundedGenerationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -607,7 +607,7 @@ async def sample_check_grounding(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -633,8 +633,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -643,7 +647,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -651,7 +655,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -662,7 +666,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -688,8 +692,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -698,7 +706,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -706,7 +714,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -717,7 +725,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -746,8 +754,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -756,7 +768,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -764,7 +776,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/client.py index cc67cec69f43..0cfb154d9536 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/client.py @@ -116,7 +116,7 @@ class GroundedGenerationServiceClient(metaclass=GroundedGenerationServiceClientM """Service for grounded generation.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -482,7 +486,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -581,7 +585,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -683,7 +687,7 @@ def __init__( self._universe_domain = GroundedGenerationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1065,7 +1069,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,8 +1095,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1101,7 +1109,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1110,7 +1118,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1124,7 +1132,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1150,8 +1158,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1160,7 +1172,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1169,7 +1181,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1183,7 +1195,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1212,8 +1224,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1222,7 +1238,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1230,7 +1246,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/README.rst index 5975f92cd7d1..ab3f17900b7f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GroundedGenerationServiceTransport` is the ABC for all transports. -- public child `GroundedGenerationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GroundedGenerationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGroundedGenerationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GroundedGenerationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GroundedGenerationServiceTransport`` is the ABC for all transports. + +- public child ``GroundedGenerationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GroundedGenerationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGroundedGenerationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GroundedGenerationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/base.py index 11847d001a1b..bf4d693d2723 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc.py index c93b91d5718b..7767d77d79ec 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc_asyncio.py index 66b061dfee8a..c5600b0066cd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/rest.py index 2bd8baeda92f..8580f3bcde60 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/grounded_generation_service/transports/rest.py @@ -342,6 +342,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GroundedGenerationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/async_client.py index afbe32a3ba52..b7f4202f663e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> ProjectServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -438,7 +438,7 @@ async def sample_provision_project(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -464,8 +464,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -474,7 +478,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -482,7 +486,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -493,7 +497,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -519,8 +523,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -529,7 +537,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -537,7 +545,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -548,7 +556,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -577,8 +585,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -587,7 +599,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -595,7 +607,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/client.py index eb041cea9147..84b16d8ecdc4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/client.py @@ -115,7 +115,7 @@ class ProjectServiceClient(metaclass=ProjectServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -530,7 +534,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -626,7 +630,7 @@ def __init__( self._universe_domain = ProjectServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -871,7 +875,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -897,8 +901,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -907,7 +915,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -916,7 +924,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -930,7 +938,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -956,8 +964,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -966,7 +978,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -975,7 +987,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -989,7 +1001,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1018,8 +1030,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1028,7 +1044,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1036,7 +1052,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/README.rst index e8af52d6e307..f5907a88e7e8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ProjectServiceTransport` is the ABC for all transports. -- public child `ProjectServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProjectServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProjectServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProjectServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ProjectServiceTransport`` is the ABC for all transports. + +- public child ``ProjectServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ProjectServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseProjectServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ProjectServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/base.py index c36acb13fa2a..ac09d08620d0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc.py index bc6259df509a..b107f040759e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc_asyncio.py index 74fa602db21f..75cf4d05a077 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/rest.py index 16a48c4deb4f..b1bfe7e78145 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/project_service/transports/rest.py @@ -277,6 +277,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ProjectServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/async_client.py index 0a0dd485e718..4174d9502f8a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> RankServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -384,7 +384,7 @@ async def sample_rank(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -410,8 +410,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -420,7 +424,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -428,7 +432,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -439,7 +443,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -465,8 +469,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -475,7 +483,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -483,7 +491,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -494,7 +502,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -523,8 +531,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -533,7 +545,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -541,7 +553,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/client.py index 11a3aa6113cf..b88341619721 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/client.py @@ -111,7 +111,7 @@ class RankServiceClient(metaclass=RankServiceClientMeta): """Service for ranking text records.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -436,7 +440,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -533,7 +537,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -629,7 +633,7 @@ def __init__( self._universe_domain = RankServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -826,7 +830,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -852,8 +856,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -862,7 +870,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -871,7 +879,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -885,7 +893,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -911,8 +919,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -921,7 +933,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -930,7 +942,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -944,7 +956,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -973,8 +985,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -983,7 +999,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -991,7 +1007,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/README.rst index 5103092608ec..01379c3e3dc3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RankServiceTransport` is the ABC for all transports. -- public child `RankServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RankServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRankServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RankServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RankServiceTransport`` is the ABC for all transports. + +- public child ``RankServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RankServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRankServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RankServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/base.py index 942c5a3b6a82..893bf1072f2c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc.py index 0179cf6eae42..2ccb4d976647 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc_asyncio.py index 207c85b4f3a2..2ad33a7d64b3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/rest.py index 4b2f8d6b7429..6770108117f4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/rank_service/transports/rest.py @@ -274,6 +274,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RankServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py index 7fe03cc17d69..13baad924570 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> RecommendationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -408,7 +408,7 @@ async def sample_recommend(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -434,8 +434,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -444,7 +448,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -452,7 +456,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -463,7 +467,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -489,8 +493,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -499,7 +507,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -507,7 +515,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -518,7 +526,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -547,8 +555,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -557,7 +569,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -565,7 +577,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py index 7cff9d53476e..a5614651d7eb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py @@ -111,7 +111,7 @@ class RecommendationServiceClient(metaclass=RecommendationServiceClientMeta): """Service for making recommendations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -510,7 +514,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -609,7 +613,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -709,7 +713,7 @@ def __init__( self._universe_domain = RecommendationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -912,7 +916,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -938,8 +942,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -948,7 +956,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -957,7 +965,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -971,7 +979,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -997,8 +1005,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1007,7 +1019,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1016,7 +1028,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1030,7 +1042,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1059,8 +1071,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1069,7 +1085,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1077,7 +1093,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/README.rst index 07e52e0896bb..9dff1804700e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`RecommendationServiceTransport` is the ABC for all transports. -- public child `RecommendationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `RecommendationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseRecommendationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `RecommendationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``RecommendationServiceTransport`` is the ABC for all transports. + +- public child ``RecommendationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``RecommendationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseRecommendationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``RecommendationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py index 097be38da00e..a93cadb4b510 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py index de3fd7c6a30c..e3453e0decd0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py index ceafa7dd7250..39570a46cc86 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py index 1009031f45fe..173c66703f19 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py @@ -279,6 +279,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[RecommendationServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/async_client.py index d166dbc40d05..5013523c1b5f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> SampleQueryServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1115,7 +1115,7 @@ async def sample_import_sample_queries(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1141,8 +1141,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1151,7 +1155,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1159,7 +1163,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1170,7 +1174,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1196,8 +1200,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1206,7 +1214,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1214,7 +1222,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1225,7 +1233,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1254,8 +1262,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1264,7 +1276,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1272,7 +1284,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/client.py index 7dbd8f55552c..4a60d3010404 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/client.py @@ -123,7 +123,7 @@ class SampleQueryServiceClient(metaclass=SampleQueryServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -569,7 +573,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -669,7 +673,7 @@ def __init__( self._universe_domain = SampleQueryServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1558,7 +1562,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1584,8 +1588,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1594,7 +1602,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1603,7 +1611,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1617,7 +1625,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1643,8 +1651,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1653,7 +1665,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1662,7 +1674,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1676,7 +1688,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1705,8 +1717,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1715,7 +1731,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1723,7 +1739,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/README.rst index cda772a83bf7..467c4878cb8a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SampleQueryServiceTransport` is the ABC for all transports. -- public child `SampleQueryServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SampleQueryServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSampleQueryServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SampleQueryServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SampleQueryServiceTransport`` is the ABC for all transports. + +- public child ``SampleQueryServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SampleQueryServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSampleQueryServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SampleQueryServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/base.py index f16c3770118f..fc56a2347366 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc.py index c87d5d9213a8..8ea5cdbb759d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc_asyncio.py index 550618ac865d..d5342c0bdaf2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/rest.py index 886083847437..fdc75f995296 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_service/transports/rest.py @@ -534,6 +534,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SampleQueryServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/async_client.py index c95322c21ba5..f58134522e4a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/async_client.py @@ -208,7 +208,7 @@ def transport(self) -> SampleQuerySetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1012,7 +1012,7 @@ async def sample_delete_sample_query_set(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1038,8 +1038,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1048,7 +1052,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1056,7 +1060,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1067,7 +1071,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1093,8 +1097,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1103,7 +1111,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1111,7 +1119,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1122,7 +1130,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1151,8 +1159,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1161,7 +1173,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1169,7 +1181,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/client.py index 7956a60c8961..2c1e919b564c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/client.py @@ -122,7 +122,7 @@ class SampleQuerySetServiceClient(metaclass=SampleQuerySetServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -563,7 +567,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -663,7 +667,7 @@ def __init__( self._universe_domain = SampleQuerySetServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1450,7 +1454,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1476,8 +1480,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1486,7 +1494,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1495,7 +1503,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1509,7 +1517,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1535,8 +1543,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1545,7 +1557,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1554,7 +1566,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1568,7 +1580,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1597,8 +1609,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1607,7 +1623,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1615,7 +1631,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/README.rst index a5764323aeac..0015b1d55ea5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SampleQuerySetServiceTransport` is the ABC for all transports. -- public child `SampleQuerySetServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SampleQuerySetServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSampleQuerySetServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SampleQuerySetServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SampleQuerySetServiceTransport`` is the ABC for all transports. + +- public child ``SampleQuerySetServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SampleQuerySetServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSampleQuerySetServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SampleQuerySetServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/base.py index 310fd61b10b5..c81677957cff 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc.py index 132e5a85bcfb..8495dd40e8fc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc_asyncio.py index 50f07675f41a..a412aa6aaffd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/rest.py index de5cbd6dc2a7..9b6cf8a327b8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/sample_query_set_service/transports/rest.py @@ -484,6 +484,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SampleQuerySetServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py index 1a0b8a2ad803..8ee94d8574f9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> SchemaServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -946,7 +946,7 @@ async def sample_delete_schema(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -972,8 +972,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -982,7 +986,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -990,7 +994,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1001,7 +1005,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1031,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1045,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1053,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1056,7 +1064,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1085,8 +1093,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1095,7 +1107,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1103,7 +1115,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py index 2600bc3e6fb9..c0b258d63f4e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py @@ -119,7 +119,7 @@ class SchemaServiceClient(metaclass=SchemaServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = SchemaServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1397,7 +1401,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1423,8 +1427,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1441,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1442,7 +1450,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1456,7 +1464,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1482,8 +1490,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1492,7 +1504,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1501,7 +1513,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1515,7 +1527,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1544,8 +1556,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1554,7 +1570,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1562,7 +1578,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/README.rst index a0a06949e679..a3c2df942aa3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SchemaServiceTransport` is the ABC for all transports. -- public child `SchemaServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SchemaServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSchemaServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SchemaServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SchemaServiceTransport`` is the ABC for all transports. + +- public child ``SchemaServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SchemaServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSchemaServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SchemaServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py index 4d6119220330..355ca8e70cb8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py index ca6de7bbd6c7..6fb14e53c83c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py index 1413949bf8ea..0074031b8cc3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py index f63d141e647b..61e8f0be2bc5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py @@ -499,6 +499,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SchemaServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py index 9e19d1bc888f..12101569bd86 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> SearchServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -532,7 +532,7 @@ async def sample_search_lite(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -558,8 +558,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -568,7 +572,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -576,7 +580,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -587,7 +591,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -613,8 +617,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -623,7 +631,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -631,7 +639,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -642,7 +650,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -671,8 +679,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -681,7 +693,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -689,7 +701,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py index 44f83220bf03..530f44d06e9c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py @@ -112,7 +112,7 @@ class SearchServiceClient(metaclass=SearchServiceClientMeta): """Service for search.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -563,7 +567,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -660,7 +664,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -756,7 +760,7 @@ def __init__( self._universe_domain = SearchServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1087,7 +1091,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1113,8 +1117,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1123,7 +1131,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1132,7 +1140,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1146,7 +1154,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1172,8 +1180,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1182,7 +1194,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1191,7 +1203,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1205,7 +1217,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1234,8 +1246,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1244,7 +1260,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1252,7 +1268,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/README.rst index 8ef0891e3c25..9f2873332607 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SearchServiceTransport` is the ABC for all transports. -- public child `SearchServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SearchServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSearchServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SearchServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SearchServiceTransport`` is the ABC for all transports. + +- public child ``SearchServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SearchServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSearchServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SearchServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py index 1897910a44dd..bc88cfaf5a0a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py index b499893234a2..e66188175f78 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py index 2eeff5eaff61..b27203ecd41f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py index efe6f030866a..35f79397f33d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py @@ -328,6 +328,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SearchServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/async_client.py index 1f45d85687b2..86f454c6e6aa 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> SearchTuningServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -515,7 +515,7 @@ async def sample_list_custom_models(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -541,8 +541,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -551,7 +555,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -559,7 +563,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -570,7 +574,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -596,8 +600,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -606,7 +614,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -614,7 +622,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -625,7 +633,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -654,8 +662,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -664,7 +676,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -672,7 +684,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/client.py index 5ba5de7e6422..688052e5f71c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/client.py @@ -116,7 +116,7 @@ class SearchTuningServiceClient(metaclass=SearchTuningServiceClientMeta): """Service for search tuning.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -562,7 +566,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = SearchTuningServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -969,7 +973,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -995,8 +999,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1005,7 +1013,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1014,7 +1022,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1028,7 +1036,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1054,8 +1062,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1064,7 +1076,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1073,7 +1085,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1087,7 +1099,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1116,8 +1128,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1126,7 +1142,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1134,7 +1150,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/README.rst index eef506f0f655..774bfa0d9ce6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SearchTuningServiceTransport` is the ABC for all transports. -- public child `SearchTuningServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SearchTuningServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSearchTuningServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SearchTuningServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SearchTuningServiceTransport`` is the ABC for all transports. + +- public child ``SearchTuningServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SearchTuningServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSearchTuningServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SearchTuningServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/base.py index 4faea8d179f7..d4d29e4b6591 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc.py index eaed35c3a518..8dc9477cdaaf 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc_asyncio.py index aa6a4e05c764..660fca2c8541 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/rest.py index eaa4b1080641..d8b062bbd2fc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_tuning_service/transports/rest.py @@ -337,6 +337,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SearchTuningServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/async_client.py index 41185f83a728..0bf93c56173d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> ServingConfigServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -708,7 +708,7 @@ async def sample_list_serving_configs(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -734,8 +734,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -744,7 +748,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -752,7 +756,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -763,7 +767,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -789,8 +793,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -799,7 +807,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -807,7 +815,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -818,7 +826,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -847,8 +855,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -857,7 +869,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -865,7 +877,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/client.py index 7c01a2f3c7cc..353699fb5f98 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/client.py @@ -124,7 +124,7 @@ class ServingConfigServiceClient(metaclass=ServingConfigServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -451,7 +455,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -548,7 +552,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -648,7 +652,7 @@ def __init__( self._universe_domain = ServingConfigServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1141,7 +1145,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1167,8 +1171,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1177,7 +1185,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1186,7 +1194,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1200,7 +1208,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1226,8 +1234,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1236,7 +1248,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1245,7 +1257,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1259,7 +1271,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1288,8 +1300,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1298,7 +1314,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1306,7 +1322,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/README.rst index 0581bb81c691..5641722cda1e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServingConfigServiceTransport` is the ABC for all transports. -- public child `ServingConfigServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServingConfigServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServingConfigServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServingConfigServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServingConfigServiceTransport`` is the ABC for all transports. + +- public child ``ServingConfigServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServingConfigServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServingConfigServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServingConfigServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/base.py index 27d4dd4614fd..7abcb581e0cd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc.py index 633426752ffa..402f175b1fc2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc_asyncio.py index 0f5d4318c450..214e2986a4c2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/rest.py index 2d8a911c3dda..b15be717b6a2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/serving_config_service/transports/rest.py @@ -403,6 +403,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ServingConfigServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/async_client.py index 723a59e35e39..259185174810 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> SessionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -906,7 +906,7 @@ async def sample_list_sessions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -932,8 +932,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -942,7 +946,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -950,7 +954,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -961,7 +965,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -987,8 +991,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -997,7 +1005,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1005,7 +1013,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1016,7 +1024,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1045,8 +1053,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1055,7 +1067,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1063,7 +1075,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/client.py index 25109ca29c20..f237f8afbf8d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/client.py @@ -118,7 +118,7 @@ class SessionServiceClient(metaclass=SessionServiceClientMeta): """Service for managing Sessions and Session-related resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -547,7 +551,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -644,7 +648,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -740,7 +744,7 @@ def __init__( self._universe_domain = SessionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1430,7 +1434,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1456,8 +1460,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1466,7 +1474,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1475,7 +1483,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1489,7 +1497,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1515,8 +1523,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1525,7 +1537,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1534,7 +1546,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1548,7 +1560,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1577,8 +1589,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1587,7 +1603,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1595,7 +1611,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/README.rst index f67320e75a5d..ec396d9ed40d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SessionServiceTransport` is the ABC for all transports. -- public child `SessionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SessionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSessionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SessionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SessionServiceTransport`` is the ABC for all transports. + +- public child ``SessionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SessionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSessionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SessionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/base.py index 854b9bb70c80..53a5602d413e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc.py index a32c6ab7c58f..c39ab42116b2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc_asyncio.py index 774487e309dd..945295eed0b4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/rest.py index 1ff209ab8a9e..04a6d9370913 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/session_service/transports/rest.py @@ -469,6 +469,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SessionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/async_client.py index 6f4e8799c019..5bbe21f31185 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/async_client.py @@ -217,7 +217,7 @@ def transport(self) -> SiteSearchEngineServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2233,7 +2233,7 @@ async def sample_fetch_domain_verification_status(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2259,8 +2259,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2269,7 +2273,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2277,7 +2281,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2288,7 +2292,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2314,8 +2318,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2324,7 +2332,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2332,7 +2340,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2343,7 +2351,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2372,8 +2380,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2382,7 +2394,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2390,7 +2402,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/client.py index 5c858ce94a69..4314fd0e577a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/client.py @@ -121,7 +121,7 @@ class SiteSearchEngineServiceClient(metaclass=SiteSearchEngineServiceClientMeta) """Service for managing site search related resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -494,7 +498,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -593,7 +597,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -695,7 +699,7 @@ def __init__( self._universe_domain = SiteSearchEngineServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2680,7 +2684,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2706,8 +2710,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2716,7 +2724,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2725,7 +2733,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2739,7 +2747,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2765,8 +2773,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2775,7 +2787,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2784,7 +2796,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2798,7 +2810,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2827,8 +2839,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2837,7 +2853,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2845,7 +2861,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/README.rst index 2a7b3fa91582..9c4a098942bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SiteSearchEngineServiceTransport` is the ABC for all transports. -- public child `SiteSearchEngineServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SiteSearchEngineServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSiteSearchEngineServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SiteSearchEngineServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SiteSearchEngineServiceTransport`` is the ABC for all transports. + +- public child ``SiteSearchEngineServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SiteSearchEngineServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSiteSearchEngineServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SiteSearchEngineServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/base.py index 66a8ce46393c..ce3fe3b2311e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc.py index aa0802588877..2976b49ef747 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc_asyncio.py index df3556c19384..f46345d6b5b9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/rest.py index b7d9ae1df97b..2a2c6fa340c0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/site_search_engine_service/transports/rest.py @@ -1089,6 +1089,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[SiteSearchEngineServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py index 8c1db15bbc0d..7b396d4f2ab2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> UserEventServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -764,7 +764,7 @@ async def sample_import_user_events(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -790,8 +790,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -800,7 +804,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -808,7 +812,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -819,7 +823,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -845,8 +849,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -855,7 +863,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -863,7 +871,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -874,7 +882,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -903,8 +911,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -913,7 +925,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -921,7 +933,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py index e35a12028829..ffefcc5b8a37 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py @@ -124,7 +124,7 @@ class UserEventServiceClient(metaclass=UserEventServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -499,7 +503,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -596,7 +600,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -694,7 +698,7 @@ def __init__( self._universe_domain = UserEventServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1246,7 +1250,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1272,8 +1276,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1290,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1291,7 +1299,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1305,7 +1313,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1331,8 +1339,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1341,7 +1353,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1350,7 +1362,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1364,7 +1376,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1393,8 +1405,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,7 +1419,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1411,7 +1427,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/README.rst b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/README.rst index 45f0ef746528..c6e23fe5f03f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/README.rst +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UserEventServiceTransport` is the ABC for all transports. -- public child `UserEventServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UserEventServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUserEventServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UserEventServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UserEventServiceTransport`` is the ABC for all transports. + +- public child ``UserEventServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UserEventServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUserEventServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UserEventServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py index b6828c4c9260..28f7fe311957 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py index 7ca0bdf0a7cd..20fe8728785b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py index c4930d26da39..934b003d2161 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py index d7e9baa4de64..117221689740 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py @@ -453,6 +453,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[UserEventServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index 545a6fbf716a..12cf063c1b4e 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-discoveryengine/setup.py b/packages/google-cloud-discoveryengine/setup.py index 354ef11b7faf..28acc6bc562d 100644 --- a/packages/google-cloud-discoveryengine/setup.py +++ b/packages/google-cloud-discoveryengine/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-discoveryengine" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-discoveryengine/testing/constraints-3.7.txt b/packages/google-cloud-discoveryengine/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-discoveryengine/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-discoveryengine/testing/constraints-3.8.txt b/packages/google-cloud-discoveryengine/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-discoveryengine/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-discoveryengine/testing/constraints-3.9.txt b/packages/google-cloud-discoveryengine/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-discoveryengine/testing/constraints-3.9.txt +++ b/packages/google-cloud-discoveryengine/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_assistant_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_assistant_service.py index 19b37621c6f7..fa072add8fbe 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_assistant_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_assistant_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssistantServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): AssistantServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AssistantServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1316,11 +1321,13 @@ def test_assistant_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1894,8 +1901,9 @@ def test_stream_assist_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1964,17 +1972,20 @@ def test_stream_assist_rest_interceptors(null_interceptor): ) client = AssistantServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AssistantServiceRestInterceptor, "post_stream_assist" - ) as post, mock.patch.object( - transports.AssistantServiceRestInterceptor, "post_stream_assist_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AssistantServiceRestInterceptor, "pre_stream_assist" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AssistantServiceRestInterceptor, "post_stream_assist" + ) as post, + mock.patch.object( + transports.AssistantServiceRestInterceptor, + "post_stream_assist_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AssistantServiceRestInterceptor, "pre_stream_assist" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2034,8 +2045,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2096,8 +2108,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2156,8 +2169,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2288,11 +2302,14 @@ def test_assistant_service_base_transport(): def test_assistant_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.assistant_service.transports.AssistantServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.assistant_service.transports.AssistantServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssistantServiceTransport( @@ -2309,9 +2326,12 @@ def test_assistant_service_base_transport_with_credentials_file(): def test_assistant_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.assistant_service.transports.AssistantServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.assistant_service.transports.AssistantServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AssistantServiceTransport() @@ -2383,11 +2403,12 @@ def test_assistant_service_transport_auth_gdch_credentials(transport_class): def test_assistant_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3084,6 +3105,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AssistantServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AssistantServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AssistantServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3229,6 +3282,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AssistantServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AssistantServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AssistantServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3374,6 +3461,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AssistantServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AssistantServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AssistantServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_cmek_config_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_cmek_config_service.py index 014c4c0b465a..d4c19b4dcd43 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_cmek_config_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_cmek_config_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CmekConfigServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): CmekConfigServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CmekConfigServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1324,11 +1329,13 @@ def test_cmek_config_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3789,8 +3796,9 @@ def test_update_cmek_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3924,20 +3932,21 @@ def test_update_cmek_config_rest_interceptors(null_interceptor): ) client = CmekConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "post_update_cmek_config" - ) as post, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, - "post_update_cmek_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "pre_update_cmek_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "post_update_cmek_config" + ) as post, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, + "post_update_cmek_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "pre_update_cmek_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3990,8 +3999,9 @@ def test_get_cmek_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4069,18 +4079,20 @@ def test_get_cmek_config_rest_interceptors(null_interceptor): ) client = CmekConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "post_get_cmek_config" - ) as post, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, - "post_get_cmek_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "pre_get_cmek_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "post_get_cmek_config" + ) as post, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, + "post_get_cmek_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "pre_get_cmek_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4135,8 +4147,9 @@ def test_list_cmek_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4196,18 +4209,20 @@ def test_list_cmek_configs_rest_interceptors(null_interceptor): ) client = CmekConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "post_list_cmek_configs" - ) as post, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, - "post_list_cmek_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "pre_list_cmek_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "post_list_cmek_configs" + ) as post, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, + "post_list_cmek_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "pre_list_cmek_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4265,8 +4280,9 @@ def test_delete_cmek_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4323,20 +4339,21 @@ def test_delete_cmek_config_rest_interceptors(null_interceptor): ) client = CmekConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "post_delete_cmek_config" - ) as post, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, - "post_delete_cmek_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CmekConfigServiceRestInterceptor, "pre_delete_cmek_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "post_delete_cmek_config" + ) as post, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, + "post_delete_cmek_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CmekConfigServiceRestInterceptor, "pre_delete_cmek_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4391,8 +4408,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4453,8 +4471,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4513,8 +4532,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4736,11 +4756,14 @@ def test_cmek_config_service_base_transport(): def test_cmek_config_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.cmek_config_service.transports.CmekConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.cmek_config_service.transports.CmekConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmekConfigServiceTransport( @@ -4757,9 +4780,12 @@ def test_cmek_config_service_base_transport_with_credentials_file(): def test_cmek_config_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.cmek_config_service.transports.CmekConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.cmek_config_service.transports.CmekConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CmekConfigServiceTransport() @@ -4831,11 +4857,12 @@ def test_cmek_config_service_transport_auth_gdch_credentials(transport_class): def test_cmek_config_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5528,6 +5555,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CmekConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CmekConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CmekConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5673,6 +5732,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CmekConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CmekConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CmekConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5818,6 +5911,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CmekConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CmekConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CmekConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py index 4b65fc9f3f25..49326f39da41 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CompletionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): CompletionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CompletionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1329,11 +1334,13 @@ def test_completion_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3706,8 +3713,9 @@ def test_complete_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3772,17 +3780,20 @@ def test_complete_query_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_complete_query" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_complete_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_complete_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "post_complete_query" + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_complete_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "pre_complete_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3842,8 +3853,9 @@ def test_import_suggestion_deny_list_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3902,22 +3914,23 @@ def test_import_suggestion_deny_list_entries_rest_interceptors(null_interceptor) ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_suggestion_deny_list_entries", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_suggestion_deny_list_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "pre_import_suggestion_deny_list_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_suggestion_deny_list_entries", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_suggestion_deny_list_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_import_suggestion_deny_list_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3972,8 +3985,9 @@ def test_purge_suggestion_deny_list_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4032,22 +4046,23 @@ def test_purge_suggestion_deny_list_entries_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_suggestion_deny_list_entries", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_suggestion_deny_list_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "pre_purge_suggestion_deny_list_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_suggestion_deny_list_entries", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_suggestion_deny_list_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_purge_suggestion_deny_list_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4102,8 +4117,9 @@ def test_import_completion_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4162,21 +4178,23 @@ def test_import_completion_suggestions_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_completion_suggestions", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_completion_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_import_completion_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_completion_suggestions", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_completion_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_import_completion_suggestions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4231,8 +4249,9 @@ def test_purge_completion_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4291,20 +4310,23 @@ def test_purge_completion_suggestions_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_purge_completion_suggestions" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_completion_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_purge_completion_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_completion_suggestions", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_completion_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_purge_completion_suggestions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4359,8 +4381,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4421,8 +4444,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4481,8 +4505,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4727,11 +4752,14 @@ def test_completion_service_base_transport(): def test_completion_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompletionServiceTransport( @@ -4748,9 +4776,12 @@ def test_completion_service_base_transport_with_credentials_file(): def test_completion_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompletionServiceTransport() @@ -4822,11 +4853,12 @@ def test_completion_service_transport_auth_gdch_credentials(transport_class): def test_completion_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5435,6 +5467,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5580,6 +5644,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5725,6 +5823,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_control_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_control_service.py index a9826373b972..96b29434f7fc 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_control_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_control_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ControlServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ControlServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ControlServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_control_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4614,8 +4621,9 @@ def test_create_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4802,17 +4810,20 @@ def test_create_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_create_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_create_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_create_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_create_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, + "post_create_control_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_create_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4867,8 +4878,9 @@ def test_delete_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4927,13 +4939,13 @@ def test_delete_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_delete_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_delete_control" + ) as pre, + ): pre.assert_not_called() pb_message = control_service.DeleteControlRequest.pb( control_service.DeleteControlRequest() @@ -4982,8 +4994,9 @@ def test_update_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5174,17 +5187,20 @@ def test_update_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_update_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_update_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_update_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_update_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, + "post_update_control_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_update_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5237,8 +5253,9 @@ def test_get_control_rest_bad_request(request_type=control_service.GetControlReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5313,17 +5330,19 @@ def test_get_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_get_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_get_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_get_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_get_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_get_control_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_get_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5376,8 +5395,9 @@ def test_list_controls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5440,17 +5460,19 @@ def test_list_controls_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_list_controls" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_list_controls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_list_controls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_list_controls" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_list_controls_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_list_controls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5510,8 +5532,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5572,8 +5595,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5632,8 +5656,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5848,11 +5873,14 @@ def test_control_service_base_transport(): def test_control_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ControlServiceTransport( @@ -5869,9 +5897,12 @@ def test_control_service_base_transport_with_credentials_file(): def test_control_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ControlServiceTransport() @@ -5943,11 +5974,12 @@ def test_control_service_transport_auth_gdch_credentials(transport_class): def test_control_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6585,6 +6617,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6730,6 +6794,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6875,6 +6973,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py index 3485d56d192f..e30d2bdbd8c7 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationalSearchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): ConversationalSearchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationalSearchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1398,11 +1403,13 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9949,8 +9956,9 @@ def test_converse_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10016,20 +10024,22 @@ def test_converse_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_converse_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_converse_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "pre_converse_conversation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_converse_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_converse_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_converse_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10089,8 +10099,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10283,19 +10294,22 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_create_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10352,8 +10366,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10412,13 +10427,14 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_delete_conversation", + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteConversationRequest.pb( conversational_search_service.DeleteConversationRequest() @@ -10467,8 +10483,9 @@ def test_update_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10665,19 +10682,22 @@ def test_update_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_update_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_update_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10734,8 +10754,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10804,18 +10825,22 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_get_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10868,8 +10893,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10934,18 +10960,22 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_conversations", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_list_conversations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11005,8 +11035,9 @@ def test_answer_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11073,18 +11104,20 @@ def test_answer_query_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_answer_query" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_answer_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_answer_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_answer_query" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_answer_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_answer_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11144,8 +11177,9 @@ def test_stream_answer_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11216,19 +11250,22 @@ def test_stream_answer_query_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_stream_answer_query", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_stream_answer_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_stream_answer_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_stream_answer_query", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_stream_answer_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_stream_answer_query", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11288,8 +11325,9 @@ def test_get_answer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11368,18 +11406,20 @@ def test_get_answer_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_answer" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_answer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_answer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_get_answer" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_answer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_get_answer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11432,8 +11472,9 @@ def test_create_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11756,18 +11797,20 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11822,8 +11865,9 @@ def test_delete_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11882,13 +11926,13 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteSessionRequest.pb( conversational_search_service.DeleteSessionRequest() @@ -11937,8 +11981,9 @@ def test_update_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12265,18 +12310,20 @@ def test_update_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_update_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_update_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_update_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_update_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12331,8 +12378,9 @@ def test_get_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12407,18 +12455,20 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12471,8 +12521,9 @@ def test_list_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12537,18 +12588,20 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_list_sessions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12608,8 +12661,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12670,8 +12724,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12730,8 +12785,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13147,11 +13203,14 @@ def test_conversational_search_service_base_transport(): def test_conversational_search_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationalSearchServiceTransport( @@ -13168,9 +13227,12 @@ def test_conversational_search_service_base_transport_with_credentials_file(): def test_conversational_search_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationalSearchServiceTransport() @@ -13247,11 +13309,12 @@ def test_conversational_search_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -14096,6 +14159,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14241,6 +14336,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14386,6 +14515,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_data_store_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_data_store_service.py index d7e52598608e..ad754f86af7c 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_data_store_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_data_store_service.py @@ -137,6 +137,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataStoreServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -159,6 +160,10 @@ def test__get_default_mtls_endpoint(): DataStoreServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataStoreServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1328,11 +1333,13 @@ def test_data_store_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4750,8 +4757,9 @@ def test_create_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4965,20 +4973,21 @@ def test_create_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_create_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_create_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_create_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_create_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_create_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_create_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5031,8 +5040,9 @@ def test_get_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5111,17 +5121,20 @@ def test_get_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_get_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_get_data_store_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_get_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_get_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_get_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_get_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5174,8 +5187,9 @@ def test_list_data_stores_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5238,18 +5252,20 @@ def test_list_data_stores_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_list_data_stores" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_list_data_stores_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_list_data_stores" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_list_data_stores" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_list_data_stores_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_list_data_stores" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5307,8 +5323,9 @@ def test_delete_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5365,20 +5382,21 @@ def test_delete_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_delete_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_delete_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_delete_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_delete_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_delete_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_delete_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5433,8 +5451,9 @@ def test_update_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5672,18 +5691,20 @@ def test_update_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_update_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_update_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_update_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_update_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_update_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_update_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5738,8 +5759,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5800,8 +5822,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5860,8 +5883,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6104,11 +6128,14 @@ def test_data_store_service_base_transport(): def test_data_store_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataStoreServiceTransport( @@ -6125,9 +6152,12 @@ def test_data_store_service_base_transport_with_credentials_file(): def test_data_store_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataStoreServiceTransport() @@ -6199,11 +6229,12 @@ def test_data_store_service_transport_auth_gdch_credentials(transport_class): def test_data_store_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7013,6 +7044,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7158,6 +7221,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7303,6 +7400,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py index eed121a0b4a0..a27c6bb92ba3 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py @@ -138,6 +138,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -159,6 +160,10 @@ def test__get_default_mtls_endpoint(): assert ( DocumentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1323,11 +1328,13 @@ def test_document_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6175,8 +6182,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6248,17 +6256,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6313,8 +6323,9 @@ def test_list_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6379,17 +6390,20 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_list_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6449,8 +6463,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6634,17 +6649,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_create_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6701,8 +6719,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6888,17 +6907,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_update_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6953,8 +6975,9 @@ def test_delete_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7013,13 +7036,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = document_service.DeleteDocumentRequest.pb( document_service.DeleteDocumentRequest() @@ -7066,8 +7089,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7126,19 +7150,21 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_import_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7193,8 +7219,9 @@ def test_purge_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7253,19 +7280,21 @@ def test_purge_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_purge_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_purge_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_purge_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_purge_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_purge_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_purge_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7320,8 +7349,9 @@ def test_batch_get_documents_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7385,18 +7415,22 @@ def test_batch_get_documents_metadata_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_batch_get_documents_metadata" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_batch_get_documents_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_batch_get_documents_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_get_documents_metadata", + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_get_documents_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "pre_batch_get_documents_metadata", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7456,8 +7490,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7518,8 +7553,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7578,8 +7614,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7881,11 +7918,14 @@ def test_document_service_base_transport(): def test_document_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport( @@ -7902,9 +7942,12 @@ def test_document_service_base_transport_with_credentials_file(): def test_document_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport() @@ -7976,11 +8019,12 @@ def test_document_service_transport_auth_gdch_credentials(transport_class): def test_document_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8703,6 +8747,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8848,6 +8924,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8993,6 +9103,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_engine_service.py index 55c0ef900d4c..7e7176686950 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_engine_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EngineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): assert ( EngineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EngineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1286,11 +1291,13 @@ def test_engine_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4680,8 +4687,9 @@ def test_create_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4843,19 +4851,20 @@ def test_create_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_create_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_create_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_create_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_create_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_create_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_create_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4910,8 +4919,9 @@ def test_delete_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4970,19 +4980,20 @@ def test_delete_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_delete_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_delete_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_delete_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_delete_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_delete_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_delete_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5039,8 +5050,9 @@ def test_update_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5222,17 +5234,19 @@ def test_update_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_update_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_update_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_update_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_update_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_update_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_update_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5285,8 +5299,9 @@ def test_get_engine_rest_bad_request(request_type=engine_service.GetEngineReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5361,17 +5376,19 @@ def test_get_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_get_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_get_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_get_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_get_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_get_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_get_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5422,8 +5439,9 @@ def test_list_engines_rest_bad_request(request_type=engine_service.ListEnginesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5486,17 +5504,19 @@ def test_list_engines_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_list_engines" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_list_engines_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_list_engines" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_list_engines" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_list_engines_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_list_engines" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5553,8 +5573,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5615,8 +5636,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5675,8 +5697,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5913,11 +5936,14 @@ def test_engine_service_base_transport(): def test_engine_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EngineServiceTransport( @@ -5934,9 +5960,12 @@ def test_engine_service_base_transport_with_credentials_file(): def test_engine_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EngineServiceTransport() @@ -6008,11 +6037,12 @@ def test_engine_service_transport_auth_gdch_credentials(transport_class): def test_engine_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6650,6 +6680,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6795,6 +6857,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6940,6 +7036,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_grounded_generation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_grounded_generation_service.py index 407045bbd432..a2ac45a8312b 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_grounded_generation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_grounded_generation_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GroundedGenerationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): GroundedGenerationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GroundedGenerationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1360,11 +1365,13 @@ def test_grounded_generation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2569,8 +2576,9 @@ def test_generate_grounded_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2634,20 +2642,22 @@ def test_generate_grounded_content_rest_interceptors(null_interceptor): ) client = GroundedGenerationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_generate_grounded_content", - ) as post, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_generate_grounded_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "pre_generate_grounded_content", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_generate_grounded_content", + ) as post, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_generate_grounded_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "pre_generate_grounded_content", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2711,8 +2721,9 @@ def test_check_grounding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2779,18 +2790,20 @@ def test_check_grounding_rest_interceptors(null_interceptor): ) client = GroundedGenerationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, "post_check_grounding" - ) as post, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_check_grounding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, "pre_check_grounding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, "post_check_grounding" + ) as post, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_check_grounding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, "pre_check_grounding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2850,8 +2863,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2912,8 +2926,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2972,8 +2987,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3128,11 +3144,14 @@ def test_grounded_generation_service_base_transport(): def test_grounded_generation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroundedGenerationServiceTransport( @@ -3149,9 +3168,12 @@ def test_grounded_generation_service_base_transport_with_credentials_file(): def test_grounded_generation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroundedGenerationServiceTransport() @@ -3225,11 +3247,12 @@ def test_grounded_generation_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3858,6 +3881,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4003,6 +4058,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4148,6 +4237,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_identity_mapping_store_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_identity_mapping_store_service.py index 577c1e5ca9e1..507e881e49b8 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_identity_mapping_store_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_identity_mapping_store_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IdentityMappingStoreServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): IdentityMappingStoreServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + IdentityMappingStoreServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1397,11 +1402,13 @@ def test_identity_mapping_store_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5906,8 +5913,9 @@ def test_create_identity_mapping_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6059,20 +6067,22 @@ def test_create_identity_mapping_store_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_create_identity_mapping_store", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_create_identity_mapping_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_create_identity_mapping_store", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_create_identity_mapping_store", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_create_identity_mapping_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_create_identity_mapping_store", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6134,8 +6144,9 @@ def test_get_identity_mapping_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6202,20 +6213,22 @@ def test_get_identity_mapping_store_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_get_identity_mapping_store", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_get_identity_mapping_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_get_identity_mapping_store", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_get_identity_mapping_store", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_get_identity_mapping_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_get_identity_mapping_store", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6275,8 +6288,9 @@ def test_delete_identity_mapping_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6335,22 +6349,23 @@ def test_delete_identity_mapping_store_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_delete_identity_mapping_store", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_delete_identity_mapping_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_delete_identity_mapping_store", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_delete_identity_mapping_store", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_delete_identity_mapping_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_delete_identity_mapping_store", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6407,8 +6422,9 @@ def test_import_identity_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6467,22 +6483,23 @@ def test_import_identity_mappings_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_import_identity_mappings", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_import_identity_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_import_identity_mappings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_import_identity_mappings", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_import_identity_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_import_identity_mappings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6537,8 +6554,9 @@ def test_purge_identity_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6597,22 +6615,23 @@ def test_purge_identity_mappings_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_purge_identity_mappings", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_purge_identity_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_purge_identity_mappings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_purge_identity_mappings", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_purge_identity_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_purge_identity_mappings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6667,8 +6686,9 @@ def test_list_identity_mappings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6735,20 +6755,22 @@ def test_list_identity_mappings_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_list_identity_mappings", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_list_identity_mappings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_list_identity_mappings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_list_identity_mappings", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_list_identity_mappings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_list_identity_mappings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6810,8 +6832,9 @@ def test_list_identity_mapping_stores_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6878,20 +6901,22 @@ def test_list_identity_mapping_stores_rest_interceptors(null_interceptor): ) client = IdentityMappingStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_list_identity_mapping_stores", - ) as post, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "post_list_identity_mapping_stores_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityMappingStoreServiceRestInterceptor, - "pre_list_identity_mapping_stores", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_list_identity_mapping_stores", + ) as post, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "post_list_identity_mapping_stores_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityMappingStoreServiceRestInterceptor, + "pre_list_identity_mapping_stores", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6955,8 +6980,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7017,8 +7043,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7077,8 +7104,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7371,11 +7399,14 @@ def test_identity_mapping_store_service_base_transport(): def test_identity_mapping_store_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.identity_mapping_store_service.transports.IdentityMappingStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.identity_mapping_store_service.transports.IdentityMappingStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IdentityMappingStoreServiceTransport( @@ -7392,9 +7423,12 @@ def test_identity_mapping_store_service_base_transport_with_credentials_file(): def test_identity_mapping_store_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.identity_mapping_store_service.transports.IdentityMappingStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.identity_mapping_store_service.transports.IdentityMappingStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IdentityMappingStoreServiceTransport() @@ -7473,11 +7507,12 @@ def test_identity_mapping_store_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8213,6 +8248,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = IdentityMappingStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = IdentityMappingStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = IdentityMappingStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8358,6 +8425,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = IdentityMappingStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = IdentityMappingStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = IdentityMappingStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8503,6 +8604,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = IdentityMappingStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = IdentityMappingStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = IdentityMappingStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_project_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_project_service.py index 9aed562539f9..494af2bd187a 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_project_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_project_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProjectServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ProjectServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ProjectServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_project_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2040,8 +2047,9 @@ def test_provision_project_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2098,19 +2106,21 @@ def test_provision_project_rest_interceptors(null_interceptor): ) client = ProjectServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_provision_project" - ) as post, mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_provision_project_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectServiceRestInterceptor, "pre_provision_project" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProjectServiceRestInterceptor, "post_provision_project" + ) as post, + mock.patch.object( + transports.ProjectServiceRestInterceptor, + "post_provision_project_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "pre_provision_project" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2165,8 +2175,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2227,8 +2238,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2287,8 +2299,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2443,11 +2456,14 @@ def test_project_service_base_transport(): def test_project_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectServiceTransport( @@ -2464,9 +2480,12 @@ def test_project_service_base_transport_with_credentials_file(): def test_project_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectServiceTransport() @@ -2538,11 +2557,12 @@ def test_project_service_transport_auth_gdch_credentials(transport_class): def test_project_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3133,6 +3153,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3278,6 +3330,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3423,6 +3509,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_rank_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_rank_service.py index ae034a32436e..16587787a261 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_rank_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_rank_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RankServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RankServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RankServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1244,11 +1248,13 @@ def test_rank_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1817,8 +1823,9 @@ def test_rank_rest_bad_request(request_type=rank_service.RankRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1880,17 +1887,15 @@ def test_rank_rest_interceptors(null_interceptor): ) client = RankServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RankServiceRestInterceptor, "post_rank" - ) as post, mock.patch.object( - transports.RankServiceRestInterceptor, "post_rank_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RankServiceRestInterceptor, "pre_rank" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RankServiceRestInterceptor, "post_rank") as post, + mock.patch.object( + transports.RankServiceRestInterceptor, "post_rank_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RankServiceRestInterceptor, "pre_rank") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1943,8 +1948,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2005,8 +2011,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2065,8 +2072,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2197,11 +2205,14 @@ def test_rank_service_base_transport(): def test_rank_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RankServiceTransport( @@ -2218,9 +2229,12 @@ def test_rank_service_base_transport_with_credentials_file(): def test_rank_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RankServiceTransport() @@ -2292,11 +2306,12 @@ def test_rank_service_transport_auth_gdch_credentials(transport_class): def test_rank_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2848,6 +2863,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -2993,6 +3040,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3138,6 +3219,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_recommendation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_recommendation_service.py index 6c0b966887d3..b15767b20d36 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_recommendation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_recommendation_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RecommendationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): RecommendationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RecommendationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_recommendation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1945,8 +1952,9 @@ def test_recommend_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2015,17 +2023,20 @@ def test_recommend_rest_interceptors(null_interceptor): ) client = RecommendationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "post_recommend" - ) as post, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "post_recommend_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "pre_recommend" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, "post_recommend" + ) as post, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, + "post_recommend_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, "pre_recommend" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2085,8 +2096,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2147,8 +2159,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2207,8 +2220,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2339,11 +2353,14 @@ def test_recommendation_service_base_transport(): def test_recommendation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RecommendationServiceTransport( @@ -2360,9 +2377,12 @@ def test_recommendation_service_base_transport_with_credentials_file(): def test_recommendation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RecommendationServiceTransport() @@ -2434,11 +2454,12 @@ def test_recommendation_service_transport_auth_gdch_credentials(transport_class) def test_recommendation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3099,6 +3120,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3244,6 +3297,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3389,6 +3476,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py index 681a82b14387..9693d700c766 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SchemaServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( SchemaServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SchemaServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_schema_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4445,8 +4452,9 @@ def test_get_schema_rest_bad_request(request_type=schema_service.GetSchemaReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4512,17 +4520,19 @@ def test_get_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_get_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_get_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_get_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_get_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_get_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_get_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4573,8 +4583,9 @@ def test_list_schemas_rest_bad_request(request_type=schema_service.ListSchemasRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4637,17 +4648,19 @@ def test_list_schemas_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_list_schemas" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_list_schemas_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_list_schemas" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_list_schemas" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_list_schemas_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_list_schemas" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4702,8 +4715,9 @@ def test_create_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4832,19 +4846,20 @@ def test_create_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_create_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_create_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_create_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_create_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_create_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_create_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4901,8 +4916,9 @@ def test_update_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5035,19 +5051,20 @@ def test_update_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_update_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_update_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_update_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_update_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_update_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_update_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5102,8 +5119,9 @@ def test_delete_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5162,19 +5180,20 @@ def test_delete_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_delete_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_delete_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_delete_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_delete_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_delete_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_delete_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5229,8 +5248,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5291,8 +5311,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5351,8 +5372,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5589,11 +5611,14 @@ def test_schema_service_base_transport(): def test_schema_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SchemaServiceTransport( @@ -5610,9 +5635,12 @@ def test_schema_service_base_transport_with_credentials_file(): def test_schema_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SchemaServiceTransport() @@ -5684,11 +5712,12 @@ def test_schema_service_transport_auth_gdch_credentials(transport_class): def test_schema_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6324,6 +6353,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6469,6 +6530,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6614,6 +6709,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py index 9bb868c0d565..d7bd5ecff3cf 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SearchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( SearchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SearchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1279,11 +1284,13 @@ def test_search_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2881,8 +2888,9 @@ def test_search_rest_bad_request(request_type=search_service.SearchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2959,17 +2967,17 @@ def test_search_rest_interceptors(null_interceptor): ) client = SearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search" - ) as post, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SearchServiceRestInterceptor, "pre_search" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search" + ) as post, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SearchServiceRestInterceptor, "pre_search") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3022,8 +3030,9 @@ def test_search_lite_rest_bad_request(request_type=search_service.SearchRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3100,17 +3109,19 @@ def test_search_lite_rest_interceptors(null_interceptor): ) client = SearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_lite" - ) as post, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_lite_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SearchServiceRestInterceptor, "pre_search_lite" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_lite" + ) as post, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_lite_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SearchServiceRestInterceptor, "pre_search_lite" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3165,8 +3176,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3227,8 +3239,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3287,8 +3300,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3440,11 +3454,14 @@ def test_search_service_base_transport(): def test_search_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchServiceTransport( @@ -3461,9 +3478,12 @@ def test_search_service_base_transport_with_credentials_file(): def test_search_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchServiceTransport() @@ -3535,11 +3555,12 @@ def test_search_service_transport_auth_gdch_credentials(transport_class): def test_search_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4263,6 +4284,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4408,6 +4461,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4553,6 +4640,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_tuning_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_tuning_service.py index 4530aa03faea..ba0725c1854f 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_tuning_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_tuning_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SearchTuningServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): SearchTuningServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SearchTuningServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1349,11 +1354,13 @@ def test_search_tuning_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2381,8 +2388,9 @@ def test_train_custom_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2441,20 +2449,21 @@ def test_train_custom_model_rest_interceptors(null_interceptor): ) client = SearchTuningServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "post_train_custom_model" - ) as post, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, - "post_train_custom_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "pre_train_custom_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "post_train_custom_model" + ) as post, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, + "post_train_custom_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "pre_train_custom_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2509,8 +2518,9 @@ def test_list_custom_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2572,18 +2582,20 @@ def test_list_custom_models_rest_interceptors(null_interceptor): ) client = SearchTuningServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "post_list_custom_models" - ) as post, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, - "post_list_custom_models_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "pre_list_custom_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "post_list_custom_models" + ) as post, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, + "post_list_custom_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "pre_list_custom_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2643,8 +2655,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2705,8 +2718,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2765,8 +2779,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2944,11 +2959,14 @@ def test_search_tuning_service_base_transport(): def test_search_tuning_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchTuningServiceTransport( @@ -2965,9 +2983,12 @@ def test_search_tuning_service_base_transport_with_credentials_file(): def test_search_tuning_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchTuningServiceTransport() @@ -3039,11 +3060,12 @@ def test_search_tuning_service_transport_auth_gdch_credentials(transport_class): def test_search_tuning_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3676,6 +3698,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3821,6 +3875,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3966,6 +4054,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_serving_config_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_serving_config_service.py index 3c29c40b8d4e..3ae16eab3a87 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_serving_config_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_serving_config_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServingConfigServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): ServingConfigServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ServingConfigServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1348,11 +1353,13 @@ def test_serving_config_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2206,8 +2213,9 @@ def test_update_serving_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2451,18 +2459,20 @@ def test_update_serving_config_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_update_serving_config" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_update_serving_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_update_serving_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_update_serving_config" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_update_serving_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_update_serving_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2519,8 +2529,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2581,8 +2592,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2641,8 +2653,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2775,11 +2788,14 @@ def test_serving_config_service_base_transport(): def test_serving_config_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServingConfigServiceTransport( @@ -2796,9 +2812,12 @@ def test_serving_config_service_base_transport_with_credentials_file(): def test_serving_config_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServingConfigServiceTransport() @@ -2870,11 +2889,12 @@ def test_serving_config_service_transport_auth_gdch_credentials(transport_class) def test_serving_config_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3444,6 +3464,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3589,6 +3641,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3734,6 +3820,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_session_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_session_service.py index 7b98e5754d3b..8d5f6db94ec9 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_session_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_session_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): assert ( SessionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1292,11 +1297,13 @@ def test_session_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4578,8 +4585,9 @@ def test_create_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4902,17 +4910,20 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_create_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4967,8 +4978,9 @@ def test_delete_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5027,13 +5039,13 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteSessionRequest.pb( conversational_search_service.DeleteSessionRequest() @@ -5082,8 +5094,9 @@ def test_update_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5410,17 +5423,20 @@ def test_update_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_update_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_update_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_update_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_update_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, + "post_update_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_update_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5475,8 +5491,9 @@ def test_get_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5551,17 +5568,19 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_get_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_get_session_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5614,8 +5633,9 @@ def test_list_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5680,17 +5700,19 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_sessions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_sessions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5750,8 +5772,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5812,8 +5835,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5872,8 +5896,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6088,11 +6113,14 @@ def test_session_service_base_transport(): def test_session_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport( @@ -6109,9 +6137,12 @@ def test_session_service_base_transport_with_credentials_file(): def test_session_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport() @@ -6183,11 +6214,12 @@ def test_session_service_transport_auth_gdch_credentials(transport_class): def test_session_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6933,6 +6965,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7078,6 +7142,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7223,6 +7321,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_site_search_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_site_search_engine_service.py index 524865756e1f..10a92c5ad2d7 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_site_search_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_site_search_engine_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SiteSearchEngineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): SiteSearchEngineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SiteSearchEngineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1357,11 +1362,13 @@ def test_site_search_engine_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9914,8 +9921,9 @@ def test_get_site_search_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9980,18 +9988,22 @@ def test_get_site_search_engine_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_get_site_search_engine" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_site_search_engine_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_get_site_search_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_site_search_engine", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_site_search_engine_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_get_site_search_engine", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10051,8 +10063,9 @@ def test_create_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10195,20 +10208,21 @@ def test_create_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_create_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_create_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_create_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_create_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_create_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_create_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10263,8 +10277,9 @@ def test_batch_create_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10323,22 +10338,23 @@ def test_batch_create_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_create_target_sites", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_create_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_batch_create_target_sites", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_create_target_sites", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_create_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_batch_create_target_sites", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10393,8 +10409,9 @@ def test_get_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10473,18 +10490,20 @@ def test_get_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_get_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_get_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_get_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_get_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10543,8 +10562,9 @@ def test_update_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10689,20 +10709,21 @@ def test_update_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_update_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_update_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_update_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_update_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_update_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_update_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10757,8 +10778,9 @@ def test_delete_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10817,20 +10839,21 @@ def test_delete_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_delete_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_delete_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_delete_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_delete_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10885,8 +10908,9 @@ def test_list_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10955,18 +10979,20 @@ def test_list_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_list_target_sites" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_list_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_list_target_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_list_target_sites" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_list_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_list_target_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11026,8 +11052,9 @@ def test_create_sitemap_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11158,20 +11185,21 @@ def test_create_sitemap_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_create_sitemap" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_create_sitemap_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_create_sitemap" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_create_sitemap" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_create_sitemap_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_create_sitemap" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11226,8 +11254,9 @@ def test_delete_sitemap_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11286,20 +11315,21 @@ def test_delete_sitemap_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_delete_sitemap" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_delete_sitemap_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_sitemap" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_delete_sitemap" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_delete_sitemap_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_sitemap" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11354,8 +11384,9 @@ def test_fetch_sitemaps_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11417,18 +11448,20 @@ def test_fetch_sitemaps_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_fetch_sitemaps" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_sitemaps_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_fetch_sitemaps" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_fetch_sitemaps" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_sitemaps_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_fetch_sitemaps" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11488,8 +11521,9 @@ def test_enable_advanced_site_search_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11548,22 +11582,23 @@ def test_enable_advanced_site_search_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_enable_advanced_site_search", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_enable_advanced_site_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_enable_advanced_site_search", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_enable_advanced_site_search", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_enable_advanced_site_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_enable_advanced_site_search", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11618,8 +11653,9 @@ def test_disable_advanced_site_search_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11678,22 +11714,23 @@ def test_disable_advanced_site_search_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_disable_advanced_site_search", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_disable_advanced_site_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_disable_advanced_site_search", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_disable_advanced_site_search", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_disable_advanced_site_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_disable_advanced_site_search", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11748,8 +11785,9 @@ def test_recrawl_uris_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11808,20 +11846,21 @@ def test_recrawl_uris_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_recrawl_uris" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_recrawl_uris_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_recrawl_uris" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_recrawl_uris" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_recrawl_uris_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_recrawl_uris" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11876,8 +11915,9 @@ def test_batch_verify_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11936,22 +11976,23 @@ def test_batch_verify_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_verify_target_sites", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_verify_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_batch_verify_target_sites", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_verify_target_sites", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_verify_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_batch_verify_target_sites", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12006,8 +12047,9 @@ def test_fetch_domain_verification_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12078,20 +12120,22 @@ def test_fetch_domain_verification_status_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_domain_verification_status", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_domain_verification_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_fetch_domain_verification_status", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_domain_verification_status", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_domain_verification_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_fetch_domain_verification_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12155,8 +12199,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12217,8 +12262,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12277,8 +12323,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12745,11 +12792,14 @@ def test_site_search_engine_service_base_transport(): def test_site_search_engine_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteSearchEngineServiceTransport( @@ -12766,9 +12816,12 @@ def test_site_search_engine_service_base_transport_with_credentials_file(): def test_site_search_engine_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteSearchEngineServiceTransport() @@ -12842,11 +12895,12 @@ def test_site_search_engine_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13551,6 +13605,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13696,6 +13782,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13841,6 +13961,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py index cd34e85adbba..bf56dd7fb150 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserEventServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): UserEventServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserEventServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1326,11 +1331,13 @@ def test_user_event_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3319,8 +3326,9 @@ def test_write_user_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3536,18 +3544,20 @@ def test_write_user_event_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_write_user_event" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_write_user_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_write_user_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_write_user_event" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_write_user_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_write_user_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3600,8 +3610,9 @@ def test_collect_user_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3663,18 +3674,20 @@ def test_collect_user_event_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_collect_user_event" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_collect_user_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_collect_user_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_collect_user_event" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_collect_user_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_collect_user_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3727,8 +3740,9 @@ def test_purge_user_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3785,20 +3799,21 @@ def test_purge_user_events_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_purge_user_events" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_purge_user_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_purge_user_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_purge_user_events" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_purge_user_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_purge_user_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3851,8 +3866,9 @@ def test_import_user_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3909,20 +3925,21 @@ def test_import_user_events_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_import_user_events" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_import_user_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_import_user_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_import_user_events" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_import_user_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_import_user_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3977,8 +3994,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4039,8 +4057,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4099,8 +4118,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4322,11 +4342,14 @@ def test_user_event_service_base_transport(): def test_user_event_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserEventServiceTransport( @@ -4343,9 +4366,12 @@ def test_user_event_service_base_transport_with_credentials_file(): def test_user_event_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserEventServiceTransport() @@ -4417,11 +4443,12 @@ def test_user_event_service_transport_auth_gdch_credentials(transport_class): def test_user_event_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5090,6 +5117,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5235,6 +5294,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5380,6 +5473,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_license_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_license_service.py index 23b32c283dc1..7a7326bd2dad 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_license_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_license_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserLicenseServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): UserLicenseServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserLicenseServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_user_license_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2800,8 +2807,9 @@ def test_list_user_licenses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2864,18 +2872,20 @@ def test_list_user_licenses_rest_interceptors(null_interceptor): ) client = UserLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserLicenseServiceRestInterceptor, "post_list_user_licenses" - ) as post, mock.patch.object( - transports.UserLicenseServiceRestInterceptor, - "post_list_user_licenses_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserLicenseServiceRestInterceptor, "pre_list_user_licenses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserLicenseServiceRestInterceptor, "post_list_user_licenses" + ) as post, + mock.patch.object( + transports.UserLicenseServiceRestInterceptor, + "post_list_user_licenses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserLicenseServiceRestInterceptor, "pre_list_user_licenses" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2933,8 +2943,9 @@ def test_batch_update_user_licenses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2991,20 +3002,23 @@ def test_batch_update_user_licenses_rest_interceptors(null_interceptor): ) client = UserLicenseServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserLicenseServiceRestInterceptor, "post_batch_update_user_licenses" - ) as post, mock.patch.object( - transports.UserLicenseServiceRestInterceptor, - "post_batch_update_user_licenses_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserLicenseServiceRestInterceptor, "pre_batch_update_user_licenses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserLicenseServiceRestInterceptor, + "post_batch_update_user_licenses", + ) as post, + mock.patch.object( + transports.UserLicenseServiceRestInterceptor, + "post_batch_update_user_licenses_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserLicenseServiceRestInterceptor, + "pre_batch_update_user_licenses", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3059,8 +3073,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3121,8 +3136,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3181,8 +3197,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3360,11 +3377,14 @@ def test_user_license_service_base_transport(): def test_user_license_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1.services.user_license_service.transports.UserLicenseServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1.services.user_license_service.transports.UserLicenseServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserLicenseServiceTransport( @@ -3381,9 +3401,12 @@ def test_user_license_service_base_transport_with_credentials_file(): def test_user_license_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1.services.user_license_service.transports.UserLicenseServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1.services.user_license_service.transports.UserLicenseServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserLicenseServiceTransport() @@ -3455,11 +3478,12 @@ def test_user_license_service_transport_auth_gdch_credentials(transport_class): def test_user_license_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4089,6 +4113,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = UserLicenseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = UserLicenseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = UserLicenseServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4234,6 +4290,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = UserLicenseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = UserLicenseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = UserLicenseServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4379,6 +4469,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = UserLicenseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = UserLicenseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = UserLicenseServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_acl_config_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_acl_config_service.py index fb02248e0550..91af16ab8b6f 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_acl_config_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_acl_config_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AclConfigServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): AclConfigServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AclConfigServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1315,11 +1320,13 @@ def test_acl_config_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2450,8 +2457,9 @@ def test_update_acl_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2590,18 +2598,20 @@ def test_update_acl_config_rest_interceptors(null_interceptor): ) client = AclConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AclConfigServiceRestInterceptor, "post_update_acl_config" - ) as post, mock.patch.object( - transports.AclConfigServiceRestInterceptor, - "post_update_acl_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AclConfigServiceRestInterceptor, "pre_update_acl_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AclConfigServiceRestInterceptor, "post_update_acl_config" + ) as post, + mock.patch.object( + transports.AclConfigServiceRestInterceptor, + "post_update_acl_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AclConfigServiceRestInterceptor, "pre_update_acl_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2654,8 +2664,9 @@ def test_get_acl_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2718,17 +2729,20 @@ def test_get_acl_config_rest_interceptors(null_interceptor): ) client = AclConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AclConfigServiceRestInterceptor, "post_get_acl_config" - ) as post, mock.patch.object( - transports.AclConfigServiceRestInterceptor, "post_get_acl_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AclConfigServiceRestInterceptor, "pre_get_acl_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AclConfigServiceRestInterceptor, "post_get_acl_config" + ) as post, + mock.patch.object( + transports.AclConfigServiceRestInterceptor, + "post_get_acl_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AclConfigServiceRestInterceptor, "pre_get_acl_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2786,8 +2800,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2853,8 +2868,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2920,8 +2936,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3077,11 +3094,14 @@ def test_acl_config_service_base_transport(): def test_acl_config_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.acl_config_service.transports.AclConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.acl_config_service.transports.AclConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AclConfigServiceTransport( @@ -3098,9 +3118,12 @@ def test_acl_config_service_base_transport_with_credentials_file(): def test_acl_config_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.acl_config_service.transports.AclConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.acl_config_service.transports.AclConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AclConfigServiceTransport() @@ -3172,11 +3195,12 @@ def test_acl_config_service_transport_auth_gdch_credentials(transport_class): def test_acl_config_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3739,6 +3763,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AclConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AclConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AclConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3884,6 +3940,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AclConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AclConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AclConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4029,6 +4119,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AclConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AclConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AclConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_chunk_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_chunk_service.py index 479b7c654124..0e6f0800a35c 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_chunk_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_chunk_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ChunkServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ChunkServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ChunkServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1260,11 +1265,13 @@ def test_chunk_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2805,8 +2812,9 @@ def test_get_chunk_rest_bad_request(request_type=chunk_service.GetChunkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2877,17 +2885,19 @@ def test_get_chunk_rest_interceptors(null_interceptor): ) client = ChunkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChunkServiceRestInterceptor, "post_get_chunk" - ) as post, mock.patch.object( - transports.ChunkServiceRestInterceptor, "post_get_chunk_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChunkServiceRestInterceptor, "pre_get_chunk" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChunkServiceRestInterceptor, "post_get_chunk" + ) as post, + mock.patch.object( + transports.ChunkServiceRestInterceptor, "post_get_chunk_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChunkServiceRestInterceptor, "pre_get_chunk" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2938,8 +2948,9 @@ def test_list_chunks_rest_bad_request(request_type=chunk_service.ListChunksReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3004,17 +3015,19 @@ def test_list_chunks_rest_interceptors(null_interceptor): ) client = ChunkServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ChunkServiceRestInterceptor, "post_list_chunks" - ) as post, mock.patch.object( - transports.ChunkServiceRestInterceptor, "post_list_chunks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ChunkServiceRestInterceptor, "pre_list_chunks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ChunkServiceRestInterceptor, "post_list_chunks" + ) as post, + mock.patch.object( + transports.ChunkServiceRestInterceptor, "post_list_chunks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ChunkServiceRestInterceptor, "pre_list_chunks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3074,8 +3087,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3141,8 +3155,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3208,8 +3223,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3363,11 +3379,14 @@ def test_chunk_service_base_transport(): def test_chunk_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.chunk_service.transports.ChunkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.chunk_service.transports.ChunkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChunkServiceTransport( @@ -3384,9 +3403,12 @@ def test_chunk_service_base_transport_with_credentials_file(): def test_chunk_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.chunk_service.transports.ChunkServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.chunk_service.transports.ChunkServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ChunkServiceTransport() @@ -3458,11 +3480,12 @@ def test_chunk_service_transport_auth_gdch_credentials(transport_class): def test_chunk_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4062,6 +4085,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ChunkServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ChunkServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ChunkServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4207,6 +4262,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ChunkServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ChunkServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ChunkServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4352,6 +4441,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ChunkServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ChunkServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ChunkServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py index 422039307864..67d77446f2cf 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CompletionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): CompletionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CompletionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1329,11 +1334,13 @@ def test_completion_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3706,8 +3713,9 @@ def test_complete_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3772,17 +3780,20 @@ def test_complete_query_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_complete_query" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_complete_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_complete_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "post_complete_query" + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_complete_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "pre_complete_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3842,8 +3853,9 @@ def test_import_suggestion_deny_list_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3902,22 +3914,23 @@ def test_import_suggestion_deny_list_entries_rest_interceptors(null_interceptor) ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_suggestion_deny_list_entries", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_suggestion_deny_list_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "pre_import_suggestion_deny_list_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_suggestion_deny_list_entries", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_suggestion_deny_list_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_import_suggestion_deny_list_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3972,8 +3985,9 @@ def test_purge_suggestion_deny_list_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4032,22 +4046,23 @@ def test_purge_suggestion_deny_list_entries_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_suggestion_deny_list_entries", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_suggestion_deny_list_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "pre_purge_suggestion_deny_list_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_suggestion_deny_list_entries", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_suggestion_deny_list_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_purge_suggestion_deny_list_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4102,8 +4117,9 @@ def test_import_completion_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4162,21 +4178,23 @@ def test_import_completion_suggestions_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_completion_suggestions", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_completion_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_import_completion_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_completion_suggestions", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_completion_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_import_completion_suggestions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4231,8 +4249,9 @@ def test_purge_completion_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4291,20 +4310,23 @@ def test_purge_completion_suggestions_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_purge_completion_suggestions" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_completion_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_purge_completion_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_completion_suggestions", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_completion_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_purge_completion_suggestions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4362,8 +4384,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4429,8 +4452,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4496,8 +4520,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4744,11 +4769,14 @@ def test_completion_service_base_transport(): def test_completion_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompletionServiceTransport( @@ -4765,9 +4793,12 @@ def test_completion_service_base_transport_with_credentials_file(): def test_completion_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompletionServiceTransport() @@ -4839,11 +4870,12 @@ def test_completion_service_transport_auth_gdch_credentials(transport_class): def test_completion_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5452,6 +5484,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5597,6 +5661,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5742,6 +5840,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_control_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_control_service.py index ff401cea34eb..9ddc211c42f9 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_control_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_control_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ControlServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ControlServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ControlServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_control_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4614,8 +4621,9 @@ def test_create_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4781,17 +4789,20 @@ def test_create_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_create_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_create_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_create_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_create_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, + "post_create_control_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_create_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4846,8 +4857,9 @@ def test_delete_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4906,13 +4918,13 @@ def test_delete_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_delete_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_delete_control" + ) as pre, + ): pre.assert_not_called() pb_message = control_service.DeleteControlRequest.pb( control_service.DeleteControlRequest() @@ -4961,8 +4973,9 @@ def test_update_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5132,17 +5145,20 @@ def test_update_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_update_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_update_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_update_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_update_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, + "post_update_control_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_update_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5195,8 +5211,9 @@ def test_get_control_rest_bad_request(request_type=control_service.GetControlReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5271,17 +5288,19 @@ def test_get_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_get_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_get_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_get_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_get_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_get_control_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_get_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5334,8 +5353,9 @@ def test_list_controls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5398,17 +5418,19 @@ def test_list_controls_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_list_controls" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_list_controls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_list_controls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_list_controls" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_list_controls_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_list_controls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5471,8 +5493,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5538,8 +5561,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5605,8 +5629,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5823,11 +5848,14 @@ def test_control_service_base_transport(): def test_control_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ControlServiceTransport( @@ -5844,9 +5872,12 @@ def test_control_service_base_transport_with_credentials_file(): def test_control_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ControlServiceTransport() @@ -5918,11 +5949,12 @@ def test_control_service_transport_auth_gdch_credentials(transport_class): def test_control_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6526,6 +6558,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6671,6 +6735,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6816,6 +6914,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py index 26c7998a3b3a..ee2907ed0b66 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationalSearchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): ConversationalSearchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationalSearchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1397,11 +1402,13 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9489,8 +9496,9 @@ def test_converse_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9559,20 +9567,22 @@ def test_converse_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_converse_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_converse_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "pre_converse_conversation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_converse_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_converse_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_converse_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9632,8 +9642,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9835,19 +9846,22 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_create_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9904,8 +9918,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9964,13 +9979,14 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_delete_conversation", + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteConversationRequest.pb( conversational_search_service.DeleteConversationRequest() @@ -10019,8 +10035,9 @@ def test_update_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10226,19 +10243,22 @@ def test_update_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_update_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_update_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10295,8 +10315,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10365,18 +10386,22 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_get_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10429,8 +10454,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10495,18 +10521,22 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_conversations", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_list_conversations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10566,8 +10596,9 @@ def test_answer_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10634,18 +10665,20 @@ def test_answer_query_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_answer_query" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_answer_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_answer_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_answer_query" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_answer_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_answer_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10705,8 +10738,9 @@ def test_get_answer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10783,18 +10817,20 @@ def test_get_answer_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_answer" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_answer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_answer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_get_answer" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_answer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_get_answer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10847,8 +10883,9 @@ def test_create_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11094,18 +11131,20 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11160,8 +11199,9 @@ def test_delete_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11220,13 +11260,13 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteSessionRequest.pb( conversational_search_service.DeleteSessionRequest() @@ -11275,8 +11315,9 @@ def test_update_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11526,18 +11567,20 @@ def test_update_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_update_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_update_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_update_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_update_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11592,8 +11635,9 @@ def test_get_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11666,18 +11710,20 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11730,8 +11776,9 @@ def test_list_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11796,18 +11843,20 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_list_sessions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11870,8 +11919,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11937,8 +11987,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12004,8 +12055,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12400,11 +12452,14 @@ def test_conversational_search_service_base_transport(): def test_conversational_search_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationalSearchServiceTransport( @@ -12421,9 +12476,12 @@ def test_conversational_search_service_base_transport_with_credentials_file(): def test_conversational_search_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationalSearchServiceTransport() @@ -12500,11 +12558,12 @@ def test_conversational_search_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13309,6 +13368,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13454,6 +13545,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13599,6 +13724,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py index c569a8305d2b..b7d6dc56488c 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py @@ -139,6 +139,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataStoreServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +162,10 @@ def test__get_default_mtls_endpoint(): DataStoreServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataStoreServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_data_store_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5930,8 +5937,9 @@ def test_create_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6123,20 +6131,21 @@ def test_create_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_create_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_create_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_create_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_create_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_create_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_create_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6189,8 +6198,9 @@ def test_get_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6265,17 +6275,20 @@ def test_get_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_get_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_get_data_store_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_get_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_get_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_get_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_get_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6328,8 +6341,9 @@ def test_list_data_stores_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6392,18 +6406,20 @@ def test_list_data_stores_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_list_data_stores" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_list_data_stores_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_list_data_stores" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_list_data_stores" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_list_data_stores_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_list_data_stores" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6461,8 +6477,9 @@ def test_delete_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6519,20 +6536,21 @@ def test_delete_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_delete_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_delete_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_delete_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_delete_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_delete_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_delete_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6587,8 +6605,9 @@ def test_update_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6800,18 +6819,20 @@ def test_update_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_update_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_update_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_update_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_update_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_update_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_update_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6866,8 +6887,9 @@ def test_get_document_processing_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6934,19 +6956,22 @@ def test_get_document_processing_config_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_get_document_processing_config", - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_get_document_processing_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_get_document_processing_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_get_document_processing_config", + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_get_document_processing_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "pre_get_document_processing_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7008,8 +7033,9 @@ def test_update_document_processing_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7172,20 +7198,22 @@ def test_update_document_processing_config_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_update_document_processing_config", - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_update_document_processing_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "pre_update_document_processing_config", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_update_document_processing_config", + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_update_document_processing_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "pre_update_document_processing_config", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7248,8 +7276,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7315,8 +7344,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7382,8 +7412,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7674,11 +7705,14 @@ def test_data_store_service_base_transport(): def test_data_store_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataStoreServiceTransport( @@ -7695,9 +7729,12 @@ def test_data_store_service_base_transport_with_credentials_file(): def test_data_store_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataStoreServiceTransport() @@ -7769,11 +7806,12 @@ def test_data_store_service_transport_auth_gdch_credentials(transport_class): def test_data_store_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8473,6 +8511,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8618,6 +8688,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8763,6 +8867,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py index 2a5419353dd0..d596b46fc1d8 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py @@ -138,6 +138,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -159,6 +160,10 @@ def test__get_default_mtls_endpoint(): assert ( DocumentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1323,11 +1328,13 @@ def test_document_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6776,8 +6783,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6849,17 +6857,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6914,8 +6924,9 @@ def test_list_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6980,17 +6991,20 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_list_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7050,8 +7064,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7230,17 +7245,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_create_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7297,8 +7315,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7479,17 +7498,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_update_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7544,8 +7566,9 @@ def test_delete_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7604,13 +7627,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = document_service.DeleteDocumentRequest.pb( document_service.DeleteDocumentRequest() @@ -7657,8 +7680,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7717,19 +7741,21 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_import_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7784,8 +7810,9 @@ def test_purge_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7844,19 +7871,21 @@ def test_purge_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_purge_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_purge_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_purge_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_purge_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_purge_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_purge_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7911,8 +7940,9 @@ def test_get_processed_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7978,18 +8008,20 @@ def test_get_processed_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_processed_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_get_processed_document_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_processed_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_processed_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_get_processed_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_processed_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8044,8 +8076,9 @@ def test_batch_get_documents_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8109,18 +8142,22 @@ def test_batch_get_documents_metadata_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_batch_get_documents_metadata" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_batch_get_documents_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_batch_get_documents_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_get_documents_metadata", + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_get_documents_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "pre_batch_get_documents_metadata", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8183,8 +8220,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8250,8 +8288,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8317,8 +8356,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8645,11 +8685,14 @@ def test_document_service_base_transport(): def test_document_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport( @@ -8666,9 +8709,12 @@ def test_document_service_base_transport_with_credentials_file(): def test_document_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport() @@ -8740,11 +8786,12 @@ def test_document_service_transport_auth_gdch_credentials(transport_class): def test_document_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9433,6 +9480,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9578,6 +9657,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9723,6 +9836,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py index d2acabe4e614..9325904de81a 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EngineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): assert ( EngineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EngineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1286,11 +1291,13 @@ def test_engine_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6263,8 +6270,9 @@ def test_create_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6425,19 +6433,20 @@ def test_create_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_create_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_create_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_create_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_create_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_create_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_create_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6492,8 +6501,9 @@ def test_delete_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6552,19 +6562,20 @@ def test_delete_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_delete_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_delete_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_delete_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_delete_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_delete_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_delete_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6621,8 +6632,9 @@ def test_update_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6801,17 +6813,19 @@ def test_update_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_update_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_update_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_update_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_update_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_update_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_update_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6864,8 +6878,9 @@ def test_get_engine_rest_bad_request(request_type=engine_service.GetEngineReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6938,17 +6953,19 @@ def test_get_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_get_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_get_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_get_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_get_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_get_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_get_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6999,8 +7016,9 @@ def test_list_engines_rest_bad_request(request_type=engine_service.ListEnginesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7063,17 +7081,19 @@ def test_list_engines_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_list_engines" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_list_engines_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_list_engines" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_list_engines" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_list_engines_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_list_engines" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7128,8 +7148,9 @@ def test_pause_engine_rest_bad_request(request_type=engine_service.PauseEngineRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7202,17 +7223,19 @@ def test_pause_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_pause_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_pause_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_pause_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_pause_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_pause_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_pause_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7267,8 +7290,9 @@ def test_resume_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7341,17 +7365,19 @@ def test_resume_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_resume_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_resume_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_resume_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_resume_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_resume_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_resume_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7404,8 +7430,9 @@ def test_tune_engine_rest_bad_request(request_type=engine_service.TuneEngineRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7464,19 +7491,20 @@ def test_tune_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_tune_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_tune_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_tune_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_tune_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_tune_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_tune_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7534,8 +7562,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7601,8 +7630,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7668,8 +7698,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7971,11 +8002,14 @@ def test_engine_service_base_transport(): def test_engine_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EngineServiceTransport( @@ -7992,9 +8026,12 @@ def test_engine_service_base_transport_with_credentials_file(): def test_engine_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EngineServiceTransport() @@ -8066,11 +8103,12 @@ def test_engine_service_transport_auth_gdch_credentials(transport_class): def test_engine_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8717,6 +8755,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8862,6 +8932,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9007,6 +9111,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_estimate_billing_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_estimate_billing_service.py index 9890197da7fe..ff02f42ea691 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_estimate_billing_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_estimate_billing_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EstimateBillingServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): EstimateBillingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EstimateBillingServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1355,11 +1360,13 @@ def test_estimate_billing_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1955,8 +1962,9 @@ def test_estimate_data_size_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2013,20 +2021,21 @@ def test_estimate_data_size_rest_interceptors(null_interceptor): ) client = EstimateBillingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EstimateBillingServiceRestInterceptor, "post_estimate_data_size" - ) as post, mock.patch.object( - transports.EstimateBillingServiceRestInterceptor, - "post_estimate_data_size_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EstimateBillingServiceRestInterceptor, "pre_estimate_data_size" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EstimateBillingServiceRestInterceptor, "post_estimate_data_size" + ) as post, + mock.patch.object( + transports.EstimateBillingServiceRestInterceptor, + "post_estimate_data_size_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EstimateBillingServiceRestInterceptor, "pre_estimate_data_size" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2084,8 +2093,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2151,8 +2161,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2218,8 +2229,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2376,11 +2388,14 @@ def test_estimate_billing_service_base_transport(): def test_estimate_billing_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.estimate_billing_service.transports.EstimateBillingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.estimate_billing_service.transports.EstimateBillingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EstimateBillingServiceTransport( @@ -2397,9 +2412,12 @@ def test_estimate_billing_service_base_transport_with_credentials_file(): def test_estimate_billing_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.estimate_billing_service.transports.EstimateBillingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.estimate_billing_service.transports.EstimateBillingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EstimateBillingServiceTransport() @@ -2473,11 +2491,12 @@ def test_estimate_billing_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3073,6 +3092,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EstimateBillingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EstimateBillingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EstimateBillingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3218,6 +3269,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EstimateBillingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EstimateBillingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EstimateBillingServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3363,6 +3448,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EstimateBillingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EstimateBillingServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EstimateBillingServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_evaluation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_evaluation_service.py index 0a8ade1ef74e..1bb9edef9858 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_evaluation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_evaluation_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EvaluationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): EvaluationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EvaluationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1334,11 +1339,13 @@ def test_evaluation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4359,8 +4366,9 @@ def test_get_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4425,17 +4433,20 @@ def test_get_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_get_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_get_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4488,8 +4499,9 @@ def test_list_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4552,18 +4564,20 @@ def test_list_evaluations_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluations" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluations" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4621,8 +4635,9 @@ def test_create_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4906,20 +4921,21 @@ def test_create_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_create_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_create_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_create_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_create_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4974,8 +4990,9 @@ def test_list_evaluation_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5040,18 +5057,20 @@ def test_list_evaluation_results_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluation_results" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluation_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluation_results" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5114,8 +5133,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5181,8 +5201,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5248,8 +5269,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5471,11 +5493,14 @@ def test_evaluation_service_base_transport(): def test_evaluation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EvaluationServiceTransport( @@ -5492,9 +5517,12 @@ def test_evaluation_service_base_transport_with_credentials_file(): def test_evaluation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EvaluationServiceTransport() @@ -5566,11 +5594,12 @@ def test_evaluation_service_transport_auth_gdch_credentials(transport_class): def test_evaluation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6377,6 +6406,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6522,6 +6583,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6667,6 +6762,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_grounded_generation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_grounded_generation_service.py index 2345293af56e..5b4033afc99c 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_grounded_generation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_grounded_generation_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GroundedGenerationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): GroundedGenerationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GroundedGenerationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1363,11 +1368,13 @@ def test_grounded_generation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1944,8 +1951,9 @@ def test_check_grounding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2012,18 +2020,20 @@ def test_check_grounding_rest_interceptors(null_interceptor): ) client = GroundedGenerationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, "post_check_grounding" - ) as post, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_check_grounding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, "pre_check_grounding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, "post_check_grounding" + ) as post, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_check_grounding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, "pre_check_grounding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2086,8 +2096,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2153,8 +2164,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2220,8 +2232,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2354,11 +2367,14 @@ def test_grounded_generation_service_base_transport(): def test_grounded_generation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroundedGenerationServiceTransport( @@ -2375,9 +2391,12 @@ def test_grounded_generation_service_base_transport_with_credentials_file(): def test_grounded_generation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroundedGenerationServiceTransport() @@ -2451,11 +2470,12 @@ def test_grounded_generation_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3024,6 +3044,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3169,6 +3221,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3314,6 +3400,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_project_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_project_service.py index 31d80cbaf9c1..4473c1d42251 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_project_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_project_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProjectServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): assert ( ProjectServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ProjectServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1287,11 +1292,13 @@ def test_project_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3216,8 +3223,9 @@ def test_get_project_rest_bad_request(request_type=project_service.GetProjectReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3280,17 +3288,19 @@ def test_get_project_rest_interceptors(null_interceptor): ) client = ProjectServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_get_project" - ) as post, mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_get_project_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectServiceRestInterceptor, "pre_get_project" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "post_get_project" + ) as post, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "post_get_project_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "pre_get_project" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3343,8 +3353,9 @@ def test_provision_project_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3401,19 +3412,21 @@ def test_provision_project_rest_interceptors(null_interceptor): ) client = ProjectServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_provision_project" - ) as post, mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_provision_project_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectServiceRestInterceptor, "pre_provision_project" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProjectServiceRestInterceptor, "post_provision_project" + ) as post, + mock.patch.object( + transports.ProjectServiceRestInterceptor, + "post_provision_project_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "pre_provision_project" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3466,8 +3479,9 @@ def test_report_consent_change_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3530,18 +3544,20 @@ def test_report_consent_change_rest_interceptors(null_interceptor): ) client = ProjectServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_report_consent_change" - ) as post, mock.patch.object( - transports.ProjectServiceRestInterceptor, - "post_report_consent_change_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ProjectServiceRestInterceptor, "pre_report_consent_change" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "post_report_consent_change" + ) as post, + mock.patch.object( + transports.ProjectServiceRestInterceptor, + "post_report_consent_change_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "pre_report_consent_change" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3599,8 +3615,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3666,8 +3683,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3733,8 +3751,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3935,11 +3954,14 @@ def test_project_service_base_transport(): def test_project_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectServiceTransport( @@ -3956,9 +3978,12 @@ def test_project_service_base_transport_with_credentials_file(): def test_project_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectServiceTransport() @@ -4030,11 +4055,12 @@ def test_project_service_transport_auth_gdch_credentials(transport_class): def test_project_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4631,6 +4657,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4776,6 +4834,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4921,6 +5013,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_rank_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_rank_service.py index 865361adadcf..311fe02c1993 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_rank_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_rank_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RankServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RankServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RankServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1244,11 +1248,13 @@ def test_rank_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1817,8 +1823,9 @@ def test_rank_rest_bad_request(request_type=rank_service.RankRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1880,17 +1887,15 @@ def test_rank_rest_interceptors(null_interceptor): ) client = RankServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RankServiceRestInterceptor, "post_rank" - ) as post, mock.patch.object( - transports.RankServiceRestInterceptor, "post_rank_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RankServiceRestInterceptor, "pre_rank" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RankServiceRestInterceptor, "post_rank") as post, + mock.patch.object( + transports.RankServiceRestInterceptor, "post_rank_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RankServiceRestInterceptor, "pre_rank") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1946,8 +1951,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2013,8 +2019,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2080,8 +2087,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2214,11 +2222,14 @@ def test_rank_service_base_transport(): def test_rank_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RankServiceTransport( @@ -2235,9 +2246,12 @@ def test_rank_service_base_transport_with_credentials_file(): def test_rank_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RankServiceTransport() @@ -2309,11 +2323,12 @@ def test_rank_service_transport_auth_gdch_credentials(transport_class): def test_rank_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2865,6 +2880,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3010,6 +3057,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3155,6 +3236,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py index 3b683d4a36c4..6ca0fc1dc5da 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RecommendationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): RecommendationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RecommendationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_recommendation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1945,8 +1952,9 @@ def test_recommend_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2015,17 +2023,20 @@ def test_recommend_rest_interceptors(null_interceptor): ) client = RecommendationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "post_recommend" - ) as post, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "post_recommend_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "pre_recommend" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, "post_recommend" + ) as post, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, + "post_recommend_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, "pre_recommend" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2088,8 +2099,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2155,8 +2167,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2222,8 +2235,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2356,11 +2370,14 @@ def test_recommendation_service_base_transport(): def test_recommendation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RecommendationServiceTransport( @@ -2377,9 +2394,12 @@ def test_recommendation_service_base_transport_with_credentials_file(): def test_recommendation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RecommendationServiceTransport() @@ -2451,11 +2471,12 @@ def test_recommendation_service_transport_auth_gdch_credentials(transport_class) def test_recommendation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3116,6 +3137,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3261,6 +3314,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3406,6 +3493,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_service.py index a0746e1ed4d5..b6eecf4da12b 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SampleQueryServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): SampleQueryServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SampleQueryServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1336,11 +1341,13 @@ def test_sample_query_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5164,8 +5171,9 @@ def test_get_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5230,18 +5238,20 @@ def test_get_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_get_sample_query" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_get_sample_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_get_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_get_sample_query" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_get_sample_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_get_sample_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5296,8 +5306,9 @@ def test_list_sample_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5362,18 +5373,20 @@ def test_list_sample_queries_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_list_sample_queries" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_list_sample_queries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_list_sample_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_list_sample_queries" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_list_sample_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_list_sample_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5433,8 +5446,9 @@ def test_create_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5578,18 +5592,20 @@ def test_create_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_create_sample_query" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_create_sample_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_create_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_create_sample_query" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_create_sample_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_create_sample_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5648,8 +5664,9 @@ def test_update_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5795,18 +5812,20 @@ def test_update_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_update_sample_query" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_update_sample_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_update_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_update_sample_query" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_update_sample_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_update_sample_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5863,8 +5882,9 @@ def test_delete_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5923,13 +5943,13 @@ def test_delete_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_delete_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_delete_sample_query" + ) as pre, + ): pre.assert_not_called() pb_message = sample_query_service.DeleteSampleQueryRequest.pb( sample_query_service.DeleteSampleQueryRequest() @@ -5976,8 +5996,9 @@ def test_import_sample_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6036,20 +6057,21 @@ def test_import_sample_queries_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_import_sample_queries" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_import_sample_queries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_import_sample_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_import_sample_queries" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_import_sample_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_import_sample_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6107,8 +6129,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6174,8 +6197,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6241,8 +6265,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6512,11 +6537,14 @@ def test_sample_query_service_base_transport(): def test_sample_query_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQueryServiceTransport( @@ -6533,9 +6561,12 @@ def test_sample_query_service_base_transport_with_credentials_file(): def test_sample_query_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQueryServiceTransport() @@ -6607,11 +6638,12 @@ def test_sample_query_service_transport_auth_gdch_credentials(transport_class): def test_sample_query_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7258,6 +7290,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SampleQueryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SampleQueryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SampleQueryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7403,6 +7467,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SampleQueryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SampleQueryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SampleQueryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7548,6 +7646,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SampleQueryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SampleQueryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SampleQueryServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_set_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_set_service.py index 2351a9a83b5d..98999b816bf7 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_set_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_sample_query_set_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SampleQuerySetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): SampleQuerySetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SampleQuerySetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1354,11 +1359,13 @@ def test_sample_query_set_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4769,8 +4776,9 @@ def test_get_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4839,18 +4847,20 @@ def test_get_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_get_sample_query_set" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_get_sample_query_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_get_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, "post_get_sample_query_set" + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_get_sample_query_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, "pre_get_sample_query_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4905,8 +4915,9 @@ def test_list_sample_query_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4971,18 +4982,22 @@ def test_list_sample_query_sets_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_list_sample_query_sets" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_list_sample_query_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_list_sample_query_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_list_sample_query_sets", + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_list_sample_query_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_list_sample_query_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5040,8 +5055,9 @@ def test_create_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5183,18 +5199,22 @@ def test_create_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_create_sample_query_set" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_create_sample_query_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_create_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_create_sample_query_set", + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_create_sample_query_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_create_sample_query_set", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5256,8 +5276,9 @@ def test_update_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5403,18 +5424,22 @@ def test_update_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_update_sample_query_set" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_update_sample_query_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_update_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_update_sample_query_set", + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_update_sample_query_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_update_sample_query_set", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5474,8 +5499,9 @@ def test_delete_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5534,13 +5560,14 @@ def test_delete_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_delete_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_delete_sample_query_set", + ) as pre, + ): pre.assert_not_called() pb_message = sample_query_set_service.DeleteSampleQuerySetRequest.pb( sample_query_set_service.DeleteSampleQuerySetRequest() @@ -5590,8 +5617,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5657,8 +5685,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5724,8 +5753,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5952,11 +5982,14 @@ def test_sample_query_set_service_base_transport(): def test_sample_query_set_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQuerySetServiceTransport( @@ -5973,9 +6006,12 @@ def test_sample_query_set_service_base_transport_with_credentials_file(): def test_sample_query_set_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQuerySetServiceTransport() @@ -6049,11 +6085,12 @@ def test_sample_query_set_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6655,6 +6692,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SampleQuerySetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SampleQuerySetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SampleQuerySetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6800,6 +6869,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SampleQuerySetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SampleQuerySetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SampleQuerySetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6945,6 +7048,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SampleQuerySetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SampleQuerySetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SampleQuerySetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py index 6798a86b9510..b5a5b084c3d6 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SchemaServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( SchemaServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SchemaServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_schema_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4445,8 +4452,9 @@ def test_get_schema_rest_bad_request(request_type=schema_service.GetSchemaReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4512,17 +4520,19 @@ def test_get_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_get_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_get_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_get_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_get_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_get_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_get_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4573,8 +4583,9 @@ def test_list_schemas_rest_bad_request(request_type=schema_service.ListSchemasRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4637,17 +4648,19 @@ def test_list_schemas_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_list_schemas" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_list_schemas_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_list_schemas" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_list_schemas" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_list_schemas_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_list_schemas" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4702,8 +4715,9 @@ def test_create_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4850,19 +4864,20 @@ def test_create_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_create_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_create_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_create_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_create_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_create_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_create_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4919,8 +4934,9 @@ def test_update_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5071,19 +5087,20 @@ def test_update_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_update_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_update_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_update_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_update_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_update_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_update_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5138,8 +5155,9 @@ def test_delete_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5198,19 +5216,20 @@ def test_delete_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_delete_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_delete_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_delete_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_delete_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_delete_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_delete_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5268,8 +5287,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5335,8 +5355,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5402,8 +5423,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5642,11 +5664,14 @@ def test_schema_service_base_transport(): def test_schema_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SchemaServiceTransport( @@ -5663,9 +5688,12 @@ def test_schema_service_base_transport_with_credentials_file(): def test_schema_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SchemaServiceTransport() @@ -5737,11 +5765,12 @@ def test_schema_service_transport_auth_gdch_credentials(transport_class): def test_schema_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6377,6 +6406,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6522,6 +6583,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6667,6 +6762,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py index 0655bfd466cb..6719cb18230c 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SearchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( SearchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SearchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1279,11 +1284,13 @@ def test_search_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2159,8 +2166,9 @@ def test_search_rest_bad_request(request_type=search_service.SearchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2235,17 +2243,17 @@ def test_search_rest_interceptors(null_interceptor): ) client = SearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search" - ) as post, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SearchServiceRestInterceptor, "pre_search" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search" + ) as post, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SearchServiceRestInterceptor, "pre_search") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2303,8 +2311,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2370,8 +2379,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2437,8 +2447,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2571,11 +2582,14 @@ def test_search_service_base_transport(): def test_search_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchServiceTransport( @@ -2592,9 +2606,12 @@ def test_search_service_base_transport_with_credentials_file(): def test_search_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchServiceTransport() @@ -2666,11 +2683,12 @@ def test_search_service_transport_auth_gdch_credentials(transport_class): def test_search_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3391,6 +3409,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3536,6 +3586,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3681,6 +3765,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py index 3f3d42e22bc5..3b98a0ff8e32 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SearchTuningServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): SearchTuningServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SearchTuningServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1349,11 +1354,13 @@ def test_search_tuning_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2381,8 +2388,9 @@ def test_train_custom_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2441,20 +2449,21 @@ def test_train_custom_model_rest_interceptors(null_interceptor): ) client = SearchTuningServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "post_train_custom_model" - ) as post, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, - "post_train_custom_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "pre_train_custom_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "post_train_custom_model" + ) as post, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, + "post_train_custom_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "pre_train_custom_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2509,8 +2518,9 @@ def test_list_custom_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2572,18 +2582,20 @@ def test_list_custom_models_rest_interceptors(null_interceptor): ) client = SearchTuningServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "post_list_custom_models" - ) as post, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, - "post_list_custom_models_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "pre_list_custom_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "post_list_custom_models" + ) as post, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, + "post_list_custom_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "pre_list_custom_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2646,8 +2658,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2713,8 +2726,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2780,8 +2794,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2961,11 +2976,14 @@ def test_search_tuning_service_base_transport(): def test_search_tuning_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchTuningServiceTransport( @@ -2982,9 +3000,12 @@ def test_search_tuning_service_base_transport_with_credentials_file(): def test_search_tuning_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchTuningServiceTransport() @@ -3056,11 +3077,12 @@ def test_search_tuning_service_transport_auth_gdch_credentials(transport_class): def test_search_tuning_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3693,6 +3715,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3838,6 +3892,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3983,6 +4071,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_serving_config_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_serving_config_service.py index c6422d69bc87..683ce8009c71 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_serving_config_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_serving_config_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServingConfigServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): ServingConfigServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ServingConfigServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_serving_config_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3715,8 +3722,9 @@ def test_update_serving_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3959,18 +3967,20 @@ def test_update_serving_config_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_update_serving_config" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_update_serving_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_update_serving_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_update_serving_config" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_update_serving_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_update_serving_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4027,8 +4037,9 @@ def test_get_serving_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4119,18 +4130,20 @@ def test_get_serving_config_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_get_serving_config" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_get_serving_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_get_serving_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_get_serving_config" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_get_serving_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_get_serving_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4185,8 +4198,9 @@ def test_list_serving_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4251,18 +4265,20 @@ def test_list_serving_configs_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_list_serving_configs" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_list_serving_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_list_serving_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_list_serving_configs" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_list_serving_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_list_serving_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4325,8 +4341,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4392,8 +4409,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4459,8 +4477,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4641,11 +4660,14 @@ def test_serving_config_service_base_transport(): def test_serving_config_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServingConfigServiceTransport( @@ -4662,9 +4684,12 @@ def test_serving_config_service_base_transport_with_credentials_file(): def test_serving_config_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServingConfigServiceTransport() @@ -4736,11 +4761,12 @@ def test_serving_config_service_transport_auth_gdch_credentials(transport_class) def test_serving_config_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5316,6 +5342,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5461,6 +5519,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5606,6 +5698,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_session_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_session_service.py index 43d323aa135d..dd803b646bc1 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_session_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_session_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): assert ( SessionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1291,11 +1296,13 @@ def test_session_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5387,8 +5394,9 @@ def test_create_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5634,17 +5642,20 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_create_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5699,8 +5710,9 @@ def test_delete_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5759,13 +5771,13 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteSessionRequest.pb( conversational_search_service.DeleteSessionRequest() @@ -5814,8 +5826,9 @@ def test_update_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6065,17 +6078,20 @@ def test_update_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_update_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_update_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_update_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_update_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, + "post_update_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_update_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6130,8 +6146,9 @@ def test_get_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6204,17 +6221,19 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_get_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_get_session_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6267,8 +6286,9 @@ def test_list_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6333,17 +6353,19 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_sessions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_sessions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6401,8 +6423,9 @@ def test_list_files_rest_bad_request(request_type=session_service.ListFilesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6467,17 +6490,19 @@ def test_list_files_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_files" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_list_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_files" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_list_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6537,8 +6562,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6604,8 +6630,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6671,8 +6698,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6910,11 +6938,14 @@ def test_session_service_base_transport(): def test_session_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport( @@ -6931,9 +6962,12 @@ def test_session_service_base_transport_with_credentials_file(): def test_session_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport() @@ -7005,11 +7039,12 @@ def test_session_service_transport_auth_gdch_credentials(transport_class): def test_session_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7721,6 +7756,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7866,6 +7933,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8011,6 +8112,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py index a7a7fda0787d..ee1c38819372 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SiteSearchEngineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): SiteSearchEngineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SiteSearchEngineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1358,11 +1363,13 @@ def test_site_search_engine_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9120,8 +9127,9 @@ def test_get_site_search_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9186,18 +9194,22 @@ def test_get_site_search_engine_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_get_site_search_engine" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_site_search_engine_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_get_site_search_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_site_search_engine", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_site_search_engine_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_get_site_search_engine", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9257,8 +9269,9 @@ def test_create_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9401,20 +9414,21 @@ def test_create_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_create_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_create_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_create_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_create_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_create_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_create_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9469,8 +9483,9 @@ def test_batch_create_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9529,22 +9544,23 @@ def test_batch_create_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_create_target_sites", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_create_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_batch_create_target_sites", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_create_target_sites", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_create_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_batch_create_target_sites", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9599,8 +9615,9 @@ def test_get_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9679,18 +9696,20 @@ def test_get_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_get_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_get_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_get_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_get_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9749,8 +9768,9 @@ def test_update_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9895,20 +9915,21 @@ def test_update_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_update_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_update_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_update_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_update_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_update_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_update_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9963,8 +9984,9 @@ def test_delete_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10023,20 +10045,21 @@ def test_delete_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_delete_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_delete_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_delete_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_delete_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10091,8 +10114,9 @@ def test_list_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10161,18 +10185,20 @@ def test_list_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_list_target_sites" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_list_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_list_target_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_list_target_sites" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_list_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_list_target_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10232,8 +10258,9 @@ def test_enable_advanced_site_search_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10292,22 +10319,23 @@ def test_enable_advanced_site_search_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_enable_advanced_site_search", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_enable_advanced_site_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_enable_advanced_site_search", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_enable_advanced_site_search", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_enable_advanced_site_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_enable_advanced_site_search", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10362,8 +10390,9 @@ def test_disable_advanced_site_search_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10422,22 +10451,23 @@ def test_disable_advanced_site_search_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_disable_advanced_site_search", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_disable_advanced_site_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_disable_advanced_site_search", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_disable_advanced_site_search", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_disable_advanced_site_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_disable_advanced_site_search", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10492,8 +10522,9 @@ def test_recrawl_uris_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10552,20 +10583,21 @@ def test_recrawl_uris_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_recrawl_uris" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_recrawl_uris_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_recrawl_uris" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_recrawl_uris" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_recrawl_uris_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_recrawl_uris" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10620,8 +10652,9 @@ def test_batch_verify_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10680,22 +10713,23 @@ def test_batch_verify_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_verify_target_sites", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_verify_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_batch_verify_target_sites", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_verify_target_sites", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_verify_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_batch_verify_target_sites", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10750,8 +10784,9 @@ def test_fetch_domain_verification_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10822,20 +10857,22 @@ def test_fetch_domain_verification_status_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_domain_verification_status", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_domain_verification_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_fetch_domain_verification_status", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_domain_verification_status", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_domain_verification_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_fetch_domain_verification_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10899,8 +10936,9 @@ def test_set_uri_pattern_document_data_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10959,22 +10997,23 @@ def test_set_uri_pattern_document_data_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_set_uri_pattern_document_data", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_set_uri_pattern_document_data_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_set_uri_pattern_document_data", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_set_uri_pattern_document_data", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_set_uri_pattern_document_data_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_set_uri_pattern_document_data", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11029,8 +11068,9 @@ def test_get_uri_pattern_document_data_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11096,20 +11136,22 @@ def test_get_uri_pattern_document_data_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_uri_pattern_document_data", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_uri_pattern_document_data_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_get_uri_pattern_document_data", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_uri_pattern_document_data", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_uri_pattern_document_data_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_get_uri_pattern_document_data", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11176,8 +11218,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11243,8 +11286,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11310,8 +11354,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11763,11 +11808,14 @@ def test_site_search_engine_service_base_transport(): def test_site_search_engine_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteSearchEngineServiceTransport( @@ -11784,9 +11832,12 @@ def test_site_search_engine_service_base_transport_with_credentials_file(): def test_site_search_engine_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteSearchEngineServiceTransport() @@ -11860,11 +11911,12 @@ def test_site_search_engine_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12535,6 +12587,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12680,6 +12764,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12825,6 +12943,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py index c27f5c285c92..0a1a2b7c9a16 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserEventServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): UserEventServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserEventServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1326,11 +1331,13 @@ def test_user_event_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3314,8 +3321,9 @@ def test_write_user_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3521,18 +3529,20 @@ def test_write_user_event_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_write_user_event" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_write_user_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_write_user_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_write_user_event" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_write_user_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_write_user_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3585,8 +3595,9 @@ def test_collect_user_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3648,18 +3659,20 @@ def test_collect_user_event_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_collect_user_event" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_collect_user_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_collect_user_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_collect_user_event" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_collect_user_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_collect_user_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3712,8 +3725,9 @@ def test_purge_user_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3770,20 +3784,21 @@ def test_purge_user_events_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_purge_user_events" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_purge_user_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_purge_user_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_purge_user_events" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_purge_user_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_purge_user_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3836,8 +3851,9 @@ def test_import_user_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3894,20 +3910,21 @@ def test_import_user_events_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_import_user_events" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_import_user_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_import_user_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_import_user_events" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_import_user_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_import_user_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3965,8 +3982,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4032,8 +4050,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4099,8 +4118,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4324,11 +4344,14 @@ def test_user_event_service_base_transport(): def test_user_event_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserEventServiceTransport( @@ -4345,9 +4368,12 @@ def test_user_event_service_base_transport_with_credentials_file(): def test_user_event_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1alpha.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1alpha.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserEventServiceTransport() @@ -4419,11 +4445,12 @@ def test_user_event_service_transport_auth_gdch_credentials(transport_class): def test_user_event_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5092,6 +5119,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5237,6 +5296,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5382,6 +5475,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py index d96881e370eb..1c2a71c11755 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CompletionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): CompletionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CompletionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1330,11 +1335,13 @@ def test_completion_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4162,8 +4169,9 @@ def test_complete_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4228,17 +4236,20 @@ def test_complete_query_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_complete_query" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_complete_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_complete_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "post_complete_query" + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_complete_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "pre_complete_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4298,8 +4309,9 @@ def test_advanced_complete_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4364,18 +4376,20 @@ def test_advanced_complete_query_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_advanced_complete_query" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_advanced_complete_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_advanced_complete_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "post_advanced_complete_query" + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_advanced_complete_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, "pre_advanced_complete_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4435,8 +4449,9 @@ def test_import_suggestion_deny_list_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4495,22 +4510,23 @@ def test_import_suggestion_deny_list_entries_rest_interceptors(null_interceptor) ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_suggestion_deny_list_entries", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_suggestion_deny_list_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "pre_import_suggestion_deny_list_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_suggestion_deny_list_entries", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_suggestion_deny_list_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_import_suggestion_deny_list_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4565,8 +4581,9 @@ def test_purge_suggestion_deny_list_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4625,22 +4642,23 @@ def test_purge_suggestion_deny_list_entries_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_suggestion_deny_list_entries", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_suggestion_deny_list_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "pre_purge_suggestion_deny_list_entries", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_suggestion_deny_list_entries", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_suggestion_deny_list_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_purge_suggestion_deny_list_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4695,8 +4713,9 @@ def test_import_completion_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4755,21 +4774,23 @@ def test_import_completion_suggestions_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_completion_suggestions", - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_import_completion_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_import_completion_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_completion_suggestions", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_import_completion_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_import_completion_suggestions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4824,8 +4845,9 @@ def test_purge_completion_suggestions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4884,20 +4906,23 @@ def test_purge_completion_suggestions_rest_interceptors(null_interceptor): ) client = CompletionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CompletionServiceRestInterceptor, "post_purge_completion_suggestions" - ) as post, mock.patch.object( - transports.CompletionServiceRestInterceptor, - "post_purge_completion_suggestions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CompletionServiceRestInterceptor, "pre_purge_completion_suggestions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_completion_suggestions", + ) as post, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "post_purge_completion_suggestions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CompletionServiceRestInterceptor, + "pre_purge_completion_suggestions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4955,8 +4980,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5022,8 +5048,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5089,8 +5116,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5360,11 +5388,14 @@ def test_completion_service_base_transport(): def test_completion_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompletionServiceTransport( @@ -5381,9 +5412,12 @@ def test_completion_service_base_transport_with_credentials_file(): def test_completion_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CompletionServiceTransport() @@ -5455,11 +5489,12 @@ def test_completion_service_transport_auth_gdch_credentials(transport_class): def test_completion_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6133,6 +6168,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6278,6 +6345,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6423,6 +6524,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CompletionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CompletionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = CompletionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_control_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_control_service.py index 3389fd535774..747589b04898 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_control_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_control_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ControlServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ControlServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ControlServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_control_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4614,8 +4621,9 @@ def test_create_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4782,17 +4790,20 @@ def test_create_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_create_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_create_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_create_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_create_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, + "post_create_control_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_create_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4847,8 +4858,9 @@ def test_delete_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4907,13 +4919,13 @@ def test_delete_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_delete_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_delete_control" + ) as pre, + ): pre.assert_not_called() pb_message = control_service.DeleteControlRequest.pb( control_service.DeleteControlRequest() @@ -4962,8 +4974,9 @@ def test_update_control_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5134,17 +5147,20 @@ def test_update_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_update_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_update_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_update_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_update_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, + "post_update_control_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_update_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5197,8 +5213,9 @@ def test_get_control_rest_bad_request(request_type=control_service.GetControlReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5273,17 +5290,19 @@ def test_get_control_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_get_control" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_get_control_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_get_control" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_get_control" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_get_control_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_get_control" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5336,8 +5355,9 @@ def test_list_controls_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5400,17 +5420,19 @@ def test_list_controls_rest_interceptors(null_interceptor): ) client = ControlServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_list_controls" - ) as post, mock.patch.object( - transports.ControlServiceRestInterceptor, "post_list_controls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ControlServiceRestInterceptor, "pre_list_controls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_list_controls" + ) as post, + mock.patch.object( + transports.ControlServiceRestInterceptor, "post_list_controls_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ControlServiceRestInterceptor, "pre_list_controls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5473,8 +5495,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5540,8 +5563,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5607,8 +5631,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5825,11 +5850,14 @@ def test_control_service_base_transport(): def test_control_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ControlServiceTransport( @@ -5846,9 +5874,12 @@ def test_control_service_base_transport_with_credentials_file(): def test_control_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.control_service.transports.ControlServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ControlServiceTransport() @@ -5920,11 +5951,12 @@ def test_control_service_transport_auth_gdch_credentials(transport_class): def test_control_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6528,6 +6560,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6673,6 +6737,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6818,6 +6916,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ControlServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ControlServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ControlServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py index ff36f77226e2..4319cd822f1c 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConversationalSearchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -156,6 +157,10 @@ def test__get_default_mtls_endpoint(): ConversationalSearchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConversationalSearchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1396,11 +1401,13 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9488,8 +9495,9 @@ def test_converse_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9558,20 +9566,22 @@ def test_converse_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_converse_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_converse_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "pre_converse_conversation", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_converse_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_converse_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_converse_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9631,8 +9641,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9834,19 +9845,22 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_create_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9903,8 +9917,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9963,13 +9978,14 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_delete_conversation", + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteConversationRequest.pb( conversational_search_service.DeleteConversationRequest() @@ -10018,8 +10034,9 @@ def test_update_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10225,19 +10242,22 @@ def test_update_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_conversation", - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_update_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_update_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10294,8 +10314,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10364,18 +10385,22 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_conversation", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_get_conversation", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10428,8 +10453,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10494,18 +10520,22 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_conversations", + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "pre_list_conversations", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10565,8 +10595,9 @@ def test_answer_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10633,18 +10664,20 @@ def test_answer_query_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_answer_query" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_answer_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_answer_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_answer_query" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_answer_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_answer_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10704,8 +10737,9 @@ def test_get_answer_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10782,18 +10816,20 @@ def test_get_answer_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_answer" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_answer_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_answer" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_get_answer" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_answer_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_get_answer" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10846,8 +10882,9 @@ def test_create_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11093,18 +11130,20 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_create_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11159,8 +11198,9 @@ def test_delete_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11219,13 +11259,13 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteSessionRequest.pb( conversational_search_service.DeleteSessionRequest() @@ -11274,8 +11314,9 @@ def test_update_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11525,18 +11566,20 @@ def test_update_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_update_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_update_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_update_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_update_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_update_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_update_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11591,8 +11634,9 @@ def test_get_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11665,18 +11709,20 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_get_session_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_get_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11729,8 +11775,9 @@ def test_list_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11795,18 +11842,20 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = ConversationalSearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, - "post_list_sessions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ConversationalSearchServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, + "post_list_sessions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ConversationalSearchServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11869,8 +11918,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11936,8 +11986,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12003,8 +12054,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12399,11 +12451,14 @@ def test_conversational_search_service_base_transport(): def test_conversational_search_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationalSearchServiceTransport( @@ -12420,9 +12475,12 @@ def test_conversational_search_service_base_transport_with_credentials_file(): def test_conversational_search_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConversationalSearchServiceTransport() @@ -12499,11 +12557,12 @@ def test_conversational_search_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13308,6 +13367,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13453,6 +13544,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13598,6 +13723,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConversationalSearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConversationalSearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ConversationalSearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_data_store_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_data_store_service.py index fe9408613714..79266bc98123 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_data_store_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_data_store_service.py @@ -136,6 +136,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataStoreServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): DataStoreServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataStoreServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1327,11 +1332,13 @@ def test_data_store_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4717,8 +4724,9 @@ def test_create_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4899,20 +4907,21 @@ def test_create_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_create_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_create_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_create_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_create_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_create_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_create_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4965,8 +4974,9 @@ def test_get_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5039,17 +5049,20 @@ def test_get_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_get_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_get_data_store_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_get_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_get_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_get_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_get_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5102,8 +5115,9 @@ def test_list_data_stores_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5166,18 +5180,20 @@ def test_list_data_stores_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_list_data_stores" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_list_data_stores_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_list_data_stores" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_list_data_stores" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_list_data_stores_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_list_data_stores" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5235,8 +5251,9 @@ def test_delete_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5293,20 +5310,21 @@ def test_delete_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_delete_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_delete_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_delete_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_delete_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_delete_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_delete_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5361,8 +5379,9 @@ def test_update_data_store_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5561,18 +5580,20 @@ def test_update_data_store_rest_interceptors(null_interceptor): ) client = DataStoreServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "post_update_data_store" - ) as post, mock.patch.object( - transports.DataStoreServiceRestInterceptor, - "post_update_data_store_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataStoreServiceRestInterceptor, "pre_update_data_store" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "post_update_data_store" + ) as post, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, + "post_update_data_store_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataStoreServiceRestInterceptor, "pre_update_data_store" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5630,8 +5651,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5697,8 +5719,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5764,8 +5787,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6010,11 +6034,14 @@ def test_data_store_service_base_transport(): def test_data_store_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataStoreServiceTransport( @@ -6031,9 +6058,12 @@ def test_data_store_service_base_transport_with_credentials_file(): def test_data_store_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataStoreServiceTransport() @@ -6105,11 +6135,12 @@ def test_data_store_service_transport_auth_gdch_credentials(transport_class): def test_data_store_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6803,6 +6834,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6948,6 +7011,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7093,6 +7190,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataStoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataStoreServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DataStoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py index e2cc571138a2..0b608df64719 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py @@ -137,6 +137,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -158,6 +159,10 @@ def test__get_default_mtls_endpoint(): assert ( DocumentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1322,11 +1327,13 @@ def test_document_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6174,8 +6181,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6247,17 +6255,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6312,8 +6322,9 @@ def test_list_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6378,17 +6389,20 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_list_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6448,8 +6462,9 @@ def test_create_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6618,17 +6633,20 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_create_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6685,8 +6703,9 @@ def test_update_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6857,17 +6876,20 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_update_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6922,8 +6944,9 @@ def test_delete_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6982,13 +7005,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = document_service.DeleteDocumentRequest.pb( document_service.DeleteDocumentRequest() @@ -7035,8 +7058,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7095,19 +7119,21 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_import_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7162,8 +7188,9 @@ def test_purge_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7222,19 +7249,21 @@ def test_purge_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_purge_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_purge_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_purge_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_purge_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_purge_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_purge_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7289,8 +7318,9 @@ def test_batch_get_documents_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7354,18 +7384,22 @@ def test_batch_get_documents_metadata_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_batch_get_documents_metadata" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_batch_get_documents_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_batch_get_documents_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_get_documents_metadata", + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_get_documents_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "pre_batch_get_documents_metadata", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7428,8 +7462,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7495,8 +7530,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7562,8 +7598,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7867,11 +7904,14 @@ def test_document_service_base_transport(): def test_document_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport( @@ -7888,9 +7928,12 @@ def test_document_service_base_transport_with_credentials_file(): def test_document_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport() @@ -7962,11 +8005,12 @@ def test_document_service_transport_auth_gdch_credentials(transport_class): def test_document_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8689,6 +8733,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8834,6 +8910,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8979,6 +9089,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_engine_service.py index 87cfa0c63b32..389173e88d65 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_engine_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EngineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): assert ( EngineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EngineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1286,11 +1291,13 @@ def test_engine_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6379,8 +6386,9 @@ def test_create_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6526,19 +6534,20 @@ def test_create_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_create_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_create_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_create_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_create_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_create_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_create_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6593,8 +6602,9 @@ def test_delete_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6653,19 +6663,20 @@ def test_delete_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_delete_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_delete_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_delete_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_delete_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_delete_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_delete_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6722,8 +6733,9 @@ def test_update_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6889,17 +6901,19 @@ def test_update_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_update_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_update_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_update_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_update_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_update_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_update_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6952,8 +6966,9 @@ def test_get_engine_rest_bad_request(request_type=engine_service.GetEngineReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7028,17 +7043,19 @@ def test_get_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_get_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_get_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_get_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_get_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_get_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_get_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7089,8 +7106,9 @@ def test_list_engines_rest_bad_request(request_type=engine_service.ListEnginesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7153,17 +7171,19 @@ def test_list_engines_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_list_engines" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_list_engines_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_list_engines" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_list_engines" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_list_engines_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_list_engines" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7218,8 +7238,9 @@ def test_pause_engine_rest_bad_request(request_type=engine_service.PauseEngineRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7294,17 +7315,19 @@ def test_pause_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_pause_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_pause_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_pause_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_pause_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_pause_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_pause_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7359,8 +7382,9 @@ def test_resume_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7435,17 +7459,19 @@ def test_resume_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_resume_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_resume_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_resume_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_resume_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_resume_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_resume_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7498,8 +7524,9 @@ def test_tune_engine_rest_bad_request(request_type=engine_service.TuneEngineRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7558,19 +7585,20 @@ def test_tune_engine_rest_interceptors(null_interceptor): ) client = EngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EngineServiceRestInterceptor, "post_tune_engine" - ) as post, mock.patch.object( - transports.EngineServiceRestInterceptor, "post_tune_engine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EngineServiceRestInterceptor, "pre_tune_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_tune_engine" + ) as post, + mock.patch.object( + transports.EngineServiceRestInterceptor, "post_tune_engine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EngineServiceRestInterceptor, "pre_tune_engine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7628,8 +7656,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7695,8 +7724,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7762,8 +7792,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8065,11 +8096,14 @@ def test_engine_service_base_transport(): def test_engine_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EngineServiceTransport( @@ -8086,9 +8120,12 @@ def test_engine_service_base_transport_with_credentials_file(): def test_engine_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EngineServiceTransport() @@ -8160,11 +8197,12 @@ def test_engine_service_transport_auth_gdch_credentials(transport_class): def test_engine_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8811,6 +8849,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8956,6 +9026,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9101,6 +9205,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_evaluation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_evaluation_service.py index b0bcc6ac6ec5..86de81be565a 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_evaluation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_evaluation_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EvaluationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): EvaluationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EvaluationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1334,11 +1339,13 @@ def test_evaluation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4359,8 +4366,9 @@ def test_get_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4425,17 +4433,20 @@ def test_get_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_get_evaluation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_get_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_get_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_get_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_get_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4488,8 +4499,9 @@ def test_list_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4552,18 +4564,20 @@ def test_list_evaluations_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluations" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluations" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4621,8 +4635,9 @@ def test_create_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4910,20 +4925,21 @@ def test_create_evaluation_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_create_evaluation" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_create_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_create_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_create_evaluation" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_create_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_create_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4978,8 +4994,9 @@ def test_list_evaluation_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5044,18 +5061,20 @@ def test_list_evaluation_results_rest_interceptors(null_interceptor): ) client = EvaluationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "post_list_evaluation_results" - ) as post, mock.patch.object( - transports.EvaluationServiceRestInterceptor, - "post_list_evaluation_results_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "post_list_evaluation_results" + ) as post, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, + "post_list_evaluation_results_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EvaluationServiceRestInterceptor, "pre_list_evaluation_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5118,8 +5137,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5185,8 +5205,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5252,8 +5273,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5475,11 +5497,14 @@ def test_evaluation_service_base_transport(): def test_evaluation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EvaluationServiceTransport( @@ -5496,9 +5521,12 @@ def test_evaluation_service_base_transport_with_credentials_file(): def test_evaluation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.evaluation_service.transports.EvaluationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EvaluationServiceTransport() @@ -5570,11 +5598,12 @@ def test_evaluation_service_transport_auth_gdch_credentials(transport_class): def test_evaluation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6381,6 +6410,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6526,6 +6587,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6671,6 +6766,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EvaluationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EvaluationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = EvaluationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_grounded_generation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_grounded_generation_service.py index 55c937e813e9..765b81b420f9 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_grounded_generation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_grounded_generation_service.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GroundedGenerationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): GroundedGenerationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GroundedGenerationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1363,11 +1368,13 @@ def test_grounded_generation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2572,8 +2579,9 @@ def test_generate_grounded_content_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2637,20 +2645,22 @@ def test_generate_grounded_content_rest_interceptors(null_interceptor): ) client = GroundedGenerationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_generate_grounded_content", - ) as post, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_generate_grounded_content_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "pre_generate_grounded_content", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_generate_grounded_content", + ) as post, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_generate_grounded_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "pre_generate_grounded_content", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2714,8 +2724,9 @@ def test_check_grounding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2782,18 +2793,20 @@ def test_check_grounding_rest_interceptors(null_interceptor): ) client = GroundedGenerationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, "post_check_grounding" - ) as post, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, - "post_check_grounding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GroundedGenerationServiceRestInterceptor, "pre_check_grounding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, "post_check_grounding" + ) as post, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, + "post_check_grounding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GroundedGenerationServiceRestInterceptor, "pre_check_grounding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2856,8 +2869,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2923,8 +2937,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2990,8 +3005,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3148,11 +3164,14 @@ def test_grounded_generation_service_base_transport(): def test_grounded_generation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroundedGenerationServiceTransport( @@ -3169,9 +3188,12 @@ def test_grounded_generation_service_base_transport_with_credentials_file(): def test_grounded_generation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.grounded_generation_service.transports.GroundedGenerationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroundedGenerationServiceTransport() @@ -3245,11 +3267,12 @@ def test_grounded_generation_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3878,6 +3901,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4023,6 +4078,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4168,6 +4257,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GroundedGenerationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GroundedGenerationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = GroundedGenerationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_project_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_project_service.py index a7a3b33f16c7..153e5c5168b5 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_project_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_project_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ProjectServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,10 @@ def test__get_default_mtls_endpoint(): assert ( ProjectServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ProjectServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_project_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2040,8 +2047,9 @@ def test_provision_project_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2098,19 +2106,21 @@ def test_provision_project_rest_interceptors(null_interceptor): ) client = ProjectServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_provision_project" - ) as post, mock.patch.object( - transports.ProjectServiceRestInterceptor, "post_provision_project_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ProjectServiceRestInterceptor, "pre_provision_project" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ProjectServiceRestInterceptor, "post_provision_project" + ) as post, + mock.patch.object( + transports.ProjectServiceRestInterceptor, + "post_provision_project_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ProjectServiceRestInterceptor, "pre_provision_project" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2168,8 +2178,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2235,8 +2246,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2302,8 +2314,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2460,11 +2473,14 @@ def test_project_service_base_transport(): def test_project_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectServiceTransport( @@ -2481,9 +2497,12 @@ def test_project_service_base_transport_with_credentials_file(): def test_project_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.project_service.transports.ProjectServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProjectServiceTransport() @@ -2555,11 +2574,12 @@ def test_project_service_transport_auth_gdch_credentials(transport_class): def test_project_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3150,6 +3170,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3295,6 +3347,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3440,6 +3526,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ProjectServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ProjectServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ProjectServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_rank_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_rank_service.py index 8cd24fe30c4e..6163a491cab8 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_rank_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_rank_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RankServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert RankServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + RankServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1244,11 +1248,13 @@ def test_rank_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1817,8 +1823,9 @@ def test_rank_rest_bad_request(request_type=rank_service.RankRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1880,17 +1887,15 @@ def test_rank_rest_interceptors(null_interceptor): ) client = RankServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RankServiceRestInterceptor, "post_rank" - ) as post, mock.patch.object( - transports.RankServiceRestInterceptor, "post_rank_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RankServiceRestInterceptor, "pre_rank" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.RankServiceRestInterceptor, "post_rank") as post, + mock.patch.object( + transports.RankServiceRestInterceptor, "post_rank_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.RankServiceRestInterceptor, "pre_rank") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1946,8 +1951,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2013,8 +2019,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2080,8 +2087,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2214,11 +2222,14 @@ def test_rank_service_base_transport(): def test_rank_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RankServiceTransport( @@ -2235,9 +2246,12 @@ def test_rank_service_base_transport_with_credentials_file(): def test_rank_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.rank_service.transports.RankServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RankServiceTransport() @@ -2309,11 +2323,12 @@ def test_rank_service_transport_auth_gdch_credentials(transport_class): def test_rank_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2865,6 +2880,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3010,6 +3057,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3155,6 +3236,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RankServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py index e807ff227f64..fff4f356c598 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert RecommendationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): RecommendationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + RecommendationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_recommendation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1945,8 +1952,9 @@ def test_recommend_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2015,17 +2023,20 @@ def test_recommend_rest_interceptors(null_interceptor): ) client = RecommendationServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "post_recommend" - ) as post, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "post_recommend_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.RecommendationServiceRestInterceptor, "pre_recommend" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, "post_recommend" + ) as post, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, + "post_recommend_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.RecommendationServiceRestInterceptor, "pre_recommend" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2088,8 +2099,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2155,8 +2167,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2222,8 +2235,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2356,11 +2370,14 @@ def test_recommendation_service_base_transport(): def test_recommendation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RecommendationServiceTransport( @@ -2377,9 +2394,12 @@ def test_recommendation_service_base_transport_with_credentials_file(): def test_recommendation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.RecommendationServiceTransport() @@ -2451,11 +2471,12 @@ def test_recommendation_service_transport_auth_gdch_credentials(transport_class) def test_recommendation_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3116,6 +3137,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3261,6 +3314,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3406,6 +3493,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = RecommendationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = RecommendationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = RecommendationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_service.py index 5e282abb65b7..4254b4c2a585 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SampleQueryServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): SampleQueryServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SampleQueryServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1336,11 +1341,13 @@ def test_sample_query_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5164,8 +5171,9 @@ def test_get_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5230,18 +5238,20 @@ def test_get_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_get_sample_query" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_get_sample_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_get_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_get_sample_query" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_get_sample_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_get_sample_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5296,8 +5306,9 @@ def test_list_sample_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5362,18 +5373,20 @@ def test_list_sample_queries_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_list_sample_queries" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_list_sample_queries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_list_sample_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_list_sample_queries" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_list_sample_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_list_sample_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5433,8 +5446,9 @@ def test_create_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5578,18 +5592,20 @@ def test_create_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_create_sample_query" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_create_sample_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_create_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_create_sample_query" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_create_sample_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_create_sample_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5648,8 +5664,9 @@ def test_update_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5795,18 +5812,20 @@ def test_update_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_update_sample_query" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_update_sample_query_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_update_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_update_sample_query" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_update_sample_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_update_sample_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5863,8 +5882,9 @@ def test_delete_sample_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5923,13 +5943,13 @@ def test_delete_sample_query_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_delete_sample_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_delete_sample_query" + ) as pre, + ): pre.assert_not_called() pb_message = sample_query_service.DeleteSampleQueryRequest.pb( sample_query_service.DeleteSampleQueryRequest() @@ -5976,8 +5996,9 @@ def test_import_sample_queries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6036,20 +6057,21 @@ def test_import_sample_queries_rest_interceptors(null_interceptor): ) client = SampleQueryServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "post_import_sample_queries" - ) as post, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, - "post_import_sample_queries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQueryServiceRestInterceptor, "pre_import_sample_queries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "post_import_sample_queries" + ) as post, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, + "post_import_sample_queries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQueryServiceRestInterceptor, "pre_import_sample_queries" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6107,8 +6129,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6174,8 +6197,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6241,8 +6265,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6512,11 +6537,14 @@ def test_sample_query_service_base_transport(): def test_sample_query_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQueryServiceTransport( @@ -6533,9 +6561,12 @@ def test_sample_query_service_base_transport_with_credentials_file(): def test_sample_query_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.sample_query_service.transports.SampleQueryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQueryServiceTransport() @@ -6607,11 +6638,12 @@ def test_sample_query_service_transport_auth_gdch_credentials(transport_class): def test_sample_query_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7258,6 +7290,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SampleQueryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SampleQueryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SampleQueryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7403,6 +7467,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SampleQueryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SampleQueryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SampleQueryServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7548,6 +7646,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SampleQueryServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SampleQueryServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SampleQueryServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_set_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_set_service.py index fece9d0669a6..b12a6d63dc29 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_set_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_sample_query_set_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SampleQuerySetServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): SampleQuerySetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SampleQuerySetServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1354,11 +1359,13 @@ def test_sample_query_set_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4769,8 +4776,9 @@ def test_get_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4839,18 +4847,20 @@ def test_get_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_get_sample_query_set" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_get_sample_query_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_get_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, "post_get_sample_query_set" + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_get_sample_query_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, "pre_get_sample_query_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4905,8 +4915,9 @@ def test_list_sample_query_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4971,18 +4982,22 @@ def test_list_sample_query_sets_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_list_sample_query_sets" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_list_sample_query_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_list_sample_query_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_list_sample_query_sets", + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_list_sample_query_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_list_sample_query_sets", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5040,8 +5055,9 @@ def test_create_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5183,18 +5199,22 @@ def test_create_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_create_sample_query_set" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_create_sample_query_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_create_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_create_sample_query_set", + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_create_sample_query_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_create_sample_query_set", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5256,8 +5276,9 @@ def test_update_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5403,18 +5424,22 @@ def test_update_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "post_update_sample_query_set" - ) as post, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, - "post_update_sample_query_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_update_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_update_sample_query_set", + ) as post, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "post_update_sample_query_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_update_sample_query_set", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5474,8 +5499,9 @@ def test_delete_sample_query_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5534,13 +5560,14 @@ def test_delete_sample_query_set_rest_interceptors(null_interceptor): ) client = SampleQuerySetServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SampleQuerySetServiceRestInterceptor, "pre_delete_sample_query_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SampleQuerySetServiceRestInterceptor, + "pre_delete_sample_query_set", + ) as pre, + ): pre.assert_not_called() pb_message = sample_query_set_service.DeleteSampleQuerySetRequest.pb( sample_query_set_service.DeleteSampleQuerySetRequest() @@ -5590,8 +5617,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5657,8 +5685,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5724,8 +5753,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5952,11 +5982,14 @@ def test_sample_query_set_service_base_transport(): def test_sample_query_set_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQuerySetServiceTransport( @@ -5973,9 +6006,12 @@ def test_sample_query_set_service_base_transport_with_credentials_file(): def test_sample_query_set_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.sample_query_set_service.transports.SampleQuerySetServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SampleQuerySetServiceTransport() @@ -6049,11 +6085,12 @@ def test_sample_query_set_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6655,6 +6692,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SampleQuerySetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SampleQuerySetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SampleQuerySetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6800,6 +6869,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SampleQuerySetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SampleQuerySetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SampleQuerySetServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6945,6 +7048,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SampleQuerySetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SampleQuerySetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SampleQuerySetServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py index e50eaa6044ed..adfac4f4916d 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SchemaServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( SchemaServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SchemaServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1285,11 +1290,13 @@ def test_schema_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4445,8 +4452,9 @@ def test_get_schema_rest_bad_request(request_type=schema_service.GetSchemaReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4512,17 +4520,19 @@ def test_get_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_get_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_get_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_get_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_get_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_get_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_get_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4573,8 +4583,9 @@ def test_list_schemas_rest_bad_request(request_type=schema_service.ListSchemasRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4637,17 +4648,19 @@ def test_list_schemas_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_list_schemas" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_list_schemas_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_list_schemas" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_list_schemas" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_list_schemas_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_list_schemas" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4702,8 +4715,9 @@ def test_create_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4832,19 +4846,20 @@ def test_create_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_create_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_create_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_create_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_create_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_create_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_create_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4901,8 +4916,9 @@ def test_update_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5035,19 +5051,20 @@ def test_update_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_update_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_update_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_update_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_update_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_update_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_update_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5102,8 +5119,9 @@ def test_delete_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5162,19 +5180,20 @@ def test_delete_schema_rest_interceptors(null_interceptor): ) client = SchemaServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_delete_schema" - ) as post, mock.patch.object( - transports.SchemaServiceRestInterceptor, "post_delete_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SchemaServiceRestInterceptor, "pre_delete_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_delete_schema" + ) as post, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "post_delete_schema_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SchemaServiceRestInterceptor, "pre_delete_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5232,8 +5251,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5299,8 +5319,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5366,8 +5387,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5606,11 +5628,14 @@ def test_schema_service_base_transport(): def test_schema_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SchemaServiceTransport( @@ -5627,9 +5652,12 @@ def test_schema_service_base_transport_with_credentials_file(): def test_schema_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SchemaServiceTransport() @@ -5701,11 +5729,12 @@ def test_schema_service_transport_auth_gdch_credentials(transport_class): def test_schema_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6341,6 +6370,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6486,6 +6547,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6631,6 +6726,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SchemaServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SchemaServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SchemaServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py index 04387caef58e..dba1fc6eec72 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SearchServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): assert ( SearchServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SearchServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1279,11 +1284,13 @@ def test_search_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2877,8 +2884,9 @@ def test_search_rest_bad_request(request_type=search_service.SearchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2953,17 +2961,17 @@ def test_search_rest_interceptors(null_interceptor): ) client = SearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search" - ) as post, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SearchServiceRestInterceptor, "pre_search" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search" + ) as post, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.SearchServiceRestInterceptor, "pre_search") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3016,8 +3024,9 @@ def test_search_lite_rest_bad_request(request_type=search_service.SearchRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3092,17 +3101,19 @@ def test_search_lite_rest_interceptors(null_interceptor): ) client = SearchServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_lite" - ) as post, mock.patch.object( - transports.SearchServiceRestInterceptor, "post_search_lite_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SearchServiceRestInterceptor, "pre_search_lite" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_lite" + ) as post, + mock.patch.object( + transports.SearchServiceRestInterceptor, "post_search_lite_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SearchServiceRestInterceptor, "pre_search_lite" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3160,8 +3171,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3227,8 +3239,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3294,8 +3307,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3449,11 +3463,14 @@ def test_search_service_base_transport(): def test_search_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchServiceTransport( @@ -3470,9 +3487,12 @@ def test_search_service_base_transport_with_credentials_file(): def test_search_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchServiceTransport() @@ -3544,11 +3564,12 @@ def test_search_service_transport_auth_gdch_credentials(transport_class): def test_search_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4272,6 +4293,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4417,6 +4470,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -4562,6 +4649,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SearchServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SearchServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SearchServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_tuning_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_tuning_service.py index aca353d29bc5..2dd37c6becdf 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_tuning_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_tuning_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SearchTuningServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): SearchTuningServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SearchTuningServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1349,11 +1354,13 @@ def test_search_tuning_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2381,8 +2388,9 @@ def test_train_custom_model_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2441,20 +2449,21 @@ def test_train_custom_model_rest_interceptors(null_interceptor): ) client = SearchTuningServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "post_train_custom_model" - ) as post, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, - "post_train_custom_model_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "pre_train_custom_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "post_train_custom_model" + ) as post, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, + "post_train_custom_model_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "pre_train_custom_model" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2509,8 +2518,9 @@ def test_list_custom_models_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2572,18 +2582,20 @@ def test_list_custom_models_rest_interceptors(null_interceptor): ) client = SearchTuningServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "post_list_custom_models" - ) as post, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, - "post_list_custom_models_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SearchTuningServiceRestInterceptor, "pre_list_custom_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "post_list_custom_models" + ) as post, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, + "post_list_custom_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SearchTuningServiceRestInterceptor, "pre_list_custom_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2646,8 +2658,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2713,8 +2726,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2780,8 +2794,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2961,11 +2976,14 @@ def test_search_tuning_service_base_transport(): def test_search_tuning_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchTuningServiceTransport( @@ -2982,9 +3000,12 @@ def test_search_tuning_service_base_transport_with_credentials_file(): def test_search_tuning_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SearchTuningServiceTransport() @@ -3056,11 +3077,12 @@ def test_search_tuning_service_transport_auth_gdch_credentials(transport_class): def test_search_tuning_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3693,6 +3715,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3838,6 +3892,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3983,6 +4071,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SearchTuningServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SearchTuningServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SearchTuningServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_serving_config_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_serving_config_service.py index cfdc6a8b3cd9..c6aba70edec8 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_serving_config_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_serving_config_service.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServingConfigServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): ServingConfigServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ServingConfigServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_serving_config_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3715,8 +3722,9 @@ def test_update_serving_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3956,18 +3964,20 @@ def test_update_serving_config_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_update_serving_config" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_update_serving_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_update_serving_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_update_serving_config" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_update_serving_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_update_serving_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4024,8 +4034,9 @@ def test_get_serving_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4116,18 +4127,20 @@ def test_get_serving_config_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_get_serving_config" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_get_serving_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_get_serving_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_get_serving_config" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_get_serving_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_get_serving_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4182,8 +4195,9 @@ def test_list_serving_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4248,18 +4262,20 @@ def test_list_serving_configs_rest_interceptors(null_interceptor): ) client = ServingConfigServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "post_list_serving_configs" - ) as post, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, - "post_list_serving_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ServingConfigServiceRestInterceptor, "pre_list_serving_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "post_list_serving_configs" + ) as post, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, + "post_list_serving_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ServingConfigServiceRestInterceptor, "pre_list_serving_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4322,8 +4338,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4389,8 +4406,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4456,8 +4474,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4638,11 +4657,14 @@ def test_serving_config_service_base_transport(): def test_serving_config_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServingConfigServiceTransport( @@ -4659,9 +4681,12 @@ def test_serving_config_service_base_transport_with_credentials_file(): def test_serving_config_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.serving_config_service.transports.ServingConfigServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServingConfigServiceTransport() @@ -4733,11 +4758,12 @@ def test_serving_config_service_transport_auth_gdch_credentials(transport_class) def test_serving_config_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5313,6 +5339,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5458,6 +5516,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5603,6 +5695,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ServingConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ServingConfigServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ServingConfigServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_session_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_session_service.py index 8f154c3bd4df..4f9bd6d7bfaf 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_session_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_session_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SessionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): assert ( SessionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SessionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1290,11 +1295,13 @@ def test_session_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4561,8 +4568,9 @@ def test_create_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4808,17 +4816,20 @@ def test_create_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_create_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_create_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_create_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_create_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, + "post_create_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_create_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4873,8 +4884,9 @@ def test_delete_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4933,13 +4945,13 @@ def test_delete_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_delete_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_delete_session" + ) as pre, + ): pre.assert_not_called() pb_message = conversational_search_service.DeleteSessionRequest.pb( conversational_search_service.DeleteSessionRequest() @@ -4988,8 +5000,9 @@ def test_update_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5239,17 +5252,20 @@ def test_update_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_update_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_update_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_update_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_update_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, + "post_update_session_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_update_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5304,8 +5320,9 @@ def test_get_session_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5378,17 +5395,19 @@ def test_get_session_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_get_session" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_get_session_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_get_session" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_get_session" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_get_session_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_get_session" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5441,8 +5460,9 @@ def test_list_sessions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5507,17 +5527,19 @@ def test_list_sessions_rest_interceptors(null_interceptor): ) client = SessionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_sessions" - ) as post, mock.patch.object( - transports.SessionServiceRestInterceptor, "post_list_sessions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.SessionServiceRestInterceptor, "pre_list_sessions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_sessions" + ) as post, + mock.patch.object( + transports.SessionServiceRestInterceptor, "post_list_sessions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.SessionServiceRestInterceptor, "pre_list_sessions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5580,8 +5602,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5647,8 +5670,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5714,8 +5738,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5932,11 +5957,14 @@ def test_session_service_base_transport(): def test_session_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport( @@ -5953,9 +5981,12 @@ def test_session_service_base_transport_with_credentials_file(): def test_session_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.session_service.transports.SessionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SessionServiceTransport() @@ -6027,11 +6058,12 @@ def test_session_service_transport_auth_gdch_credentials(transport_class): def test_session_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6740,6 +6772,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -6885,6 +6949,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7030,6 +7128,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SessionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SessionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SessionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_site_search_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_site_search_engine_service.py index 424afebcb9f0..1114b4c91e0e 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_site_search_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_site_search_engine_service.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SiteSearchEngineServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): SiteSearchEngineServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SiteSearchEngineServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1357,11 +1362,13 @@ def test_site_search_engine_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9914,8 +9921,9 @@ def test_get_site_search_engine_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9980,18 +9988,22 @@ def test_get_site_search_engine_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_get_site_search_engine" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_site_search_engine_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_get_site_search_engine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_site_search_engine", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_site_search_engine_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_get_site_search_engine", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10051,8 +10063,9 @@ def test_create_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10195,20 +10208,21 @@ def test_create_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_create_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_create_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_create_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_create_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_create_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_create_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10263,8 +10277,9 @@ def test_batch_create_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10323,22 +10338,23 @@ def test_batch_create_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_create_target_sites", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_create_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_batch_create_target_sites", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_create_target_sites", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_create_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_batch_create_target_sites", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10393,8 +10409,9 @@ def test_get_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10473,18 +10490,20 @@ def test_get_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_get_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_get_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_get_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_get_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_get_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_get_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10543,8 +10562,9 @@ def test_update_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10689,20 +10709,21 @@ def test_update_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_update_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_update_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_update_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_update_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_update_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_update_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10757,8 +10778,9 @@ def test_delete_target_site_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10817,20 +10839,21 @@ def test_delete_target_site_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_delete_target_site" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_delete_target_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_target_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_delete_target_site" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_delete_target_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_target_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10885,8 +10908,9 @@ def test_list_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10955,18 +10979,20 @@ def test_list_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_list_target_sites" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_list_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_list_target_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_list_target_sites" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_list_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_list_target_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11026,8 +11052,9 @@ def test_create_sitemap_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11158,20 +11185,21 @@ def test_create_sitemap_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_create_sitemap" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_create_sitemap_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_create_sitemap" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_create_sitemap" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_create_sitemap_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_create_sitemap" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11226,8 +11254,9 @@ def test_delete_sitemap_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11286,20 +11315,21 @@ def test_delete_sitemap_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_delete_sitemap" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_delete_sitemap_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_sitemap" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_delete_sitemap" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_delete_sitemap_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_delete_sitemap" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11354,8 +11384,9 @@ def test_fetch_sitemaps_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11417,18 +11448,20 @@ def test_fetch_sitemaps_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_fetch_sitemaps" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_sitemaps_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_fetch_sitemaps" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_fetch_sitemaps" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_sitemaps_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_fetch_sitemaps" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11488,8 +11521,9 @@ def test_enable_advanced_site_search_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11548,22 +11582,23 @@ def test_enable_advanced_site_search_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_enable_advanced_site_search", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_enable_advanced_site_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_enable_advanced_site_search", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_enable_advanced_site_search", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_enable_advanced_site_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_enable_advanced_site_search", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11618,8 +11653,9 @@ def test_disable_advanced_site_search_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11678,22 +11714,23 @@ def test_disable_advanced_site_search_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_disable_advanced_site_search", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_disable_advanced_site_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_disable_advanced_site_search", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_disable_advanced_site_search", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_disable_advanced_site_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_disable_advanced_site_search", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11748,8 +11785,9 @@ def test_recrawl_uris_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11808,20 +11846,21 @@ def test_recrawl_uris_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "post_recrawl_uris" - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_recrawl_uris_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, "pre_recrawl_uris" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "post_recrawl_uris" + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_recrawl_uris_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, "pre_recrawl_uris" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11876,8 +11915,9 @@ def test_batch_verify_target_sites_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11936,22 +11976,23 @@ def test_batch_verify_target_sites_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_verify_target_sites", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_batch_verify_target_sites_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_batch_verify_target_sites", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_verify_target_sites", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_batch_verify_target_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_batch_verify_target_sites", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12006,8 +12047,9 @@ def test_fetch_domain_verification_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12078,20 +12120,22 @@ def test_fetch_domain_verification_status_rest_interceptors(null_interceptor): ) client = SiteSearchEngineServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_domain_verification_status", - ) as post, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "post_fetch_domain_verification_status_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.SiteSearchEngineServiceRestInterceptor, - "pre_fetch_domain_verification_status", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_domain_verification_status", + ) as post, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "post_fetch_domain_verification_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.SiteSearchEngineServiceRestInterceptor, + "pre_fetch_domain_verification_status", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12158,8 +12202,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12225,8 +12270,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12292,8 +12338,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12762,11 +12809,14 @@ def test_site_search_engine_service_base_transport(): def test_site_search_engine_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteSearchEngineServiceTransport( @@ -12783,9 +12833,12 @@ def test_site_search_engine_service_base_transport_with_credentials_file(): def test_site_search_engine_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SiteSearchEngineServiceTransport() @@ -12859,11 +12912,12 @@ def test_site_search_engine_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13568,6 +13622,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13713,6 +13799,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13858,6 +13978,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = SiteSearchEngineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = SiteSearchEngineServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = SiteSearchEngineServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py index b588165f2138..634dc9ad6bbe 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UserEventServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): UserEventServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UserEventServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1326,11 +1331,13 @@ def test_user_event_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3314,8 +3321,9 @@ def test_write_user_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3523,18 +3531,20 @@ def test_write_user_event_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_write_user_event" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_write_user_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_write_user_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_write_user_event" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_write_user_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_write_user_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3587,8 +3597,9 @@ def test_collect_user_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3650,18 +3661,20 @@ def test_collect_user_event_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_collect_user_event" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_collect_user_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_collect_user_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_collect_user_event" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_collect_user_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_collect_user_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3714,8 +3727,9 @@ def test_purge_user_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3772,20 +3786,21 @@ def test_purge_user_events_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_purge_user_events" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_purge_user_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_purge_user_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_purge_user_events" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_purge_user_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_purge_user_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3838,8 +3853,9 @@ def test_import_user_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3896,20 +3912,21 @@ def test_import_user_events_rest_interceptors(null_interceptor): ) client = UserEventServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.UserEventServiceRestInterceptor, "post_import_user_events" - ) as post, mock.patch.object( - transports.UserEventServiceRestInterceptor, - "post_import_user_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.UserEventServiceRestInterceptor, "pre_import_user_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.UserEventServiceRestInterceptor, "post_import_user_events" + ) as post, + mock.patch.object( + transports.UserEventServiceRestInterceptor, + "post_import_user_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.UserEventServiceRestInterceptor, "pre_import_user_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3967,8 +3984,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4034,8 +4052,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4101,8 +4120,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4326,11 +4346,14 @@ def test_user_event_service_base_transport(): def test_user_event_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.discoveryengine_v1beta.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserEventServiceTransport( @@ -4347,9 +4370,12 @@ def test_user_event_service_base_transport_with_credentials_file(): def test_user_event_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.discoveryengine_v1beta.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.discoveryengine_v1beta.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UserEventServiceTransport() @@ -4421,11 +4447,12 @@ def test_user_event_service_transport_auth_gdch_credentials(transport_class): def test_user_event_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5094,6 +5121,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5239,6 +5298,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5384,6 +5477,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = UserEventServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = UserEventServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = UserEventServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py index 1f479e46edeb..75a1086713b9 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py @@ -231,7 +231,7 @@ def transport(self) -> DlpServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py index 2b2e5fbdbe99..748cc441f58f 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py @@ -119,7 +119,7 @@ class DlpServiceClient(metaclass=DlpServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -691,7 +695,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -788,7 +792,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -884,7 +888,7 @@ def __init__( self._universe_domain = DlpServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/README.rst b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/README.rst index 50e91ed69892..8ff65cc2ae82 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/README.rst +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DlpServiceTransport` is the ABC for all transports. -- public child `DlpServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DlpServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDlpServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DlpServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DlpServiceTransport`` is the ABC for all transports. + +- public child ``DlpServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DlpServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDlpServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DlpServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py index 784a5afda500..6dbb7662d9fd 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py index 59233c153bd4..844cb2ad84a3 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py index 845059f8ffdd..a2375d7bbeaa 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py index 0bc2e64f634f..6e048d56f690 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py @@ -2748,6 +2748,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DlpServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index b0ba57676b6c..78a1a8f78847 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dlp/setup.py b/packages/google-cloud-dlp/setup.py index 40ec5e8546d6..b67208d3ed9c 100644 --- a/packages/google-cloud-dlp/setup.py +++ b/packages/google-cloud-dlp/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dlp" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dlp/testing/constraints-3.7.txt b/packages/google-cloud-dlp/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-dlp/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-dlp/testing/constraints-3.8.txt b/packages/google-cloud-dlp/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-dlp/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-dlp/testing/constraints-3.9.txt b/packages/google-cloud-dlp/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-dlp/testing/constraints-3.9.txt +++ b/packages/google-cloud-dlp/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py b/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py index 5023ac484581..489c30c7883b 100644 --- a/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py +++ b/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DlpServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DlpServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + DlpServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1249,11 +1253,13 @@ def test_dlp_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -35340,8 +35346,9 @@ def test_inspect_content_rest_bad_request(request_type=dlp.InspectContentRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35401,17 +35408,19 @@ def test_inspect_content_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_inspect_content" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_inspect_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_inspect_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_inspect_content" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_inspect_content_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_inspect_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35460,8 +35469,9 @@ def test_redact_image_rest_bad_request(request_type=dlp.RedactImageRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35526,17 +35536,19 @@ def test_redact_image_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_redact_image" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_redact_image_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_redact_image" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_redact_image" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_redact_image_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_redact_image" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35585,8 +35597,9 @@ def test_deidentify_content_rest_bad_request(request_type=dlp.DeidentifyContentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35646,17 +35659,20 @@ def test_deidentify_content_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_deidentify_content" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_deidentify_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_deidentify_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_deidentify_content" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_deidentify_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_deidentify_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35707,8 +35723,9 @@ def test_reidentify_content_rest_bad_request(request_type=dlp.ReidentifyContentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35768,17 +35785,20 @@ def test_reidentify_content_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_reidentify_content" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_reidentify_content_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_reidentify_content" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_reidentify_content" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_reidentify_content_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_reidentify_content" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35829,8 +35849,9 @@ def test_list_info_types_rest_bad_request(request_type=dlp.ListInfoTypesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35890,17 +35911,19 @@ def test_list_info_types_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_info_types" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_info_types_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_info_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_info_types" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_info_types_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_info_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35951,8 +35974,9 @@ def test_create_inspect_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36019,18 +36043,20 @@ def test_create_inspect_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_inspect_template" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_create_inspect_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_inspect_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_inspect_template" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_create_inspect_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_inspect_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36085,8 +36111,9 @@ def test_update_inspect_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36155,18 +36182,20 @@ def test_update_inspect_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_inspect_template" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_update_inspect_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_update_inspect_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_inspect_template" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_update_inspect_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_update_inspect_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36221,8 +36250,9 @@ def test_get_inspect_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36291,17 +36321,20 @@ def test_get_inspect_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_inspect_template" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_inspect_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_inspect_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_inspect_template" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_inspect_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_inspect_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36352,8 +36385,9 @@ def test_list_inspect_templates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36416,18 +36450,20 @@ def test_list_inspect_templates_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_inspect_templates" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_inspect_templates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_inspect_templates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_inspect_templates" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_inspect_templates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_inspect_templates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36484,8 +36520,9 @@ def test_delete_inspect_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36544,13 +36581,13 @@ def test_delete_inspect_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_inspect_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_inspect_template" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteInspectTemplateRequest.pb( dlp.DeleteInspectTemplateRequest() @@ -36595,8 +36632,9 @@ def test_create_deidentify_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36663,18 +36701,20 @@ def test_create_deidentify_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_deidentify_template" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_create_deidentify_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_deidentify_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_deidentify_template" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_create_deidentify_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_deidentify_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36727,8 +36767,9 @@ def test_update_deidentify_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36795,18 +36836,20 @@ def test_update_deidentify_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_deidentify_template" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_update_deidentify_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_update_deidentify_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_deidentify_template" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_update_deidentify_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_update_deidentify_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36859,8 +36902,9 @@ def test_get_deidentify_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36927,18 +36971,20 @@ def test_get_deidentify_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_deidentify_template" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_get_deidentify_template_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_deidentify_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_deidentify_template" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_deidentify_template_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_deidentify_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36991,8 +37037,9 @@ def test_list_deidentify_templates_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37055,18 +37102,20 @@ def test_list_deidentify_templates_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_deidentify_templates" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_deidentify_templates_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_deidentify_templates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_deidentify_templates" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_deidentify_templates_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_deidentify_templates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37124,8 +37173,9 @@ def test_delete_deidentify_template_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37182,13 +37232,13 @@ def test_delete_deidentify_template_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_deidentify_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_deidentify_template" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteDeidentifyTemplateRequest.pb( dlp.DeleteDeidentifyTemplateRequest() @@ -37231,8 +37281,9 @@ def test_create_job_trigger_rest_bad_request(request_type=dlp.CreateJobTriggerRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37301,17 +37352,20 @@ def test_create_job_trigger_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_job_trigger" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_job_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_job_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_job_trigger" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_create_job_trigger_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_job_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37360,8 +37414,9 @@ def test_update_job_trigger_rest_bad_request(request_type=dlp.UpdateJobTriggerRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37430,17 +37485,20 @@ def test_update_job_trigger_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_job_trigger" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_job_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_update_job_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_job_trigger" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_update_job_trigger_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_update_job_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37491,8 +37549,9 @@ def test_hybrid_inspect_job_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37552,18 +37611,20 @@ def test_hybrid_inspect_job_trigger_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_hybrid_inspect_job_trigger" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_hybrid_inspect_job_trigger_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_hybrid_inspect_job_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_hybrid_inspect_job_trigger" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_hybrid_inspect_job_trigger_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_hybrid_inspect_job_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37614,8 +37675,9 @@ def test_get_job_trigger_rest_bad_request(request_type=dlp.GetJobTriggerRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37684,17 +37746,19 @@ def test_get_job_trigger_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_job_trigger" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_job_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_job_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_job_trigger" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_job_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_job_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37743,8 +37807,9 @@ def test_list_job_triggers_rest_bad_request(request_type=dlp.ListJobTriggersRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37807,17 +37872,19 @@ def test_list_job_triggers_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_job_triggers" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_job_triggers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_job_triggers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_job_triggers" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_job_triggers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_job_triggers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37868,8 +37935,9 @@ def test_delete_job_trigger_rest_bad_request(request_type=dlp.DeleteJobTriggerRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37926,13 +37994,13 @@ def test_delete_job_trigger_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_job_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_job_trigger" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteJobTriggerRequest.pb(dlp.DeleteJobTriggerRequest()) transcode.return_value = { @@ -37975,8 +38043,9 @@ def test_activate_job_trigger_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38045,17 +38114,20 @@ def test_activate_job_trigger_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_activate_job_trigger" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_activate_job_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_activate_job_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_activate_job_trigger" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_activate_job_trigger_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_activate_job_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38106,8 +38178,9 @@ def test_create_discovery_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38176,18 +38249,20 @@ def test_create_discovery_config_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_discovery_config" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_create_discovery_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_discovery_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_discovery_config" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_create_discovery_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_discovery_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38242,8 +38317,9 @@ def test_update_discovery_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38314,18 +38390,20 @@ def test_update_discovery_config_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_discovery_config" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_update_discovery_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_update_discovery_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_discovery_config" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_update_discovery_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_update_discovery_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38380,8 +38458,9 @@ def test_get_discovery_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38452,17 +38531,20 @@ def test_get_discovery_config_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_discovery_config" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_discovery_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_discovery_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_discovery_config" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_discovery_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_discovery_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38513,8 +38595,9 @@ def test_list_discovery_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38577,18 +38660,20 @@ def test_list_discovery_configs_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_discovery_configs" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_discovery_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_discovery_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_discovery_configs" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_discovery_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_discovery_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38645,8 +38730,9 @@ def test_delete_discovery_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38705,13 +38791,13 @@ def test_delete_discovery_config_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_discovery_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_discovery_config" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteDiscoveryConfigRequest.pb( dlp.DeleteDiscoveryConfigRequest() @@ -38754,8 +38840,9 @@ def test_create_dlp_job_rest_bad_request(request_type=dlp.CreateDlpJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38824,17 +38911,19 @@ def test_create_dlp_job_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_dlp_job" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_dlp_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_dlp_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_dlp_job" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_dlp_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_dlp_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38883,8 +38972,9 @@ def test_list_dlp_jobs_rest_bad_request(request_type=dlp.ListDlpJobsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38947,17 +39037,19 @@ def test_list_dlp_jobs_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_dlp_jobs" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_dlp_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_dlp_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_dlp_jobs" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_dlp_jobs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_dlp_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39006,8 +39098,9 @@ def test_get_dlp_job_rest_bad_request(request_type=dlp.GetDlpJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39076,17 +39169,19 @@ def test_get_dlp_job_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_dlp_job" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_dlp_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_dlp_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_dlp_job" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_dlp_job_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_dlp_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39135,8 +39230,9 @@ def test_delete_dlp_job_rest_bad_request(request_type=dlp.DeleteDlpJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39193,13 +39289,13 @@ def test_delete_dlp_job_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_dlp_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_dlp_job" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteDlpJobRequest.pb(dlp.DeleteDlpJobRequest()) transcode.return_value = { @@ -39240,8 +39336,9 @@ def test_cancel_dlp_job_rest_bad_request(request_type=dlp.CancelDlpJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39298,13 +39395,13 @@ def test_cancel_dlp_job_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_cancel_dlp_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_cancel_dlp_job" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.CancelDlpJobRequest.pb(dlp.CancelDlpJobRequest()) transcode.return_value = { @@ -39347,8 +39444,9 @@ def test_create_stored_info_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39411,18 +39509,20 @@ def test_create_stored_info_type_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_stored_info_type" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_create_stored_info_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_stored_info_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_stored_info_type" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_create_stored_info_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_stored_info_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39475,8 +39575,9 @@ def test_update_stored_info_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39539,18 +39640,20 @@ def test_update_stored_info_type_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_stored_info_type" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_update_stored_info_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_update_stored_info_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_stored_info_type" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_update_stored_info_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_update_stored_info_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39603,8 +39706,9 @@ def test_get_stored_info_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39667,17 +39771,20 @@ def test_get_stored_info_type_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_stored_info_type" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_stored_info_type_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_stored_info_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_stored_info_type" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_stored_info_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_stored_info_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39728,8 +39835,9 @@ def test_list_stored_info_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39792,18 +39900,20 @@ def test_list_stored_info_types_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_stored_info_types" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_stored_info_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_stored_info_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_stored_info_types" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_stored_info_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_stored_info_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39856,8 +39966,9 @@ def test_delete_stored_info_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39914,13 +40025,13 @@ def test_delete_stored_info_type_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_stored_info_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_stored_info_type" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteStoredInfoTypeRequest.pb( dlp.DeleteStoredInfoTypeRequest() @@ -39965,8 +40076,9 @@ def test_list_project_data_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40029,18 +40141,20 @@ def test_list_project_data_profiles_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_project_data_profiles" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_project_data_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_project_data_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_project_data_profiles" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_project_data_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_project_data_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40098,8 +40212,9 @@ def test_list_table_data_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40162,18 +40277,20 @@ def test_list_table_data_profiles_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_table_data_profiles" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_table_data_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_table_data_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_table_data_profiles" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_table_data_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_table_data_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40228,8 +40345,9 @@ def test_list_column_data_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40292,18 +40410,20 @@ def test_list_column_data_profiles_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_column_data_profiles" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_column_data_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_column_data_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_column_data_profiles" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_column_data_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_column_data_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40360,8 +40480,9 @@ def test_get_project_data_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40432,18 +40553,20 @@ def test_get_project_data_profile_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_project_data_profile" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_get_project_data_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_project_data_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_project_data_profile" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_project_data_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_project_data_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40496,8 +40619,9 @@ def test_list_file_store_data_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40560,18 +40684,20 @@ def test_list_file_store_data_profiles_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_file_store_data_profiles" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_list_file_store_data_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_file_store_data_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_file_store_data_profiles" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_list_file_store_data_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_file_store_data_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40631,8 +40757,9 @@ def test_get_file_store_data_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40720,18 +40847,20 @@ def test_get_file_store_data_profile_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_file_store_data_profile" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_get_file_store_data_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_file_store_data_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_file_store_data_profile" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_file_store_data_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_file_store_data_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -40786,8 +40915,9 @@ def test_delete_file_store_data_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40846,13 +40976,13 @@ def test_delete_file_store_data_profile_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_file_store_data_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_file_store_data_profile" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteFileStoreDataProfileRequest.pb( dlp.DeleteFileStoreDataProfileRequest() @@ -40899,8 +41029,9 @@ def test_get_table_data_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -40994,18 +41125,20 @@ def test_get_table_data_profile_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_table_data_profile" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_get_table_data_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_table_data_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_table_data_profile" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_table_data_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_table_data_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41058,8 +41191,9 @@ def test_get_column_data_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41159,18 +41293,20 @@ def test_get_column_data_profile_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_column_data_profile" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_get_column_data_profile_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_column_data_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_column_data_profile" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_get_column_data_profile_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_column_data_profile" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41225,8 +41361,9 @@ def test_delete_table_data_profile_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41285,13 +41422,13 @@ def test_delete_table_data_profile_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_table_data_profile" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_table_data_profile" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteTableDataProfileRequest.pb( dlp.DeleteTableDataProfileRequest() @@ -41336,8 +41473,9 @@ def test_hybrid_inspect_dlp_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41397,18 +41535,20 @@ def test_hybrid_inspect_dlp_job_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_hybrid_inspect_dlp_job" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, - "post_hybrid_inspect_dlp_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_hybrid_inspect_dlp_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_hybrid_inspect_dlp_job" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_hybrid_inspect_dlp_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_hybrid_inspect_dlp_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41457,8 +41597,9 @@ def test_finish_dlp_job_rest_bad_request(request_type=dlp.FinishDlpJobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41515,13 +41656,13 @@ def test_finish_dlp_job_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_finish_dlp_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_finish_dlp_job" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.FinishDlpJobRequest.pb(dlp.FinishDlpJobRequest()) transcode.return_value = { @@ -41562,8 +41703,9 @@ def test_create_connection_rest_bad_request(request_type=dlp.CreateConnectionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41628,17 +41770,19 @@ def test_create_connection_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_connection" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_create_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_create_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_connection" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_create_connection_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_create_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41687,8 +41831,9 @@ def test_get_connection_rest_bad_request(request_type=dlp.GetConnectionRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41753,17 +41898,19 @@ def test_get_connection_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_connection" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_get_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_get_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_connection" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_get_connection_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_get_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41812,8 +41959,9 @@ def test_list_connections_rest_bad_request(request_type=dlp.ListConnectionsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41876,17 +42024,19 @@ def test_list_connections_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_connections" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_list_connections_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_list_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_connections" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_list_connections_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_list_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -41937,8 +42087,9 @@ def test_search_connections_rest_bad_request(request_type=dlp.SearchConnectionsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42001,17 +42152,20 @@ def test_search_connections_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_search_connections" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_search_connections_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_search_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_search_connections" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, + "post_search_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_search_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42062,8 +42216,9 @@ def test_delete_connection_rest_bad_request(request_type=dlp.DeleteConnectionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42120,13 +42275,13 @@ def test_delete_connection_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_delete_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_delete_connection" + ) as pre, + ): pre.assert_not_called() pb_message = dlp.DeleteConnectionRequest.pb(dlp.DeleteConnectionRequest()) transcode.return_value = { @@ -42167,8 +42322,9 @@ def test_update_connection_rest_bad_request(request_type=dlp.UpdateConnectionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42233,17 +42389,19 @@ def test_update_connection_rest_interceptors(null_interceptor): ) client = DlpServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_connection" - ) as post, mock.patch.object( - transports.DlpServiceRestInterceptor, "post_update_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DlpServiceRestInterceptor, "pre_update_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_connection" + ) as post, + mock.patch.object( + transports.DlpServiceRestInterceptor, "post_update_connection_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DlpServiceRestInterceptor, "pre_update_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43583,11 +43741,14 @@ def test_dlp_service_base_transport(): def test_dlp_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.dlp_v2.services.dlp_service.transports.DlpServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.dlp_v2.services.dlp_service.transports.DlpServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DlpServiceTransport( @@ -43604,9 +43765,12 @@ def test_dlp_service_base_transport_with_credentials_file(): def test_dlp_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.dlp_v2.services.dlp_service.transports.DlpServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.dlp_v2.services.dlp_service.transports.DlpServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DlpServiceTransport() @@ -43678,11 +43842,12 @@ def test_dlp_service_transport_auth_gdch_credentials(transport_class): def test_dlp_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py index 82e0348f0adc..f435fa7c6d4f 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py @@ -231,7 +231,7 @@ def transport(self) -> DataMigrationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5255,7 +5255,7 @@ async def sample_fetch_static_ips(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5281,8 +5281,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5291,7 +5295,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5299,7 +5303,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5310,7 +5314,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5336,8 +5340,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5346,7 +5354,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5354,7 +5362,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5365,7 +5373,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5395,8 +5403,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5405,7 +5417,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5413,7 +5425,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5421,7 +5433,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5450,8 +5462,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5460,7 +5476,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5468,7 +5484,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5476,7 +5492,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5568,8 +5584,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5578,7 +5598,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5586,7 +5608,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5597,7 +5619,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5690,8 +5712,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5700,7 +5726,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5708,7 +5736,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5719,7 +5747,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5750,8 +5778,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5762,7 +5794,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5770,7 +5804,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5781,7 +5815,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5807,8 +5841,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5817,7 +5855,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5825,7 +5863,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5836,7 +5874,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5862,8 +5900,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5872,7 +5914,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5880,7 +5922,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py index 25c873f7b75d..0c8220ea2bb4 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py @@ -125,7 +125,7 @@ class DataMigrationServiceClient(metaclass=DataMigrationServiceClientMeta): """Database Migration service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -559,7 +563,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -656,7 +660,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -756,7 +760,7 @@ def __init__( self._universe_domain = DataMigrationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5706,7 +5710,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5732,8 +5736,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5742,7 +5750,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5751,7 +5759,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5765,7 +5773,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5791,8 +5799,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5801,7 +5813,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5810,7 +5822,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5824,7 +5836,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5854,8 +5866,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5864,7 +5880,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5872,7 +5888,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5880,7 +5896,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5909,8 +5925,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5919,7 +5939,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5927,7 +5947,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5935,7 +5955,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6027,8 +6047,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6037,7 +6061,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6046,7 +6072,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6060,7 +6086,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6153,8 +6179,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6163,7 +6193,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6172,7 +6204,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6186,7 +6218,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6217,8 +6249,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6227,7 +6263,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6236,7 +6274,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6250,7 +6288,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6276,8 +6314,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6286,7 +6328,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6295,7 +6337,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6309,7 +6351,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6335,8 +6377,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6345,7 +6391,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6354,7 +6400,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/README.rst b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/README.rst index 9d82094a0c0f..8a15afda9b0a 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/README.rst +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataMigrationServiceTransport` is the ABC for all transports. -- public child `DataMigrationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataMigrationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataMigrationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataMigrationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataMigrationServiceTransport`` is the ABC for all transports. + +- public child ``DataMigrationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataMigrationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataMigrationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataMigrationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py index 69c923e673be..25e2f3b1460a 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py @@ -91,6 +91,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -140,6 +144,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py index 1a407f6352ac..1be869ffc4e3 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py @@ -65,7 +65,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py index 4e16cd5e2e92..a93832cfc810 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py @@ -71,7 +71,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -106,7 +106,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index 59582b8e2ff4..3958ed4545f8 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-dms/setup.py b/packages/google-cloud-dms/setup.py index 12cfdf2a440f..7c683095b4ca 100644 --- a/packages/google-cloud-dms/setup.py +++ b/packages/google-cloud-dms/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-dms/testing/constraints-3.7.txt b/packages/google-cloud-dms/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-dms/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dms/testing/constraints-3.8.txt b/packages/google-cloud-dms/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-dms/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-dms/testing/constraints-3.9.txt b/packages/google-cloud-dms/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-dms/testing/constraints-3.9.txt +++ b/packages/google-cloud-dms/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py b/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py index 94530a177fbd..f480aff38993 100644 --- a/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py +++ b/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py @@ -139,6 +139,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataMigrationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +162,10 @@ def test__get_default_mtls_endpoint(): DataMigrationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataMigrationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1320,11 +1325,13 @@ def test_data_migration_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -18071,11 +18078,14 @@ def test_data_migration_service_base_transport(): def test_data_migration_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.clouddms_v1.services.data_migration_service.transports.DataMigrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.clouddms_v1.services.data_migration_service.transports.DataMigrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataMigrationServiceTransport( @@ -18092,9 +18102,12 @@ def test_data_migration_service_base_transport_with_credentials_file(): def test_data_migration_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.clouddms_v1.services.data_migration_service.transports.DataMigrationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.clouddms_v1.services.data_migration_service.transports.DataMigrationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataMigrationServiceTransport() @@ -18165,11 +18178,12 @@ def test_data_migration_service_transport_auth_gdch_credentials(transport_class) def test_data_migration_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -18867,6 +18881,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataMigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19006,6 +19052,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataMigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19151,6 +19229,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataMigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19296,6 +19408,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataMigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19441,6 +19587,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataMigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19584,6 +19764,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataMigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19748,6 +19962,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = DataMigrationServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19915,6 +20164,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = DataMigrationServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20092,6 +20376,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = DataMigrationServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DataMigrationServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = DataMigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py index 8dbc2c825e97..61dfd7dcfff3 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py @@ -240,7 +240,7 @@ def transport(self) -> DocumentProcessorServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3156,7 +3156,7 @@ async def sample_list_evaluations(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3182,8 +3182,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3192,7 +3196,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3200,7 +3204,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3211,7 +3215,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3237,8 +3241,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3247,7 +3255,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3255,7 +3263,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3266,7 +3274,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3295,8 +3303,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3305,7 +3317,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3313,7 +3325,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3321,7 +3333,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3347,8 +3359,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3357,7 +3373,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3365,7 +3381,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3376,7 +3392,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3402,8 +3418,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3412,7 +3432,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3420,7 +3440,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py index e02297803068..175191bb63b8 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -130,7 +130,7 @@ class DocumentProcessorServiceClient(metaclass=DocumentProcessorServiceClientMet """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -549,7 +553,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -648,7 +652,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -750,7 +754,7 @@ def __init__( self._universe_domain = DocumentProcessorServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3607,7 +3611,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3633,8 +3637,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3643,7 +3651,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3652,7 +3660,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3666,7 +3674,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3692,8 +3700,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3702,7 +3714,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3711,7 +3723,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3725,7 +3737,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3754,8 +3766,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3764,7 +3780,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3772,7 +3788,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3780,7 +3796,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3806,8 +3822,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3816,7 +3836,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3825,7 +3845,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3839,7 +3859,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3865,8 +3885,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3875,7 +3899,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3884,7 +3908,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/README.rst b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/README.rst index d3c5f4919121..2901a3efaa36 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/README.rst +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentProcessorServiceTransport` is the ABC for all transports. -- public child `DocumentProcessorServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentProcessorServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentProcessorServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentProcessorServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentProcessorServiceTransport`` is the ABC for all transports. + +- public child ``DocumentProcessorServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentProcessorServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentProcessorServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentProcessorServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index c8333ff2858e..00fc46ce212d 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index 91d82f296485..e4144a97f058 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index abaeefc3d12d..8502054d0de6 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py index bfeee2803f67..1740845ffb53 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py @@ -1550,6 +1550,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentProcessorServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py index d0364e91b20a..5837b2b35adf 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py @@ -241,7 +241,7 @@ def transport(self) -> DocumentProcessorServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3312,7 +3312,7 @@ async def sample_import_processor_version(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3338,8 +3338,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3348,7 +3352,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3356,7 +3360,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3367,7 +3371,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3393,8 +3397,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3403,7 +3411,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3411,7 +3419,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3422,7 +3430,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3451,8 +3459,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3461,7 +3473,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3469,7 +3481,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3477,7 +3489,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3503,8 +3515,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3513,7 +3529,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3521,7 +3537,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3532,7 +3548,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3558,8 +3574,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3568,7 +3588,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3576,7 +3596,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py index e912ae98dd8d..4a03d058fea9 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py @@ -130,7 +130,7 @@ class DocumentProcessorServiceClient(metaclass=DocumentProcessorServiceClientMet """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -138,7 +138,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -148,6 +148,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -549,7 +553,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -648,7 +652,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -750,7 +754,7 @@ def __init__( self._universe_domain = DocumentProcessorServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3759,7 +3763,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3785,8 +3789,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3795,7 +3803,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3804,7 +3812,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3818,7 +3826,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3844,8 +3852,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3854,7 +3866,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3863,7 +3875,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3877,7 +3889,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3906,8 +3918,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3916,7 +3932,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3924,7 +3940,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3932,7 +3948,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3958,8 +3974,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3968,7 +3988,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3977,7 +3997,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3991,7 +4011,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4017,8 +4037,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4027,7 +4051,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4036,7 +4060,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/README.rst b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/README.rst index d3c5f4919121..2901a3efaa36 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/README.rst +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentProcessorServiceTransport` is the ABC for all transports. -- public child `DocumentProcessorServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentProcessorServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentProcessorServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentProcessorServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentProcessorServiceTransport`` is the ABC for all transports. + +- public child ``DocumentProcessorServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentProcessorServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentProcessorServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentProcessorServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index 08003b58a4f4..443a20cbdd55 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index b6c949a525f0..276df1cddfd4 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index c194639a1c78..dad814073fc3 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py index f9fba6e8fdc8..f44dd4f3983a 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py @@ -1607,6 +1607,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentProcessorServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py index d873bfd29611..b26117cfc2ae 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> DocumentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1198,7 +1198,7 @@ async def sample_update_dataset_schema(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1224,8 +1224,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1234,7 +1238,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1242,7 +1246,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1253,7 +1257,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1279,8 +1283,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1289,7 +1297,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1297,7 +1305,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1308,7 +1316,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1337,8 +1345,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1347,7 +1359,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1355,7 +1367,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1363,7 +1375,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1389,8 +1401,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1399,7 +1415,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1407,7 +1423,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1418,7 +1434,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1444,8 +1460,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1454,7 +1474,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1462,7 +1482,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py index dcb9b1e49a5c..3d33e9a90218 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py @@ -123,7 +123,7 @@ class DocumentServiceClient(metaclass=DocumentServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -492,7 +496,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -589,7 +593,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -687,7 +691,7 @@ def __init__( self._universe_domain = DocumentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1658,7 +1662,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1684,8 +1688,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1694,7 +1702,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1703,7 +1711,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1717,7 +1725,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1743,8 +1751,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1753,7 +1765,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1762,7 +1774,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1776,7 +1788,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1805,8 +1817,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1815,7 +1831,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1823,7 +1839,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1831,7 +1847,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1857,8 +1873,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1867,7 +1887,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1876,7 +1896,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1890,7 +1910,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1916,8 +1936,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1926,7 +1950,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1935,7 +1959,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/README.rst b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/README.rst index 4aabee4652ef..765422bd31c7 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/README.rst +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DocumentServiceTransport` is the ABC for all transports. -- public child `DocumentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DocumentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDocumentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DocumentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DocumentServiceTransport`` is the ABC for all transports. + +- public child ``DocumentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DocumentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDocumentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DocumentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py index 9040f417ccf2..0b597133b032 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py index 653f2dfc5d1b..b6b0d92e6cfc 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py index a027b2b3bd69..16f48af3d38d 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py index 95a45abd6cae..0f91fb8ceadd 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py @@ -670,6 +670,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DocumentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index 045b56f0aa8e..1d015a586bb9 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-documentai/setup.py b/packages/google-cloud-documentai/setup.py index 28c7f991db3e..1d20e7c28450 100644 --- a/packages/google-cloud-documentai/setup.py +++ b/packages/google-cloud-documentai/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-documentai" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-documentai/testing/constraints-3.7.txt b/packages/google-cloud-documentai/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-documentai/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-documentai/testing/constraints-3.8.txt b/packages/google-cloud-documentai/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-documentai/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-documentai/testing/constraints-3.9.txt b/packages/google-cloud-documentai/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-documentai/testing/constraints-3.9.txt +++ b/packages/google-cloud-documentai/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py index 514462ef734f..0e62198c9b26 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -149,6 +149,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentProcessorServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -171,6 +172,10 @@ def test__get_default_mtls_endpoint(): DocumentProcessorServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentProcessorServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1382,11 +1387,13 @@ def test_document_processor_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -14988,8 +14995,9 @@ def test_process_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15049,18 +15057,20 @@ def test_process_document_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_process_document" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_process_document_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_process_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_process_document" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_process_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_process_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15118,8 +15128,9 @@ def test_batch_process_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15176,22 +15187,23 @@ def test_batch_process_documents_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_batch_process_documents", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_batch_process_documents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_batch_process_documents", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_batch_process_documents", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_batch_process_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_batch_process_documents", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15244,8 +15256,9 @@ def test_fetch_processor_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15307,18 +15320,22 @@ def test_fetch_processor_types_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_fetch_processor_types" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_fetch_processor_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_fetch_processor_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_fetch_processor_types", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_fetch_processor_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_fetch_processor_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15376,8 +15393,9 @@ def test_list_processor_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15442,18 +15460,22 @@ def test_list_processor_types_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_list_processor_types" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processor_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_list_processor_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_types", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_list_processor_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15511,8 +15533,9 @@ def test_get_processor_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15585,18 +15608,21 @@ def test_get_processor_type_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_processor_type" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_processor_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_type", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15651,8 +15677,9 @@ def test_list_processors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15717,18 +15744,20 @@ def test_list_processors_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_list_processors" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_list_processors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_list_processors" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_list_processors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15786,8 +15815,9 @@ def test_get_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15866,18 +15896,20 @@ def test_get_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_get_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15930,8 +15962,9 @@ def test_train_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15988,22 +16021,23 @@ def test_train_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_train_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_train_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_train_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_train_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_train_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_train_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16058,8 +16092,9 @@ def test_get_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16143,18 +16178,22 @@ def test_get_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_processor_version" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_get_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16207,8 +16246,9 @@ def test_list_processor_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16273,20 +16313,22 @@ def test_list_processor_versions_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processor_versions", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processor_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_list_processor_versions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_versions", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_list_processor_versions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16346,8 +16388,9 @@ def test_delete_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16406,22 +16449,23 @@ def test_delete_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_delete_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_delete_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_delete_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_delete_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_delete_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_delete_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16476,8 +16520,9 @@ def test_deploy_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16536,22 +16581,23 @@ def test_deploy_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_deploy_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_deploy_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_deploy_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_deploy_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_deploy_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_deploy_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16606,8 +16652,9 @@ def test_undeploy_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16666,22 +16713,23 @@ def test_undeploy_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_undeploy_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_undeploy_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_undeploy_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_undeploy_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_undeploy_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_undeploy_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16734,8 +16782,9 @@ def test_create_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16898,18 +16947,20 @@ def test_create_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_create_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_create_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_create_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_create_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_create_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_create_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16962,8 +17013,9 @@ def test_delete_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17020,20 +17072,21 @@ def test_delete_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_delete_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_delete_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_delete_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_delete_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_delete_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_delete_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17086,8 +17139,9 @@ def test_enable_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17144,20 +17198,21 @@ def test_enable_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_enable_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_enable_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_enable_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_enable_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_enable_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_enable_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17210,8 +17265,9 @@ def test_disable_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17268,20 +17324,21 @@ def test_disable_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_disable_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_disable_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_disable_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_disable_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_disable_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_disable_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17336,8 +17393,9 @@ def test_set_default_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17396,22 +17454,23 @@ def test_set_default_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_set_default_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_set_default_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_set_default_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_set_default_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_set_default_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_set_default_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17466,8 +17525,9 @@ def test_review_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17526,20 +17586,21 @@ def test_review_document_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_review_document" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_review_document_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_review_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_review_document" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_review_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_review_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17594,8 +17655,9 @@ def test_evaluate_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17654,22 +17716,23 @@ def test_evaluate_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_evaluate_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_evaluate_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_evaluate_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_evaluate_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_evaluate_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_evaluate_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17724,8 +17787,9 @@ def test_get_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17794,18 +17858,20 @@ def test_get_evaluation_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_evaluation" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_get_evaluation" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_get_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17860,8 +17926,9 @@ def test_list_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17928,18 +17995,20 @@ def test_list_evaluations_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_list_evaluations" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_list_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_list_evaluations" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_list_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17997,8 +18066,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18057,8 +18127,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18119,8 +18190,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18181,8 +18253,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18243,8 +18316,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18866,11 +18940,14 @@ def test_document_processor_service_base_transport(): def test_document_processor_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentProcessorServiceTransport( @@ -18887,9 +18964,12 @@ def test_document_processor_service_base_transport_with_credentials_file(): def test_document_processor_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentProcessorServiceTransport() @@ -18963,11 +19043,12 @@ def test_document_processor_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -19750,6 +19831,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19895,6 +20008,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20040,6 +20187,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20185,6 +20366,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20330,6 +20545,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 0bda22217c63..ecb5e87e771d 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -149,6 +149,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentProcessorServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -171,6 +172,10 @@ def test__get_default_mtls_endpoint(): DocumentProcessorServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentProcessorServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1382,11 +1387,13 @@ def test_document_processor_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -15584,8 +15591,9 @@ def test_process_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15648,18 +15656,20 @@ def test_process_document_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_process_document" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_process_document_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_process_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_process_document" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_process_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_process_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15717,8 +15727,9 @@ def test_batch_process_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15775,22 +15786,23 @@ def test_batch_process_documents_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_batch_process_documents", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_batch_process_documents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_batch_process_documents", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_batch_process_documents", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_batch_process_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_batch_process_documents", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15843,8 +15855,9 @@ def test_fetch_processor_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15906,18 +15919,22 @@ def test_fetch_processor_types_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_fetch_processor_types" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_fetch_processor_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_fetch_processor_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_fetch_processor_types", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_fetch_processor_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_fetch_processor_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15975,8 +15992,9 @@ def test_list_processor_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16041,18 +16059,22 @@ def test_list_processor_types_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_list_processor_types" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processor_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_list_processor_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_types", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_list_processor_types", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16110,8 +16132,9 @@ def test_get_processor_type_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16184,18 +16207,21 @@ def test_get_processor_type_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_processor_type" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_processor_type_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor_type" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_type", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_type_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor_type" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16250,8 +16276,9 @@ def test_list_processors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16316,18 +16343,20 @@ def test_list_processors_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_list_processors" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_list_processors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_list_processors" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_list_processors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16385,8 +16414,9 @@ def test_get_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16465,18 +16495,20 @@ def test_get_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_get_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16529,8 +16561,9 @@ def test_train_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16587,22 +16620,23 @@ def test_train_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_train_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_train_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_train_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_train_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_train_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_train_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16657,8 +16691,9 @@ def test_get_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16742,18 +16777,22 @@ def test_get_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_processor_version" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_processor_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_get_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16806,8 +16845,9 @@ def test_list_processor_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16872,20 +16912,22 @@ def test_list_processor_versions_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processor_versions", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_processor_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_list_processor_versions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_versions", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_processor_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_list_processor_versions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16945,8 +16987,9 @@ def test_delete_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17005,22 +17048,23 @@ def test_delete_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_delete_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_delete_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_delete_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_delete_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_delete_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_delete_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17075,8 +17119,9 @@ def test_deploy_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17135,22 +17180,23 @@ def test_deploy_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_deploy_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_deploy_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_deploy_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_deploy_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_deploy_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_deploy_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17205,8 +17251,9 @@ def test_undeploy_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17265,22 +17312,23 @@ def test_undeploy_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_undeploy_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_undeploy_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_undeploy_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_undeploy_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_undeploy_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_undeploy_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17333,8 +17381,9 @@ def test_create_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17497,18 +17546,20 @@ def test_create_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_create_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_create_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_create_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_create_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_create_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_create_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17561,8 +17612,9 @@ def test_delete_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17619,20 +17671,21 @@ def test_delete_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_delete_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_delete_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_delete_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_delete_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_delete_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_delete_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17685,8 +17738,9 @@ def test_enable_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17743,20 +17797,21 @@ def test_enable_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_enable_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_enable_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_enable_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_enable_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_enable_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_enable_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17809,8 +17864,9 @@ def test_disable_processor_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17867,20 +17923,21 @@ def test_disable_processor_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_disable_processor" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_disable_processor_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_disable_processor" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_disable_processor" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_disable_processor_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_disable_processor" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17935,8 +17992,9 @@ def test_set_default_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17995,22 +18053,23 @@ def test_set_default_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_set_default_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_set_default_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_set_default_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_set_default_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_set_default_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_set_default_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18065,8 +18124,9 @@ def test_review_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18125,20 +18185,21 @@ def test_review_document_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_review_document" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_review_document_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_review_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_review_document" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_review_document_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_review_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18193,8 +18254,9 @@ def test_evaluate_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18253,22 +18315,23 @@ def test_evaluate_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_evaluate_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_evaluate_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_evaluate_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_evaluate_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_evaluate_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_evaluate_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18323,8 +18386,9 @@ def test_get_evaluation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18393,18 +18457,20 @@ def test_get_evaluation_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_get_evaluation" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_get_evaluation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_get_evaluation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_get_evaluation" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_get_evaluation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_get_evaluation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18459,8 +18525,9 @@ def test_list_evaluations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18527,18 +18594,20 @@ def test_list_evaluations_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "post_list_evaluations" - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_list_evaluations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, "pre_list_evaluations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "post_list_evaluations" + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_list_evaluations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, "pre_list_evaluations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18596,8 +18665,9 @@ def test_import_processor_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18654,22 +18724,23 @@ def test_import_processor_version_rest_interceptors(null_interceptor): ) client = DocumentProcessorServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_import_processor_version", - ) as post, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "post_import_processor_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentProcessorServiceRestInterceptor, - "pre_import_processor_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_import_processor_version", + ) as post, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "post_import_processor_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentProcessorServiceRestInterceptor, + "pre_import_processor_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18722,8 +18793,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18782,8 +18854,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18844,8 +18917,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18906,8 +18980,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18968,8 +19043,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -19614,11 +19690,14 @@ def test_document_processor_service_base_transport(): def test_document_processor_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentProcessorServiceTransport( @@ -19635,9 +19714,12 @@ def test_document_processor_service_base_transport_with_credentials_file(): def test_document_processor_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentProcessorServiceTransport() @@ -19711,11 +19793,12 @@ def test_document_processor_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -20501,6 +20584,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20646,6 +20761,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20791,6 +20940,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20936,6 +21119,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -21081,6 +21298,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DocumentProcessorServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py index 52d4049fb9b8..9f24190f2933 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DocumentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): assert ( DocumentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DocumentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1318,11 +1323,13 @@ def test_document_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5819,8 +5826,9 @@ def test_update_dataset_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5962,19 +5970,21 @@ def test_update_dataset_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_dataset" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_update_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_update_dataset" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_update_dataset_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_update_dataset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6029,8 +6039,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6089,19 +6100,21 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_import_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6156,8 +6169,9 @@ def test_get_document_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6219,17 +6233,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6289,8 +6305,9 @@ def test_list_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6357,17 +6374,20 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_list_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6427,8 +6447,9 @@ def test_batch_delete_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6487,20 +6508,21 @@ def test_batch_delete_documents_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_batch_delete_documents" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_batch_delete_documents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_batch_delete_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_batch_delete_documents" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_batch_delete_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_batch_delete_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6555,8 +6577,9 @@ def test_get_dataset_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6625,18 +6648,20 @@ def test_get_dataset_schema_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_get_dataset_schema" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_get_dataset_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_get_dataset_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_get_dataset_schema" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_get_dataset_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_get_dataset_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6693,8 +6718,9 @@ def test_update_dataset_schema_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6876,18 +6902,20 @@ def test_update_dataset_schema_rest_interceptors(null_interceptor): ) client = DocumentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DocumentServiceRestInterceptor, "post_update_dataset_schema" - ) as post, mock.patch.object( - transports.DocumentServiceRestInterceptor, - "post_update_dataset_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DocumentServiceRestInterceptor, "pre_update_dataset_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "post_update_dataset_schema" + ) as post, + mock.patch.object( + transports.DocumentServiceRestInterceptor, + "post_update_dataset_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DocumentServiceRestInterceptor, "pre_update_dataset_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6940,8 +6968,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7000,8 +7029,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7062,8 +7092,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7124,8 +7155,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7186,8 +7218,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7474,11 +7507,14 @@ def test_document_service_base_transport(): def test_document_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.documentai_v1beta3.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.documentai_v1beta3.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport( @@ -7495,9 +7531,12 @@ def test_document_service_base_transport_with_credentials_file(): def test_document_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.documentai_v1beta3.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.documentai_v1beta3.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DocumentServiceTransport() @@ -7569,11 +7608,12 @@ def test_document_service_transport_auth_gdch_credentials(transport_class): def test_document_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8242,6 +8282,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8387,6 +8459,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8532,6 +8638,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8677,6 +8817,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8818,6 +8992,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DocumentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DocumentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DocumentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py index 81e7ac82eb4a..9068829bc4a4 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> DomainsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py index 762bfa151c1e..ef236b501e5a 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py @@ -118,7 +118,7 @@ class DomainsClient(metaclass=DomainsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = DomainsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/README.rst b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/README.rst index 6966249b2768..f8c17b7b0e3e 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/README.rst +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DomainsTransport` is the ABC for all transports. -- public child `DomainsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DomainsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDomainsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DomainsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DomainsTransport`` is the ABC for all transports. + +- public child ``DomainsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DomainsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDomainsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DomainsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py index 1d2fed797189..1ed126036919 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py index df3de685bcf9..fbf482d8c98e 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py index 199c8559f337..13621e36568c 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py index e57efd7b13da..6da35c4fc51a 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py @@ -991,6 +991,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DomainsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py index 8a377ea11c42..25954befa489 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> DomainsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py index 3efadbc66003..f3382fa666ff 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py @@ -118,7 +118,7 @@ class DomainsClient(metaclass=DomainsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = DomainsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/README.rst b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/README.rst index 6966249b2768..f8c17b7b0e3e 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/README.rst +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DomainsTransport` is the ABC for all transports. -- public child `DomainsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DomainsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDomainsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DomainsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DomainsTransport`` is the ABC for all transports. + +- public child ``DomainsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DomainsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDomainsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DomainsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py index d0c377799ba0..337bf3bb62c5 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py index be66deb6f02e..7f91bd1b4cd7 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py index 4f9a34e789ab..c23beafaf7ba 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py index ecc0fa7b1951..56b35f08899c 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py @@ -991,6 +991,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DomainsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index 19bf84808bb4..7792dcac8820 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-domains/setup.py b/packages/google-cloud-domains/setup.py index b2b058c897d0..d10dd1eae3eb 100644 --- a/packages/google-cloud-domains/setup.py +++ b/packages/google-cloud-domains/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-domains" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-domains/testing/constraints-3.7.txt b/packages/google-cloud-domains/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-domains/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-domains/testing/constraints-3.8.txt b/packages/google-cloud-domains/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-domains/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-domains/testing/constraints-3.9.txt b/packages/google-cloud-domains/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-domains/testing/constraints-3.9.txt +++ b/packages/google-cloud-domains/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py b/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py index 7bff3fed5300..7ed7394e1d32 100644 --- a/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py +++ b/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DomainsClient._get_default_mtls_endpoint(None) is None assert DomainsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DomainsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert DomainsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1223,11 +1225,13 @@ def test_domains_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10599,8 +10603,9 @@ def test_search_domains_rest_bad_request(request_type=domains.SearchDomainsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10658,17 +10663,19 @@ def test_search_domains_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_search_domains" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_search_domains_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_search_domains" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_search_domains" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_search_domains_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_search_domains" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10721,8 +10728,9 @@ def test_retrieve_register_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10780,18 +10788,20 @@ def test_retrieve_register_parameters_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_retrieve_register_parameters" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_retrieve_register_parameters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_retrieve_register_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_retrieve_register_parameters" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_retrieve_register_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_retrieve_register_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10847,8 +10857,9 @@ def test_register_domain_rest_bad_request(request_type=domains.RegisterDomainReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10903,19 +10914,20 @@ def test_register_domain_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_register_domain" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_register_domain_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_register_domain" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_register_domain" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_register_domain_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_register_domain" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10966,8 +10978,9 @@ def test_retrieve_transfer_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11025,18 +11038,20 @@ def test_retrieve_transfer_parameters_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_retrieve_transfer_parameters" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_retrieve_transfer_parameters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_retrieve_transfer_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_retrieve_transfer_parameters" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_retrieve_transfer_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_retrieve_transfer_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11092,8 +11107,9 @@ def test_transfer_domain_rest_bad_request(request_type=domains.TransferDomainReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11148,19 +11164,20 @@ def test_transfer_domain_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_transfer_domain" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_transfer_domain_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_transfer_domain" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_transfer_domain" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_transfer_domain_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_transfer_domain" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11211,8 +11228,9 @@ def test_list_registrations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11273,17 +11291,19 @@ def test_list_registrations_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_list_registrations" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_list_registrations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_list_registrations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_list_registrations" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_list_registrations_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_list_registrations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11336,8 +11356,9 @@ def test_get_registration_rest_bad_request(request_type=domains.GetRegistrationR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11406,17 +11427,19 @@ def test_get_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_get_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_get_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_get_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_get_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_get_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_get_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11471,8 +11494,9 @@ def test_update_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11664,19 +11688,20 @@ def test_update_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_update_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_update_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_update_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_update_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_update_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_update_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11731,8 +11756,9 @@ def test_configure_management_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11789,20 +11815,21 @@ def test_configure_management_settings_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_management_settings" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_configure_management_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_configure_management_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_configure_management_settings" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_configure_management_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_configure_management_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11857,8 +11884,9 @@ def test_configure_dns_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11915,19 +11943,21 @@ def test_configure_dns_settings_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_dns_settings" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_dns_settings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_configure_dns_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_configure_dns_settings" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_configure_dns_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_configure_dns_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11982,8 +12012,9 @@ def test_configure_contact_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12040,20 +12071,21 @@ def test_configure_contact_settings_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_contact_settings" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_configure_contact_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_configure_contact_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_configure_contact_settings" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_configure_contact_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_configure_contact_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12106,8 +12138,9 @@ def test_export_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12162,19 +12195,20 @@ def test_export_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_export_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_export_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_export_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_export_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_export_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_export_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12227,8 +12261,9 @@ def test_delete_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12283,19 +12318,20 @@ def test_delete_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_delete_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_delete_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_delete_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_delete_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_delete_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_delete_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12350,8 +12386,9 @@ def test_retrieve_authorization_code_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12414,18 +12451,20 @@ def test_retrieve_authorization_code_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_retrieve_authorization_code" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_retrieve_authorization_code_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_retrieve_authorization_code" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_retrieve_authorization_code" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_retrieve_authorization_code_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_retrieve_authorization_code" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12480,8 +12519,9 @@ def test_reset_authorization_code_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12544,17 +12584,20 @@ def test_reset_authorization_code_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_reset_authorization_code" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_reset_authorization_code_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_reset_authorization_code" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_reset_authorization_code" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_reset_authorization_code_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_reset_authorization_code" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13014,11 +13057,14 @@ def test_domains_base_transport(): def test_domains_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.domains_v1.services.domains.transports.DomainsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.domains_v1.services.domains.transports.DomainsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DomainsTransport( @@ -13035,9 +13081,12 @@ def test_domains_base_transport_with_credentials_file(): def test_domains_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.domains_v1.services.domains.transports.DomainsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.domains_v1.services.domains.transports.DomainsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DomainsTransport() @@ -13109,11 +13158,12 @@ def test_domains_transport_auth_gdch_credentials(transport_class): def test_domains_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py b/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py index a6e1443d214f..0d15b7e92269 100644 --- a/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py +++ b/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DomainsClient._get_default_mtls_endpoint(None) is None assert DomainsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert DomainsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert DomainsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1223,11 +1225,13 @@ def test_domains_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10599,8 +10603,9 @@ def test_search_domains_rest_bad_request(request_type=domains.SearchDomainsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10658,17 +10663,19 @@ def test_search_domains_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_search_domains" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_search_domains_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_search_domains" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_search_domains" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_search_domains_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_search_domains" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10721,8 +10728,9 @@ def test_retrieve_register_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10780,18 +10788,20 @@ def test_retrieve_register_parameters_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_retrieve_register_parameters" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_retrieve_register_parameters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_retrieve_register_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_retrieve_register_parameters" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_retrieve_register_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_retrieve_register_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10847,8 +10857,9 @@ def test_register_domain_rest_bad_request(request_type=domains.RegisterDomainReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10903,19 +10914,20 @@ def test_register_domain_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_register_domain" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_register_domain_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_register_domain" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_register_domain" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_register_domain_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_register_domain" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10966,8 +10978,9 @@ def test_retrieve_transfer_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11025,18 +11038,20 @@ def test_retrieve_transfer_parameters_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_retrieve_transfer_parameters" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_retrieve_transfer_parameters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_retrieve_transfer_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_retrieve_transfer_parameters" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_retrieve_transfer_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_retrieve_transfer_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11092,8 +11107,9 @@ def test_transfer_domain_rest_bad_request(request_type=domains.TransferDomainReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11148,19 +11164,20 @@ def test_transfer_domain_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_transfer_domain" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_transfer_domain_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_transfer_domain" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_transfer_domain" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_transfer_domain_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_transfer_domain" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11211,8 +11228,9 @@ def test_list_registrations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11273,17 +11291,19 @@ def test_list_registrations_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_list_registrations" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_list_registrations_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_list_registrations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_list_registrations" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_list_registrations_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_list_registrations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11336,8 +11356,9 @@ def test_get_registration_rest_bad_request(request_type=domains.GetRegistrationR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11406,17 +11427,19 @@ def test_get_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_get_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_get_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_get_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_get_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_get_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_get_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11471,8 +11494,9 @@ def test_update_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11664,19 +11688,20 @@ def test_update_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_update_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_update_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_update_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_update_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_update_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_update_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11731,8 +11756,9 @@ def test_configure_management_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11789,20 +11815,21 @@ def test_configure_management_settings_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_management_settings" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_configure_management_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_configure_management_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_configure_management_settings" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_configure_management_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_configure_management_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11857,8 +11884,9 @@ def test_configure_dns_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11915,19 +11943,21 @@ def test_configure_dns_settings_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_dns_settings" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_dns_settings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_configure_dns_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_configure_dns_settings" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_configure_dns_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_configure_dns_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11982,8 +12012,9 @@ def test_configure_contact_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12040,20 +12071,21 @@ def test_configure_contact_settings_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_configure_contact_settings" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_configure_contact_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_configure_contact_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_configure_contact_settings" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_configure_contact_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_configure_contact_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12106,8 +12138,9 @@ def test_export_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12162,19 +12195,20 @@ def test_export_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_export_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_export_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_export_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_export_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_export_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_export_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12227,8 +12261,9 @@ def test_delete_registration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12283,19 +12318,20 @@ def test_delete_registration_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DomainsRestInterceptor, "post_delete_registration" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_delete_registration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_delete_registration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DomainsRestInterceptor, "post_delete_registration" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, "post_delete_registration_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_delete_registration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12350,8 +12386,9 @@ def test_retrieve_authorization_code_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12414,18 +12451,20 @@ def test_retrieve_authorization_code_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_retrieve_authorization_code" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, - "post_retrieve_authorization_code_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_retrieve_authorization_code" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_retrieve_authorization_code" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_retrieve_authorization_code_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_retrieve_authorization_code" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12480,8 +12519,9 @@ def test_reset_authorization_code_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12544,17 +12584,20 @@ def test_reset_authorization_code_rest_interceptors(null_interceptor): ) client = DomainsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DomainsRestInterceptor, "post_reset_authorization_code" - ) as post, mock.patch.object( - transports.DomainsRestInterceptor, "post_reset_authorization_code_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DomainsRestInterceptor, "pre_reset_authorization_code" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DomainsRestInterceptor, "post_reset_authorization_code" + ) as post, + mock.patch.object( + transports.DomainsRestInterceptor, + "post_reset_authorization_code_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DomainsRestInterceptor, "pre_reset_authorization_code" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13014,11 +13057,14 @@ def test_domains_base_transport(): def test_domains_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.domains_v1beta1.services.domains.transports.DomainsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.domains_v1beta1.services.domains.transports.DomainsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DomainsTransport( @@ -13035,9 +13081,12 @@ def test_domains_base_transport_with_credentials_file(): def test_domains_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.domains_v1beta1.services.domains.transports.DomainsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.domains_v1beta1.services.domains.transports.DomainsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DomainsTransport() @@ -13109,11 +13158,12 @@ def test_domains_transport_auth_gdch_credentials(transport_class): def test_domains_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py index 61c989af0685..b5aa85aec205 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py @@ -210,7 +210,7 @@ def transport(self) -> EdgeContainerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2858,7 +2858,7 @@ async def sample_get_server_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2884,8 +2884,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2894,7 +2898,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2902,7 +2906,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2913,7 +2917,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2939,8 +2943,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2949,7 +2957,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2957,7 +2965,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2968,7 +2976,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2998,8 +3006,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3008,7 +3020,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3016,7 +3028,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3024,7 +3036,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3053,8 +3065,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3063,7 +3079,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3071,7 +3087,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3079,7 +3095,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3105,8 +3121,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3115,7 +3135,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3123,7 +3143,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3134,7 +3154,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3160,8 +3180,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3170,7 +3194,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3178,7 +3202,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py index 8085bc0f6bb0..b29edc586a0e 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py @@ -120,7 +120,7 @@ class EdgeContainerClient(metaclass=EdgeContainerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -563,7 +567,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -660,7 +664,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -756,7 +760,7 @@ def __init__( self._universe_domain = EdgeContainerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3347,7 +3351,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3373,8 +3377,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3383,7 +3391,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3392,7 +3400,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3406,7 +3414,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3432,8 +3440,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3442,7 +3454,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3451,7 +3463,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3465,7 +3477,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3495,8 +3507,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3505,7 +3521,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3513,7 +3529,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3521,7 +3537,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3550,8 +3566,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3560,7 +3580,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3568,7 +3588,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3576,7 +3596,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3602,8 +3622,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3612,7 +3636,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3621,7 +3645,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3635,7 +3659,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3661,8 +3685,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3671,7 +3699,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3680,7 +3708,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/README.rst b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/README.rst index aee887ff00b3..8e8a0bdda3be 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/README.rst +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EdgeContainerTransport` is the ABC for all transports. -- public child `EdgeContainerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EdgeContainerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEdgeContainerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EdgeContainerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EdgeContainerTransport`` is the ABC for all transports. + +- public child ``EdgeContainerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EdgeContainerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEdgeContainerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EdgeContainerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py index b705181f1a2b..f371cab637a3 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py index 22cc823d70cb..b39e45ee1c80 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py index a38434689122..27ca0f076a41 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py index 81d99c050534..89f1972c5b84 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py @@ -1388,6 +1388,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EdgeContainerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index cc2cf5ded17e..2ef954f4ced6 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-edgecontainer/setup.py b/packages/google-cloud-edgecontainer/setup.py index a927c60323ea..b34844d97b1f 100644 --- a/packages/google-cloud-edgecontainer/setup.py +++ b/packages/google-cloud-edgecontainer/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-edgecontainer" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-edgecontainer/testing/constraints-3.7.txt b/packages/google-cloud-edgecontainer/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-edgecontainer/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-edgecontainer/testing/constraints-3.8.txt b/packages/google-cloud-edgecontainer/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-edgecontainer/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-edgecontainer/testing/constraints-3.9.txt b/packages/google-cloud-edgecontainer/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-edgecontainer/testing/constraints-3.9.txt +++ b/packages/google-cloud-edgecontainer/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py b/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py index 45f28a143158..b73503bb150c 100644 --- a/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py +++ b/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EdgeContainerClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): assert ( EdgeContainerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EdgeContainerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_edge_container_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -14039,8 +14046,9 @@ def test_list_clusters_rest_bad_request(request_type=service.ListClustersRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14105,17 +14113,19 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_list_clusters_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14166,8 +14176,9 @@ def test_get_cluster_rest_bad_request(request_type=service.GetClusterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14260,17 +14271,19 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14319,8 +14332,9 @@ def test_create_cluster_rest_bad_request(request_type=service.CreateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14534,19 +14548,20 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_create_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14597,8 +14612,9 @@ def test_update_cluster_rest_bad_request(request_type=service.UpdateClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14814,19 +14830,20 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_update_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14875,8 +14892,9 @@ def test_upgrade_cluster_rest_bad_request(request_type=service.UpgradeClusterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14933,19 +14951,21 @@ def test_upgrade_cluster_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_upgrade_cluster" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_upgrade_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_upgrade_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_upgrade_cluster" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_upgrade_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_upgrade_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14994,8 +15014,9 @@ def test_delete_cluster_rest_bad_request(request_type=service.DeleteClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15052,19 +15073,20 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_delete_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15115,8 +15137,9 @@ def test_generate_access_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15179,18 +15202,20 @@ def test_generate_access_token_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_generate_access_token" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, - "post_generate_access_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_generate_access_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_generate_access_token" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_generate_access_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_generate_access_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15248,8 +15273,9 @@ def test_generate_offline_credential_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15316,18 +15342,20 @@ def test_generate_offline_credential_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_generate_offline_credential" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, - "post_generate_offline_credential_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_generate_offline_credential" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_generate_offline_credential" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_generate_offline_credential_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_generate_offline_credential" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15383,8 +15411,9 @@ def test_list_node_pools_rest_bad_request(request_type=service.ListNodePoolsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15449,17 +15478,20 @@ def test_list_node_pools_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_node_pools" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_node_pools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_list_node_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_list_node_pools" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_list_node_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_list_node_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15512,8 +15544,9 @@ def test_get_node_pool_rest_bad_request(request_type=service.GetNodePoolRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15586,17 +15619,19 @@ def test_get_node_pool_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_node_pool" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_get_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_node_pool" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_node_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_get_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15645,8 +15680,9 @@ def test_create_node_pool_rest_bad_request(request_type=service.CreateNodePoolRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15800,19 +15836,21 @@ def test_create_node_pool_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_create_node_pool" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_create_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_create_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_create_node_pool" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_create_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_create_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15865,8 +15903,9 @@ def test_update_node_pool_rest_bad_request(request_type=service.UpdateNodePoolRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16024,19 +16063,21 @@ def test_update_node_pool_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_update_node_pool" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_update_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_update_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_update_node_pool" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_update_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_update_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16087,8 +16128,9 @@ def test_delete_node_pool_rest_bad_request(request_type=service.DeleteNodePoolRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16147,19 +16189,21 @@ def test_delete_node_pool_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_delete_node_pool" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_delete_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_delete_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_delete_node_pool" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_delete_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_delete_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16208,8 +16252,9 @@ def test_list_machines_rest_bad_request(request_type=service.ListMachinesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16274,17 +16319,19 @@ def test_list_machines_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_machines" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_machines_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_list_machines" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_list_machines" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_list_machines_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_list_machines" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16335,8 +16382,9 @@ def test_get_machine_rest_bad_request(request_type=service.GetMachineRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16407,17 +16455,19 @@ def test_get_machine_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_machine" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_machine_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_get_machine" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_machine" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_machine_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_get_machine" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16468,8 +16518,9 @@ def test_list_vpn_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16534,18 +16585,20 @@ def test_list_vpn_connections_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_list_vpn_connections" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, - "post_list_vpn_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_list_vpn_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_list_vpn_connections" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_list_vpn_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_list_vpn_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16600,8 +16653,9 @@ def test_get_vpn_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16676,17 +16730,20 @@ def test_get_vpn_connection_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_vpn_connection" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_vpn_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_get_vpn_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_vpn_connection" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_get_vpn_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_get_vpn_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16739,8 +16796,9 @@ def test_create_vpn_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16886,20 +16944,21 @@ def test_create_vpn_connection_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_create_vpn_connection" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, - "post_create_vpn_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_create_vpn_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_create_vpn_connection" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_create_vpn_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_create_vpn_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16952,8 +17011,9 @@ def test_delete_vpn_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17010,20 +17070,21 @@ def test_delete_vpn_connection_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_delete_vpn_connection" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, - "post_delete_vpn_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_delete_vpn_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_delete_vpn_connection" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_delete_vpn_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_delete_vpn_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17076,8 +17137,9 @@ def test_get_server_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17140,17 +17202,20 @@ def test_get_server_config_rest_interceptors(null_interceptor): ) client = EdgeContainerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_server_config" - ) as post, mock.patch.object( - transports.EdgeContainerRestInterceptor, "post_get_server_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeContainerRestInterceptor, "pre_get_server_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "post_get_server_config" + ) as post, + mock.patch.object( + transports.EdgeContainerRestInterceptor, + "post_get_server_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeContainerRestInterceptor, "pre_get_server_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17201,8 +17266,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -17261,8 +17327,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -17323,8 +17390,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -17385,8 +17453,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -17447,8 +17516,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -17509,8 +17579,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18079,11 +18150,14 @@ def test_edge_container_base_transport(): def test_edge_container_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.edgecontainer_v1.services.edge_container.transports.EdgeContainerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.edgecontainer_v1.services.edge_container.transports.EdgeContainerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EdgeContainerTransport( @@ -18100,9 +18174,12 @@ def test_edge_container_base_transport_with_credentials_file(): def test_edge_container_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.edgecontainer_v1.services.edge_container.transports.EdgeContainerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.edgecontainer_v1.services.edge_container.transports.EdgeContainerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EdgeContainerTransport() @@ -18174,11 +18251,12 @@ def test_edge_container_transport_auth_gdch_credentials(transport_class): def test_edge_container_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -18976,6 +19054,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = EdgeContainerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = EdgeContainerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = EdgeContainerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19115,6 +19225,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EdgeContainerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EdgeContainerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EdgeContainerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19260,6 +19402,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EdgeContainerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EdgeContainerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EdgeContainerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19405,6 +19581,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EdgeContainerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EdgeContainerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EdgeContainerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19550,6 +19760,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EdgeContainerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EdgeContainerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EdgeContainerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19691,6 +19935,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EdgeContainerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EdgeContainerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EdgeContainerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py index 8e461f756b5c..fd18d1e8d862 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py @@ -209,7 +209,7 @@ def transport(self) -> EdgeNetworkTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3583,7 +3583,7 @@ async def sample_delete_router(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3609,8 +3609,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3619,7 +3623,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3627,7 +3631,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3638,7 +3642,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3664,8 +3668,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3674,7 +3682,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3682,7 +3690,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3693,7 +3701,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3723,8 +3731,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3733,7 +3745,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3741,7 +3753,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3749,7 +3761,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3778,8 +3790,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3788,7 +3804,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3796,7 +3812,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3804,7 +3820,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3830,8 +3846,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3840,7 +3860,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3848,7 +3868,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3859,7 +3879,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3885,8 +3905,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3895,7 +3919,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3903,7 +3927,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py index 852d8e1d296a..6aef3c0336e8 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py @@ -122,7 +122,7 @@ class EdgeNetworkClient(metaclass=EdgeNetworkClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -130,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -140,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -567,7 +571,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -664,7 +668,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -760,7 +764,7 @@ def __init__( self._universe_domain = EdgeNetworkClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4060,7 +4064,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4086,8 +4090,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4096,7 +4104,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4105,7 +4113,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4119,7 +4127,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4145,8 +4153,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4155,7 +4167,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4164,7 +4176,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4178,7 +4190,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4208,8 +4220,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4218,7 +4234,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4226,7 +4242,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4234,7 +4250,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4263,8 +4279,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4273,7 +4293,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4281,7 +4301,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4289,7 +4309,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4315,8 +4335,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4325,7 +4349,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4334,7 +4358,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4348,7 +4372,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4374,8 +4398,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4384,7 +4412,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4393,7 +4421,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/README.rst b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/README.rst index 1e83619458c3..875ed4fdaf04 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/README.rst +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EdgeNetworkTransport` is the ABC for all transports. -- public child `EdgeNetworkGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EdgeNetworkGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEdgeNetworkRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EdgeNetworkRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EdgeNetworkTransport`` is the ABC for all transports. + +- public child ``EdgeNetworkGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EdgeNetworkGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEdgeNetworkRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EdgeNetworkRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py index fb26eec3267a..47734af894fe 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py index 918f4473649c..8aebec246929 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py index 45abb2690189..71b3100860d7 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py index 907680a725f7..dcd10abff096 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py @@ -1720,6 +1720,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EdgeNetworkRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-edgenetwork/noxfile.py b/packages/google-cloud-edgenetwork/noxfile.py index 46277b41d993..715e39f33640 100644 --- a/packages/google-cloud-edgenetwork/noxfile.py +++ b/packages/google-cloud-edgenetwork/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-edgenetwork/setup.py b/packages/google-cloud-edgenetwork/setup.py index d505a7293b85..988e46c34f2f 100644 --- a/packages/google-cloud-edgenetwork/setup.py +++ b/packages/google-cloud-edgenetwork/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-edgenetwork" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-edgenetwork/testing/constraints-3.7.txt b/packages/google-cloud-edgenetwork/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-edgenetwork/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-edgenetwork/testing/constraints-3.8.txt b/packages/google-cloud-edgenetwork/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-edgenetwork/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-edgenetwork/testing/constraints-3.9.txt b/packages/google-cloud-edgenetwork/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-edgenetwork/testing/constraints-3.9.txt +++ b/packages/google-cloud-edgenetwork/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py b/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py index a7a15b409fcc..8f3f46254b68 100644 --- a/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py +++ b/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EdgeNetworkClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EdgeNetworkClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EdgeNetworkClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1252,11 +1256,13 @@ def test_edge_network_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -18036,8 +18042,9 @@ def test_initialize_zone_rest_bad_request(request_type=service.InitializeZoneReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18097,17 +18104,19 @@ def test_initialize_zone_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_initialize_zone" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_initialize_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_initialize_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_initialize_zone" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_initialize_zone_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_initialize_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18158,8 +18167,9 @@ def test_list_zones_rest_bad_request(request_type=service.ListZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18224,17 +18234,19 @@ def test_list_zones_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_zones" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_zones_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_list_zones" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_zones" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_zones_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_list_zones" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18283,8 +18295,9 @@ def test_get_zone_rest_bad_request(request_type=service.GetZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18349,17 +18362,17 @@ def test_get_zone_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_zone" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_get_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_zone" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_zone_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.EdgeNetworkRestInterceptor, "pre_get_zone") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18408,8 +18421,9 @@ def test_list_networks_rest_bad_request(request_type=service.ListNetworksRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18474,17 +18488,19 @@ def test_list_networks_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_networks" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_networks_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_list_networks" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_networks" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_networks_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_list_networks" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18537,8 +18553,9 @@ def test_get_network_rest_bad_request(request_type=service.GetNetworkRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18607,17 +18624,19 @@ def test_get_network_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_network" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_get_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_network" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_network_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_get_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18668,8 +18687,9 @@ def test_diagnose_network_rest_bad_request(request_type=service.DiagnoseNetworkR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18731,17 +18751,19 @@ def test_diagnose_network_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_diagnose_network" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_diagnose_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_diagnose_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_diagnose_network" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_diagnose_network_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_diagnose_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18792,8 +18814,9 @@ def test_create_network_rest_bad_request(request_type=service.CreateNetworkReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18925,19 +18948,20 @@ def test_create_network_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_network" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_create_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_network" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_network_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_create_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18988,8 +19012,9 @@ def test_delete_network_rest_bad_request(request_type=service.DeleteNetworkReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19048,19 +19073,20 @@ def test_delete_network_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_network" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_network_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_delete_network" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_network" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_network_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_delete_network" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19109,8 +19135,9 @@ def test_list_subnets_rest_bad_request(request_type=service.ListSubnetsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19175,17 +19202,19 @@ def test_list_subnets_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_subnets" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_subnets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_list_subnets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_subnets" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_subnets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_list_subnets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19238,8 +19267,9 @@ def test_get_subnet_rest_bad_request(request_type=service.GetSubnetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19318,17 +19348,19 @@ def test_get_subnet_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_subnet" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_subnet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_get_subnet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_subnet" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_subnet_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_get_subnet" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19377,8 +19409,9 @@ def test_create_subnet_rest_bad_request(request_type=service.CreateSubnetRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19515,19 +19548,20 @@ def test_create_subnet_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_subnet" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_subnet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_create_subnet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_subnet" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_subnet_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_create_subnet" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19580,8 +19614,9 @@ def test_update_subnet_rest_bad_request(request_type=service.UpdateSubnetRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19722,19 +19757,20 @@ def test_update_subnet_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_update_subnet" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_update_subnet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_update_subnet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_update_subnet" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_update_subnet_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_update_subnet" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19785,8 +19821,9 @@ def test_delete_subnet_rest_bad_request(request_type=service.DeleteSubnetRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19845,19 +19882,20 @@ def test_delete_subnet_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_subnet" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_subnet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_delete_subnet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_subnet" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_subnet_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_delete_subnet" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19908,8 +19946,9 @@ def test_list_interconnects_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19974,17 +20013,20 @@ def test_list_interconnects_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_interconnects" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_interconnects_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_list_interconnects" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_interconnects" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, + "post_list_interconnects_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_list_interconnects" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20039,8 +20081,9 @@ def test_get_interconnect_rest_bad_request(request_type=service.GetInterconnectR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20122,17 +20165,19 @@ def test_get_interconnect_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_interconnect" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_interconnect_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_get_interconnect" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_interconnect" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_interconnect_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_get_interconnect" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20185,8 +20230,9 @@ def test_diagnose_interconnect_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20248,18 +20294,20 @@ def test_diagnose_interconnect_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_diagnose_interconnect" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, - "post_diagnose_interconnect_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_diagnose_interconnect" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_diagnose_interconnect" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, + "post_diagnose_interconnect_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_diagnose_interconnect" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20317,8 +20365,9 @@ def test_list_interconnect_attachments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20383,18 +20432,20 @@ def test_list_interconnect_attachments_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_interconnect_attachments" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, - "post_list_interconnect_attachments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_list_interconnect_attachments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_interconnect_attachments" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, + "post_list_interconnect_attachments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_list_interconnect_attachments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20454,8 +20505,9 @@ def test_get_interconnect_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20537,18 +20589,20 @@ def test_get_interconnect_attachment_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_interconnect_attachment" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, - "post_get_interconnect_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_get_interconnect_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_interconnect_attachment" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, + "post_get_interconnect_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_get_interconnect_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20603,8 +20657,9 @@ def test_create_interconnect_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20745,20 +20800,21 @@ def test_create_interconnect_attachment_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_interconnect_attachment" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, - "post_create_interconnect_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_create_interconnect_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_interconnect_attachment" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, + "post_create_interconnect_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_create_interconnect_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20813,8 +20869,9 @@ def test_delete_interconnect_attachment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20873,20 +20930,21 @@ def test_delete_interconnect_attachment_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_interconnect_attachment" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, - "post_delete_interconnect_attachment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_delete_interconnect_attachment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_interconnect_attachment" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, + "post_delete_interconnect_attachment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_delete_interconnect_attachment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20937,8 +20995,9 @@ def test_list_routers_rest_bad_request(request_type=service.ListRoutersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21003,17 +21062,19 @@ def test_list_routers_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_routers" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_list_routers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_list_routers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_routers" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_list_routers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_list_routers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21066,8 +21127,9 @@ def test_get_router_rest_bad_request(request_type=service.GetRouterRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21140,17 +21202,19 @@ def test_get_router_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_router" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_get_router_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_get_router" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_router" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_get_router_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_get_router" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21201,8 +21265,9 @@ def test_diagnose_router_rest_bad_request(request_type=service.DiagnoseRouterReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21264,17 +21329,19 @@ def test_diagnose_router_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_diagnose_router" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_diagnose_router_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_diagnose_router" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_diagnose_router" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_diagnose_router_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_diagnose_router" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21325,8 +21392,9 @@ def test_create_router_rest_bad_request(request_type=service.CreateRouterRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21489,19 +21557,20 @@ def test_create_router_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_router" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_create_router_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_create_router" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_router" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_create_router_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_create_router" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21554,8 +21623,9 @@ def test_update_router_rest_bad_request(request_type=service.UpdateRouterRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21722,19 +21792,20 @@ def test_update_router_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_update_router" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_update_router_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_update_router" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_update_router" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_update_router_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_update_router" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21785,8 +21856,9 @@ def test_delete_router_rest_bad_request(request_type=service.DeleteRouterRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21845,19 +21917,20 @@ def test_delete_router_rest_interceptors(null_interceptor): ) client = EdgeNetworkClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_router" - ) as post, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "post_delete_router_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EdgeNetworkRestInterceptor, "pre_delete_router" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_router" + ) as post, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "post_delete_router_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EdgeNetworkRestInterceptor, "pre_delete_router" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21908,8 +21981,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21968,8 +22042,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22030,8 +22105,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22092,8 +22168,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22154,8 +22231,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22216,8 +22294,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -22910,11 +22989,14 @@ def test_edge_network_base_transport(): def test_edge_network_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.edgenetwork_v1.services.edge_network.transports.EdgeNetworkTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.edgenetwork_v1.services.edge_network.transports.EdgeNetworkTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EdgeNetworkTransport( @@ -22931,9 +23013,12 @@ def test_edge_network_base_transport_with_credentials_file(): def test_edge_network_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.edgenetwork_v1.services.edge_network.transports.EdgeNetworkTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.edgenetwork_v1.services.edge_network.transports.EdgeNetworkTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EdgeNetworkTransport() @@ -23005,11 +23090,12 @@ def test_edge_network_transport_auth_gdch_credentials(transport_class): def test_edge_network_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -23821,6 +23907,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = EdgeNetworkClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = EdgeNetworkAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = EdgeNetworkClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23960,6 +24078,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EdgeNetworkClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EdgeNetworkAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EdgeNetworkClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24105,6 +24255,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EdgeNetworkClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EdgeNetworkAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EdgeNetworkClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24250,6 +24434,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EdgeNetworkClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EdgeNetworkAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EdgeNetworkClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24395,6 +24613,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EdgeNetworkClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EdgeNetworkAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EdgeNetworkClient( credentials=ga_credentials.AnonymousCredentials(), @@ -24536,6 +24788,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EdgeNetworkClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EdgeNetworkAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = EdgeNetworkClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py index 2a5c91db0390..3a63e5c1e717 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py @@ -233,7 +233,7 @@ def transport(self) -> EnterpriseKnowledgeGraphServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py index 294603fee687..004143d1c384 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py @@ -123,7 +123,7 @@ class EnterpriseKnowledgeGraphServiceClient( """APIs for enterprise knowledge graph product.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -535,7 +539,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -634,7 +638,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -738,7 +742,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/README.rst b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/README.rst index 11cffd768122..8b9ad00a1362 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/README.rst +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EnterpriseKnowledgeGraphServiceTransport` is the ABC for all transports. -- public child `EnterpriseKnowledgeGraphServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EnterpriseKnowledgeGraphServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEnterpriseKnowledgeGraphServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EnterpriseKnowledgeGraphServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EnterpriseKnowledgeGraphServiceTransport`` is the ABC for all transports. + +- public child ``EnterpriseKnowledgeGraphServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EnterpriseKnowledgeGraphServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEnterpriseKnowledgeGraphServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EnterpriseKnowledgeGraphServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py index e6bb1a2e2d32..dc36c15f065c 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py index d7f889bcaf58..fb9564a38a78 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py index 46910f13641f..824c4ab42180 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py index 73fa16b562f7..f6573731d455 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py @@ -577,6 +577,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EnterpriseKnowledgeGraphServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index 4e68c5c8f9a0..a95a33b91590 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-enterpriseknowledgegraph/setup.py b/packages/google-cloud-enterpriseknowledgegraph/setup.py index 0a1ed591c527..b1d1b0a578de 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/setup.py +++ b/packages/google-cloud-enterpriseknowledgegraph/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-enterpriseknowledgegraph" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.7.txt b/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.8.txt b/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.9.txt b/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.9.txt +++ b/packages/google-cloud-enterpriseknowledgegraph/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py b/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py index b7f9606f2c3f..d9db5a4053f1 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py +++ b/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( EnterpriseKnowledgeGraphServiceClient._get_default_mtls_endpoint(None) is None @@ -155,6 +156,12 @@ def test__get_default_mtls_endpoint(): EnterpriseKnowledgeGraphServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1418,11 +1425,13 @@ def test_enterprise_knowledge_graph_service_client_create_channel_credentials_fi ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7136,8 +7145,9 @@ def test_create_entity_reconciliation_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7309,20 +7319,22 @@ def test_create_entity_reconciliation_job_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_create_entity_reconciliation_job", - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_create_entity_reconciliation_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_create_entity_reconciliation_job", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_create_entity_reconciliation_job", + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_create_entity_reconciliation_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_create_entity_reconciliation_job", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7379,8 +7391,9 @@ def test_get_entity_reconciliation_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7447,20 +7460,22 @@ def test_get_entity_reconciliation_job_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_get_entity_reconciliation_job", - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_get_entity_reconciliation_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_get_entity_reconciliation_job", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_get_entity_reconciliation_job", + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_get_entity_reconciliation_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_get_entity_reconciliation_job", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7515,8 +7530,9 @@ def test_list_entity_reconciliation_jobs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7579,20 +7595,22 @@ def test_list_entity_reconciliation_jobs_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_list_entity_reconciliation_jobs", - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_list_entity_reconciliation_jobs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_list_entity_reconciliation_jobs", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_list_entity_reconciliation_jobs", + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_list_entity_reconciliation_jobs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_list_entity_reconciliation_jobs", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7652,8 +7670,9 @@ def test_cancel_entity_reconciliation_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7712,14 +7731,14 @@ def test_cancel_entity_reconciliation_job_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_cancel_entity_reconciliation_job", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_cancel_entity_reconciliation_job", + ) as pre, + ): pre.assert_not_called() pb_message = service.CancelEntityReconciliationJobRequest.pb( service.CancelEntityReconciliationJobRequest() @@ -7766,8 +7785,9 @@ def test_delete_entity_reconciliation_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7826,14 +7846,14 @@ def test_delete_entity_reconciliation_job_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_delete_entity_reconciliation_job", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_delete_entity_reconciliation_job", + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteEntityReconciliationJobRequest.pb( service.DeleteEntityReconciliationJobRequest() @@ -7876,8 +7896,9 @@ def test_lookup_rest_bad_request(request_type=service.LookupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7937,18 +7958,20 @@ def test_lookup_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "post_lookup" - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_lookup_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "pre_lookup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "post_lookup" + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_lookup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "pre_lookup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7997,8 +8020,9 @@ def test_search_rest_bad_request(request_type=service.SearchRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8058,18 +8082,20 @@ def test_search_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "post_search" - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_search_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "pre_search" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "post_search" + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_search_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, "pre_search" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8118,8 +8144,9 @@ def test_lookup_public_kg_rest_bad_request(request_type=service.LookupPublicKgRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8179,20 +8206,22 @@ def test_lookup_public_kg_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_lookup_public_kg", - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_lookup_public_kg_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_lookup_public_kg", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_lookup_public_kg", + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_lookup_public_kg_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_lookup_public_kg", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8243,8 +8272,9 @@ def test_search_public_kg_rest_bad_request(request_type=service.SearchPublicKgRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8304,20 +8334,22 @@ def test_search_public_kg_rest_interceptors(null_interceptor): ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_search_public_kg", - ) as post, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "post_search_public_kg_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EnterpriseKnowledgeGraphServiceRestInterceptor, - "pre_search_public_kg", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_search_public_kg", + ) as post, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "post_search_public_kg_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EnterpriseKnowledgeGraphServiceRestInterceptor, + "pre_search_public_kg", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8617,11 +8649,14 @@ def test_enterprise_knowledge_graph_service_base_transport(): def test_enterprise_knowledge_graph_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.enterpriseknowledgegraph_v1.services.enterprise_knowledge_graph_service.transports.EnterpriseKnowledgeGraphServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.enterpriseknowledgegraph_v1.services.enterprise_knowledge_graph_service.transports.EnterpriseKnowledgeGraphServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnterpriseKnowledgeGraphServiceTransport( @@ -8638,9 +8673,12 @@ def test_enterprise_knowledge_graph_service_base_transport_with_credentials_file def test_enterprise_knowledge_graph_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.enterpriseknowledgegraph_v1.services.enterprise_knowledge_graph_service.transports.EnterpriseKnowledgeGraphServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.enterpriseknowledgegraph_v1.services.enterprise_knowledge_graph_service.transports.EnterpriseKnowledgeGraphServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EnterpriseKnowledgeGraphServiceTransport() @@ -8719,11 +8757,12 @@ def test_enterprise_knowledge_graph_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/async_client.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/async_client.py index 796b449a74d2..51eb849a8f7d 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/async_client.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/async_client.py @@ -186,7 +186,7 @@ def transport(self) -> ErrorGroupServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/client.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/client.py index 26331f36a2d1..9699fe316a40 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/client.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/client.py @@ -108,7 +108,7 @@ class ErrorGroupServiceClient(metaclass=ErrorGroupServiceClientMeta): """Service for retrieving and updating individual error groups.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -428,7 +432,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -525,7 +529,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -625,7 +629,7 @@ def __init__( self._universe_domain = ErrorGroupServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/README.rst b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/README.rst index a0b01808f7b7..7dee1e8e50c2 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/README.rst +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ErrorGroupServiceTransport` is the ABC for all transports. -- public child `ErrorGroupServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ErrorGroupServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseErrorGroupServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ErrorGroupServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ErrorGroupServiceTransport`` is the ABC for all transports. + +- public child ``ErrorGroupServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ErrorGroupServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseErrorGroupServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ErrorGroupServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/base.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/base.py index 16096edd47d0..3e531eca1c6e 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/base.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py index c21d435029fd..489f2f412d2c 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc_asyncio.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc_asyncio.py index ed0256325930..61609aa3f6bd 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/rest.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/rest.py index 68b1770f8db0..985cc0babb84 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/rest.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/rest.py @@ -253,6 +253,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ErrorGroupServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/async_client.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/async_client.py index 586e76e2e706..dd561be38ef0 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/async_client.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/async_client.py @@ -189,7 +189,7 @@ def transport(self) -> ErrorStatsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py index b7b1703576e5..8022d775d583 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py @@ -111,7 +111,7 @@ class ErrorStatsServiceClient(metaclass=ErrorStatsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -431,7 +435,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = ErrorStatsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/README.rst b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/README.rst index 9fb4cf06a773..b9bdd45046e7 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/README.rst +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ErrorStatsServiceTransport` is the ABC for all transports. -- public child `ErrorStatsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ErrorStatsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseErrorStatsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ErrorStatsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ErrorStatsServiceTransport`` is the ABC for all transports. + +- public child ``ErrorStatsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ErrorStatsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseErrorStatsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ErrorStatsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/base.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/base.py index 1c2b126d6191..d6db19449bb8 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/base.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc.py index 7490e9195fcb..72389e7d152d 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc_asyncio.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc_asyncio.py index 0cb1543f69d2..e86ecdc81643 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/rest.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/rest.py index 408ca8eab51e..8d49cc9da3fb 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/rest.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/rest.py @@ -323,6 +323,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ErrorStatsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/async_client.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/async_client.py index b1a6c42eb437..6a747db8bd56 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/async_client.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> ReportErrorsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/client.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/client.py index ad92a08f508b..6619bf3b5e74 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/client.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/client.py @@ -108,7 +108,7 @@ class ReportErrorsServiceClient(metaclass=ReportErrorsServiceClientMeta): """An API for reporting error events.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -116,7 +116,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -126,6 +126,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -411,7 +415,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -508,7 +512,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = ReportErrorsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/README.rst b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/README.rst index d70e90101f33..c37514f6149f 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/README.rst +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ReportErrorsServiceTransport` is the ABC for all transports. -- public child `ReportErrorsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ReportErrorsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseReportErrorsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ReportErrorsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ReportErrorsServiceTransport`` is the ABC for all transports. + +- public child ``ReportErrorsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ReportErrorsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseReportErrorsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ReportErrorsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/base.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/base.py index db99703a2e93..ccacee36f3d1 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/base.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc.py index c3bda2643502..c0a850f9a6fc 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc_asyncio.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc_asyncio.py index 6a5a055f1f11..91e53b1d0e84 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/rest.py b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/rest.py index 2465644287eb..017f27fd6575 100644 --- a/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/rest.py +++ b/packages/google-cloud-error-reporting/google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/rest.py @@ -205,6 +205,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ReportErrorsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-error-reporting/noxfile.py b/packages/google-cloud-error-reporting/noxfile.py index 4af2fb23c527..d215b64ec2d2 100644 --- a/packages/google-cloud-error-reporting/noxfile.py +++ b/packages/google-cloud-error-reporting/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,9 @@ def mypy(session): "mypy", "-p", "google", + # TODO(https://github.com/googleapis/google-cloud-python/issues/16083) + # "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +299,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +532,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +627,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-error-reporting/setup.py b/packages/google-cloud-error-reporting/setup.py index 2db1775432a4..e4e198d0b127 100644 --- a/packages/google-cloud-error-reporting/setup.py +++ b/packages/google-cloud-error-reporting/setup.py @@ -41,16 +41,16 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "google-cloud-logging>=1.14.0, <4.0.0", + "google-cloud-logging>=1.15.2, <4.0.0", "grpcio >= 1.33.2, < 2.0.0", "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-error-reporting" @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-error-reporting/testing/constraints-3.7.txt b/packages/google-cloud-error-reporting/testing/constraints-3.7.txt deleted file mode 100644 index 156c3335e183..000000000000 --- a/packages/google-cloud-error-reporting/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-cloud-logging==1.14.0 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-error-reporting/testing/constraints-3.8.txt b/packages/google-cloud-error-reporting/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-error-reporting/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-error-reporting/testing/constraints-3.9.txt b/packages/google-cloud-error-reporting/testing/constraints-3.9.txt index 7599dea499ed..c387d3b12832 100644 --- a/packages/google-cloud-error-reporting/testing/constraints-3.9.txt +++ b/packages/google-cloud-error-reporting/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-cloud-logging==1.15.2 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_group_service.py b/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_group_service.py index 94b75b44160a..4a450567f334 100644 --- a/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_group_service.py +++ b/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_group_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ErrorGroupServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,10 @@ def test__get_default_mtls_endpoint(): ErrorGroupServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ErrorGroupServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1317,11 +1322,13 @@ def test_error_group_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2577,8 +2584,9 @@ def test_get_group_rest_bad_request(request_type=error_group_service.GetGroupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2645,17 +2653,19 @@ def test_get_group_rest_interceptors(null_interceptor): ) client = ErrorGroupServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ErrorGroupServiceRestInterceptor, "post_get_group" - ) as post, mock.patch.object( - transports.ErrorGroupServiceRestInterceptor, "post_get_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ErrorGroupServiceRestInterceptor, "pre_get_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ErrorGroupServiceRestInterceptor, "post_get_group" + ) as post, + mock.patch.object( + transports.ErrorGroupServiceRestInterceptor, "post_get_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ErrorGroupServiceRestInterceptor, "pre_get_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2708,8 +2718,9 @@ def test_update_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2849,17 +2860,20 @@ def test_update_group_rest_interceptors(null_interceptor): ) client = ErrorGroupServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ErrorGroupServiceRestInterceptor, "post_update_group" - ) as post, mock.patch.object( - transports.ErrorGroupServiceRestInterceptor, "post_update_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ErrorGroupServiceRestInterceptor, "pre_update_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ErrorGroupServiceRestInterceptor, "post_update_group" + ) as post, + mock.patch.object( + transports.ErrorGroupServiceRestInterceptor, + "post_update_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ErrorGroupServiceRestInterceptor, "pre_update_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3002,11 +3016,14 @@ def test_error_group_service_base_transport(): def test_error_group_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.errorreporting_v1beta1.services.error_group_service.transports.ErrorGroupServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.errorreporting_v1beta1.services.error_group_service.transports.ErrorGroupServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ErrorGroupServiceTransport( @@ -3023,9 +3040,12 @@ def test_error_group_service_base_transport_with_credentials_file(): def test_error_group_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.errorreporting_v1beta1.services.error_group_service.transports.ErrorGroupServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.errorreporting_v1beta1.services.error_group_service.transports.ErrorGroupServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ErrorGroupServiceTransport() @@ -3097,11 +3117,12 @@ def test_error_group_service_transport_auth_gdch_credentials(transport_class): def test_error_group_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_stats_service.py b/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_stats_service.py index bdd240c6f7b8..384ad3cb91f6 100644 --- a/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_stats_service.py +++ b/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_error_stats_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ErrorStatsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): ErrorStatsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ErrorStatsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1320,11 +1325,13 @@ def test_error_stats_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3756,8 +3763,9 @@ def test_list_group_stats_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3820,18 +3828,20 @@ def test_list_group_stats_rest_interceptors(null_interceptor): ) client = ErrorStatsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "post_list_group_stats" - ) as post, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, - "post_list_group_stats_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "pre_list_group_stats" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, "post_list_group_stats" + ) as post, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, + "post_list_group_stats_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, "pre_list_group_stats" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3889,8 +3899,9 @@ def test_list_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3953,17 +3964,20 @@ def test_list_events_rest_interceptors(null_interceptor): ) client = ErrorStatsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "post_list_events" - ) as post, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "post_list_events_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "pre_list_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, "post_list_events" + ) as post, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, + "post_list_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, "pre_list_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4021,8 +4035,9 @@ def test_delete_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4082,17 +4097,20 @@ def test_delete_events_rest_interceptors(null_interceptor): ) client = ErrorStatsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "post_delete_events" - ) as post, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "post_delete_events_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ErrorStatsServiceRestInterceptor, "pre_delete_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, "post_delete_events" + ) as post, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, + "post_delete_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ErrorStatsServiceRestInterceptor, "pre_delete_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4261,11 +4279,14 @@ def test_error_stats_service_base_transport(): def test_error_stats_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.errorreporting_v1beta1.services.error_stats_service.transports.ErrorStatsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.errorreporting_v1beta1.services.error_stats_service.transports.ErrorStatsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ErrorStatsServiceTransport( @@ -4282,9 +4303,12 @@ def test_error_stats_service_base_transport_with_credentials_file(): def test_error_stats_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.errorreporting_v1beta1.services.error_stats_service.transports.ErrorStatsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.errorreporting_v1beta1.services.error_stats_service.transports.ErrorStatsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ErrorStatsServiceTransport() @@ -4356,11 +4380,12 @@ def test_error_stats_service_transport_auth_gdch_credentials(transport_class): def test_error_stats_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_report_errors_service.py b/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_report_errors_service.py index e2941ee7408a..0dfb0c49eefa 100644 --- a/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_report_errors_service.py +++ b/packages/google-cloud-error-reporting/tests/unit/gapic/errorreporting_v1beta1/test_report_errors_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ReportErrorsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): ReportErrorsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ReportErrorsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1340,11 +1345,13 @@ def test_report_errors_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2111,8 +2118,9 @@ def test_report_error_event_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2264,18 +2272,20 @@ def test_report_error_event_rest_interceptors(null_interceptor): ) client = ReportErrorsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ReportErrorsServiceRestInterceptor, "post_report_error_event" - ) as post, mock.patch.object( - transports.ReportErrorsServiceRestInterceptor, - "post_report_error_event_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ReportErrorsServiceRestInterceptor, "pre_report_error_event" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ReportErrorsServiceRestInterceptor, "post_report_error_event" + ) as post, + mock.patch.object( + transports.ReportErrorsServiceRestInterceptor, + "post_report_error_event_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ReportErrorsServiceRestInterceptor, "pre_report_error_event" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2402,11 +2412,14 @@ def test_report_errors_service_base_transport(): def test_report_errors_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.errorreporting_v1beta1.services.report_errors_service.transports.ReportErrorsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.errorreporting_v1beta1.services.report_errors_service.transports.ReportErrorsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReportErrorsServiceTransport( @@ -2423,9 +2436,12 @@ def test_report_errors_service_base_transport_with_credentials_file(): def test_report_errors_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.errorreporting_v1beta1.services.report_errors_service.transports.ReportErrorsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.errorreporting_v1beta1.services.report_errors_service.transports.ReportErrorsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ReportErrorsServiceTransport() @@ -2497,11 +2513,12 @@ def test_report_errors_service_transport_auth_gdch_credentials(transport_class): def test_report_errors_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py index a87aa9326e4a..4bf83ac989d0 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> EssentialContactsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py index 9143bae26d8e..e477f74dfcc5 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py @@ -114,7 +114,7 @@ class EssentialContactsServiceClient(metaclass=EssentialContactsServiceClientMet """Manages contacts for important Google Cloud notifications.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -434,7 +438,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -533,7 +537,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -635,7 +639,7 @@ def __init__( self._universe_domain = EssentialContactsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/README.rst b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/README.rst index b808ec390f56..c697338cc563 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/README.rst +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EssentialContactsServiceTransport` is the ABC for all transports. -- public child `EssentialContactsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EssentialContactsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEssentialContactsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EssentialContactsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EssentialContactsServiceTransport`` is the ABC for all transports. + +- public child ``EssentialContactsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EssentialContactsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEssentialContactsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EssentialContactsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py index 1d7320da49ee..82f09ae4eaa7 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py index 4d76b4fd1d72..7099d2825f8f 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py index 51283d9a8365..26eff88c302c 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py index 2df2a91b79cb..2a510242496a 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py @@ -444,6 +444,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EssentialContactsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index 5eab379ed99f..41615e10b813 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-essential-contacts/setup.py b/packages/google-cloud-essential-contacts/setup.py index 458f93f2b76f..f7d7f8cab3e3 100644 --- a/packages/google-cloud-essential-contacts/setup.py +++ b/packages/google-cloud-essential-contacts/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-essential-contacts" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-essential-contacts/testing/constraints-3.7.txt b/packages/google-cloud-essential-contacts/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-essential-contacts/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-essential-contacts/testing/constraints-3.8.txt b/packages/google-cloud-essential-contacts/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-essential-contacts/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-essential-contacts/testing/constraints-3.9.txt b/packages/google-cloud-essential-contacts/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-essential-contacts/testing/constraints-3.9.txt +++ b/packages/google-cloud-essential-contacts/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py b/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py index 38135e902dcb..be7b8cc89f5e 100644 --- a/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py +++ b/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EssentialContactsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): EssentialContactsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + EssentialContactsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1354,11 +1359,13 @@ def test_essential_contacts_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5691,8 +5698,9 @@ def test_create_contact_rest_bad_request(request_type=service.CreateContactReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5840,18 +5848,20 @@ def test_create_contact_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "post_create_contact" - ) as post, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, - "post_create_contact_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_create_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "post_create_contact" + ) as post, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, + "post_create_contact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_create_contact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5900,8 +5910,9 @@ def test_update_contact_rest_bad_request(request_type=service.UpdateContactReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6049,18 +6060,20 @@ def test_update_contact_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "post_update_contact" - ) as post, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, - "post_update_contact_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_update_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "post_update_contact" + ) as post, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, + "post_update_contact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_update_contact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6109,8 +6122,9 @@ def test_list_contacts_rest_bad_request(request_type=service.ListContactsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6173,18 +6187,20 @@ def test_list_contacts_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "post_list_contacts" - ) as post, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, - "post_list_contacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_list_contacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "post_list_contacts" + ) as post, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, + "post_list_contacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_list_contacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6235,8 +6251,9 @@ def test_get_contact_rest_bad_request(request_type=service.GetContactRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6309,18 +6326,20 @@ def test_get_contact_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "post_get_contact" - ) as post, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, - "post_get_contact_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_get_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "post_get_contact" + ) as post, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, + "post_get_contact_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_get_contact" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6369,8 +6388,9 @@ def test_delete_contact_rest_bad_request(request_type=service.DeleteContactReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6427,13 +6447,13 @@ def test_delete_contact_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_delete_contact" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_delete_contact" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteContactRequest.pb(service.DeleteContactRequest()) transcode.return_value = { @@ -6474,8 +6494,9 @@ def test_compute_contacts_rest_bad_request(request_type=service.ComputeContactsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6538,18 +6559,20 @@ def test_compute_contacts_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "post_compute_contacts" - ) as post, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, - "post_compute_contacts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_compute_contacts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "post_compute_contacts" + ) as post, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, + "post_compute_contacts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_compute_contacts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6602,8 +6625,9 @@ def test_send_test_message_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6660,13 +6684,13 @@ def test_send_test_message_rest_interceptors(null_interceptor): ) client = EssentialContactsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EssentialContactsServiceRestInterceptor, "pre_send_test_message" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EssentialContactsServiceRestInterceptor, "pre_send_test_message" + ) as pre, + ): pre.assert_not_called() pb_message = service.SendTestMessageRequest.pb(service.SendTestMessageRequest()) transcode.return_value = { @@ -6906,11 +6930,14 @@ def test_essential_contacts_service_base_transport(): def test_essential_contacts_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.essential_contacts_v1.services.essential_contacts_service.transports.EssentialContactsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.essential_contacts_v1.services.essential_contacts_service.transports.EssentialContactsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EssentialContactsServiceTransport( @@ -6927,9 +6954,12 @@ def test_essential_contacts_service_base_transport_with_credentials_file(): def test_essential_contacts_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.essential_contacts_v1.services.essential_contacts_service.transports.EssentialContactsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.essential_contacts_v1.services.essential_contacts_service.transports.EssentialContactsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EssentialContactsServiceTransport() @@ -7003,11 +7033,12 @@ def test_essential_contacts_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py index 742ea0e7cacf..454c8304b3cc 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> PublisherTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py index 6a577577f19d..d6bad61b5698 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py @@ -143,7 +143,7 @@ class PublisherClient(metaclass=PublisherClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -151,7 +151,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -161,6 +161,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -446,7 +450,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -543,7 +547,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -639,7 +643,7 @@ def __init__( self._universe_domain = PublisherClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/README.rst b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/README.rst index 489748f4d996..058642d5672a 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/README.rst +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PublisherTransport` is the ABC for all transports. -- public child `PublisherGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PublisherGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePublisherRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PublisherRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PublisherTransport`` is the ABC for all transports. + +- public child ``PublisherGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PublisherGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePublisherRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PublisherRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py index 3197b0dd9238..ce227c19abf8 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py index 4661831a78ff..635c06c3f378 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -218,6 +218,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py index 73d026b28be4..2dfc2ffdea00 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -269,6 +269,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py index 54b67ab78671..f0f560979e7c 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py @@ -349,6 +349,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PublisherRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index 492d54900f4a..81078a93d443 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-eventarc-publishing/setup.py b/packages/google-cloud-eventarc-publishing/setup.py index fc1ab9055a71..3ea3c6080214 100644 --- a/packages/google-cloud-eventarc-publishing/setup.py +++ b/packages/google-cloud-eventarc-publishing/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-eventarc-publishing" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-eventarc-publishing/testing/constraints-3.7.txt b/packages/google-cloud-eventarc-publishing/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-eventarc-publishing/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-eventarc-publishing/testing/constraints-3.8.txt b/packages/google-cloud-eventarc-publishing/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-eventarc-publishing/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-eventarc-publishing/testing/constraints-3.9.txt b/packages/google-cloud-eventarc-publishing/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-eventarc-publishing/testing/constraints-3.9.txt +++ b/packages/google-cloud-eventarc-publishing/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py b/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py index 031cb04bc9c1..bc9541780add 100644 --- a/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py +++ b/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PublisherClient._get_default_mtls_endpoint(None) is None assert PublisherClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -136,6 +137,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PublisherClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + PublisherClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1236,11 +1240,13 @@ def test_publisher_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2461,8 +2467,9 @@ def test_publish_channel_connection_events_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2522,18 +2529,21 @@ def test_publish_channel_connection_events_rest_interceptors(null_interceptor): ) client = PublisherClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublisherRestInterceptor, "post_publish_channel_connection_events" - ) as post, mock.patch.object( - transports.PublisherRestInterceptor, - "post_publish_channel_connection_events_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PublisherRestInterceptor, "pre_publish_channel_connection_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublisherRestInterceptor, + "post_publish_channel_connection_events", + ) as post, + mock.patch.object( + transports.PublisherRestInterceptor, + "post_publish_channel_connection_events_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PublisherRestInterceptor, "pre_publish_channel_connection_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2589,8 +2599,9 @@ def test_publish_events_rest_bad_request(request_type=publisher.PublishEventsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2648,17 +2659,19 @@ def test_publish_events_rest_interceptors(null_interceptor): ) client = PublisherClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublisherRestInterceptor, "post_publish_events" - ) as post, mock.patch.object( - transports.PublisherRestInterceptor, "post_publish_events_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublisherRestInterceptor, "pre_publish_events" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PublisherRestInterceptor, "post_publish_events" + ) as post, + mock.patch.object( + transports.PublisherRestInterceptor, "post_publish_events_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PublisherRestInterceptor, "pre_publish_events" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2711,8 +2724,9 @@ def test_publish_rest_bad_request(request_type=publisher.PublishRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2772,17 +2786,15 @@ def test_publish_rest_interceptors(null_interceptor): ) client = PublisherClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PublisherRestInterceptor, "post_publish" - ) as post, mock.patch.object( - transports.PublisherRestInterceptor, "post_publish_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PublisherRestInterceptor, "pre_publish" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.PublisherRestInterceptor, "post_publish") as post, + mock.patch.object( + transports.PublisherRestInterceptor, "post_publish_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PublisherRestInterceptor, "pre_publish") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2946,11 +2958,14 @@ def test_publisher_base_transport(): def test_publisher_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.eventarc_publishing_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.eventarc_publishing_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublisherTransport( @@ -2967,9 +2982,12 @@ def test_publisher_base_transport_with_credentials_file(): def test_publisher_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.eventarc_publishing_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.eventarc_publishing_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PublisherTransport() @@ -3041,11 +3059,12 @@ def test_publisher_transport_auth_gdch_credentials(transport_class): def test_publisher_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index 81aec84c91c4..3d4b1e2e6c02 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py @@ -251,7 +251,7 @@ def transport(self) -> EventarcTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5540,7 +5540,7 @@ async def sample_delete_google_api_source(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5566,8 +5566,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5576,7 +5580,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5584,7 +5588,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5595,7 +5599,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5621,8 +5625,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5631,7 +5639,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5639,7 +5647,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5650,7 +5658,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5680,8 +5688,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5690,7 +5702,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5698,7 +5710,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5706,7 +5718,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5735,8 +5747,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5745,7 +5761,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5753,7 +5769,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5761,7 +5777,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5853,8 +5869,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5863,7 +5883,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5871,7 +5893,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5882,7 +5904,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5975,8 +5997,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5985,7 +6011,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5993,7 +6021,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6004,7 +6032,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6035,8 +6063,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6047,7 +6079,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6055,7 +6089,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6066,7 +6100,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6092,8 +6126,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6102,7 +6140,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6110,7 +6148,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6121,7 +6159,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6147,8 +6185,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6157,7 +6199,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6165,7 +6207,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index dab76effeb7b..f5e75958063b 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py @@ -145,7 +145,7 @@ class EventarcClient(metaclass=EventarcClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -153,7 +153,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -163,6 +163,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -786,7 +790,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -883,7 +887,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -979,7 +983,7 @@ def __init__( self._universe_domain = EventarcClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6159,7 +6163,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6185,8 +6189,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6195,7 +6203,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6204,7 +6212,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6218,7 +6226,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6244,8 +6252,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6254,7 +6266,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6263,7 +6275,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6277,7 +6289,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6307,8 +6319,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6317,7 +6333,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6325,7 +6341,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6333,7 +6349,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6362,8 +6378,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6372,7 +6392,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6380,7 +6400,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6388,7 +6408,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6480,8 +6500,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6490,7 +6514,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6499,7 +6525,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6513,7 +6539,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6606,8 +6632,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6616,7 +6646,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6625,7 +6657,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6639,7 +6671,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6670,8 +6702,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6680,7 +6716,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6689,7 +6727,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6703,7 +6741,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6729,8 +6767,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6739,7 +6781,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6748,7 +6790,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6762,7 +6804,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6788,8 +6830,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6798,7 +6844,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6807,7 +6853,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/README.rst b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/README.rst index 442d2fb0c1b2..ed7a902532be 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/README.rst +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EventarcTransport` is the ABC for all transports. -- public child `EventarcGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EventarcGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEventarcRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EventarcRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EventarcTransport`` is the ABC for all transports. + +- public child ``EventarcGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EventarcGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEventarcRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EventarcRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py index 7a028f49eb37..5e5d9aa5d3d3 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py @@ -100,6 +100,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -149,6 +153,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py index 5149925abe3c..74be00e42661 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py @@ -74,7 +74,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -109,7 +109,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -206,6 +206,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py index 5b16f3fe0003..2ea2e2622873 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py @@ -80,7 +80,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -115,7 +115,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -257,6 +257,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py index 2355a61e77a6..ddf744b6b724 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py @@ -2546,6 +2546,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EventarcRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index df397aa8756e..73dec7bf5a8c 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-eventarc/setup.py b/packages/google-cloud-eventarc/setup.py index 0193695eace5..e55a624dec8e 100644 --- a/packages/google-cloud-eventarc/setup.py +++ b/packages/google-cloud-eventarc/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-eventarc/testing/constraints-3.7.txt b/packages/google-cloud-eventarc/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-eventarc/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-eventarc/testing/constraints-3.8.txt b/packages/google-cloud-eventarc/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-eventarc/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-eventarc/testing/constraints-3.9.txt b/packages/google-cloud-eventarc/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-eventarc/testing/constraints-3.9.txt +++ b/packages/google-cloud-eventarc/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index 806933859131..22b95bd666b7 100644 --- a/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -157,6 +157,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EventarcClient._get_default_mtls_endpoint(None) is None assert EventarcClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -173,6 +174,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EventarcClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert EventarcClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1262,11 +1264,13 @@ def test_eventarc_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -26723,8 +26727,9 @@ def test_get_trigger_rest_bad_request(request_type=eventarc.GetTriggerRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26797,17 +26802,17 @@ def test_get_trigger_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_trigger" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_trigger" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.EventarcRestInterceptor, "pre_get_trigger") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26856,8 +26861,9 @@ def test_list_triggers_rest_bad_request(request_type=eventarc.ListTriggersReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26920,17 +26926,19 @@ def test_list_triggers_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_triggers" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_triggers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_triggers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_triggers" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_triggers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_triggers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26981,8 +26989,9 @@ def test_create_trigger_rest_bad_request(request_type=eventarc.CreateTriggerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27146,19 +27155,20 @@ def test_create_trigger_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_trigger" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_create_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_trigger" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27209,8 +27219,9 @@ def test_update_trigger_rest_bad_request(request_type=eventarc.UpdateTriggerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27376,19 +27387,20 @@ def test_update_trigger_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_update_trigger" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_update_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_trigger" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27437,8 +27449,9 @@ def test_delete_trigger_rest_bad_request(request_type=eventarc.DeleteTriggerRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27493,19 +27506,20 @@ def test_delete_trigger_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_trigger" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_trigger_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_trigger" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_trigger" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_trigger_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_trigger" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27554,8 +27568,9 @@ def test_get_channel_rest_bad_request(request_type=eventarc.GetChannelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27629,17 +27644,17 @@ def test_get_channel_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_channel" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_channel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_channel" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_channel_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.EventarcRestInterceptor, "pre_get_channel") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27688,8 +27703,9 @@ def test_list_channels_rest_bad_request(request_type=eventarc.ListChannelsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27752,17 +27768,19 @@ def test_list_channels_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_channels" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_channels_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_channels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_channels" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_channels_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_channels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27813,8 +27831,9 @@ def test_create_channel_rest_bad_request(request_type=eventarc.CreateChannelRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27949,19 +27968,20 @@ def test_create_channel_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_channel" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_create_channel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_channel" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_channel_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28012,8 +28032,9 @@ def test_update_channel_rest_bad_request(request_type=eventarc.UpdateChannelRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28150,19 +28171,20 @@ def test_update_channel_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_update_channel" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_update_channel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_channel" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_channel_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28211,8 +28233,9 @@ def test_delete_channel_rest_bad_request(request_type=eventarc.DeleteChannelRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28267,19 +28290,20 @@ def test_delete_channel_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_channel" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_channel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_channel" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_channel_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28328,8 +28352,9 @@ def test_get_provider_rest_bad_request(request_type=eventarc.GetProviderRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28392,17 +28417,19 @@ def test_get_provider_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_provider" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_provider_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_provider" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_provider" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_provider_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_provider" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28451,8 +28478,9 @@ def test_list_providers_rest_bad_request(request_type=eventarc.ListProvidersRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28515,17 +28543,19 @@ def test_list_providers_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_providers" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_providers_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_providers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_providers" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_providers_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_providers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28580,8 +28610,9 @@ def test_get_channel_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28650,17 +28681,20 @@ def test_get_channel_connection_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_channel_connection" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_channel_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_channel_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_channel_connection" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_get_channel_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_channel_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28718,8 +28752,9 @@ def test_list_channel_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28782,18 +28817,20 @@ def test_list_channel_connections_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_channel_connections" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_list_channel_connections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_channel_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_channel_connections" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_list_channel_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_channel_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28851,8 +28888,9 @@ def test_create_channel_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28985,20 +29023,21 @@ def test_create_channel_connection_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_channel_connection" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_create_channel_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_channel_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_channel_connection" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_create_channel_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_channel_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29053,8 +29092,9 @@ def test_delete_channel_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29111,20 +29151,21 @@ def test_delete_channel_connection_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_channel_connection" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_delete_channel_connection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_channel_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_channel_connection" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_delete_channel_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_channel_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29177,8 +29218,9 @@ def test_get_google_channel_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29241,18 +29283,20 @@ def test_get_google_channel_config_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_google_channel_config" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_get_google_channel_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_google_channel_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_google_channel_config" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_get_google_channel_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_google_channel_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29314,8 +29358,9 @@ def test_update_google_channel_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29459,18 +29504,20 @@ def test_update_google_channel_config_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_update_google_channel_config" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_update_google_channel_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_google_channel_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_google_channel_config" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_update_google_channel_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_google_channel_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29526,8 +29573,9 @@ def test_get_message_bus_rest_bad_request(request_type=eventarc.GetMessageBusReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29596,17 +29644,19 @@ def test_get_message_bus_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_message_bus" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_message_bus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_message_bus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_message_bus" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_message_bus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_message_bus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29657,8 +29707,9 @@ def test_list_message_buses_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29721,17 +29772,19 @@ def test_list_message_buses_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_message_buses" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_message_buses_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_message_buses" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_message_buses" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_message_buses_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_message_buses" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29786,8 +29839,9 @@ def test_list_message_bus_enrollments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29852,18 +29906,20 @@ def test_list_message_bus_enrollments_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_message_bus_enrollments" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_list_message_bus_enrollments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_message_bus_enrollments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_message_bus_enrollments" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_list_message_bus_enrollments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_message_bus_enrollments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29921,8 +29977,9 @@ def test_create_message_bus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30056,19 +30113,20 @@ def test_create_message_bus_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_message_bus" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_create_message_bus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_message_bus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_message_bus" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_message_bus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_message_bus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30125,8 +30183,9 @@ def test_update_message_bus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30264,19 +30323,20 @@ def test_update_message_bus_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_update_message_bus" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_update_message_bus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_message_bus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_message_bus" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_message_bus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_message_bus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30329,8 +30389,9 @@ def test_delete_message_bus_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30385,19 +30446,20 @@ def test_delete_message_bus_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_message_bus" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_message_bus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_message_bus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_message_bus" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_message_bus_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_message_bus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30448,8 +30510,9 @@ def test_get_enrollment_rest_bad_request(request_type=eventarc.GetEnrollmentRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30522,17 +30585,19 @@ def test_get_enrollment_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_enrollment" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_enrollment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_enrollment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_enrollment" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_enrollment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_enrollment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30583,8 +30648,9 @@ def test_list_enrollments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30647,17 +30713,19 @@ def test_list_enrollments_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_enrollments" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_enrollments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_enrollments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_enrollments" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_enrollments_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_enrollments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30712,8 +30780,9 @@ def test_create_enrollment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30848,19 +30917,20 @@ def test_create_enrollment_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_enrollment" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_create_enrollment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_enrollment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_enrollment" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_enrollment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_enrollment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30915,8 +30985,9 @@ def test_update_enrollment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31053,19 +31124,20 @@ def test_update_enrollment_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_update_enrollment" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_update_enrollment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_enrollment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_enrollment" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_enrollment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_enrollment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31118,8 +31190,9 @@ def test_delete_enrollment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31174,19 +31247,20 @@ def test_delete_enrollment_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_enrollment" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_enrollment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_enrollment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_enrollment" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_enrollment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_enrollment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31237,8 +31311,9 @@ def test_get_pipeline_rest_bad_request(request_type=eventarc.GetPipelineRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31309,17 +31384,19 @@ def test_get_pipeline_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_pipeline" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_pipeline_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_pipeline" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_pipeline_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31368,8 +31445,9 @@ def test_list_pipelines_rest_bad_request(request_type=eventarc.ListPipelinesRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31432,17 +31510,19 @@ def test_list_pipelines_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_pipelines" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_pipelines_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_pipelines" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_pipelines" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_pipelines_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_pipelines" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31493,8 +31573,9 @@ def test_create_pipeline_rest_bad_request(request_type=eventarc.CreatePipelineRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31669,19 +31750,20 @@ def test_create_pipeline_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_pipeline" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_create_pipeline_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_pipeline" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_pipeline_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31732,8 +31814,9 @@ def test_update_pipeline_rest_bad_request(request_type=eventarc.UpdatePipelineRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31910,19 +31993,20 @@ def test_update_pipeline_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_update_pipeline" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_update_pipeline_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_pipeline" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_pipeline_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31971,8 +32055,9 @@ def test_delete_pipeline_rest_bad_request(request_type=eventarc.DeletePipelineRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32027,19 +32112,20 @@ def test_delete_pipeline_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_pipeline" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_pipeline_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_pipeline" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_pipeline_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32092,8 +32178,9 @@ def test_get_google_api_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32166,17 +32253,20 @@ def test_get_google_api_source_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_google_api_source" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_get_google_api_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_get_google_api_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_get_google_api_source" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_get_google_api_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_get_google_api_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32231,8 +32321,9 @@ def test_list_google_api_sources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32295,17 +32386,20 @@ def test_list_google_api_sources_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_google_api_sources" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, "post_list_google_api_sources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_list_google_api_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EventarcRestInterceptor, "post_list_google_api_sources" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_list_google_api_sources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_list_google_api_sources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32363,8 +32457,9 @@ def test_create_google_api_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32501,20 +32596,21 @@ def test_create_google_api_source_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_create_google_api_source" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_create_google_api_source_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_create_google_api_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_create_google_api_source" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_create_google_api_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_create_google_api_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32571,8 +32667,9 @@ def test_update_google_api_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32713,20 +32810,21 @@ def test_update_google_api_source_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_update_google_api_source" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_update_google_api_source_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_update_google_api_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_update_google_api_source" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_update_google_api_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_update_google_api_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32781,8 +32879,9 @@ def test_delete_google_api_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32839,20 +32938,21 @@ def test_delete_google_api_source_rest_interceptors(null_interceptor): ) client = EventarcClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.EventarcRestInterceptor, "post_delete_google_api_source" - ) as post, mock.patch.object( - transports.EventarcRestInterceptor, - "post_delete_google_api_source_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.EventarcRestInterceptor, "pre_delete_google_api_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.EventarcRestInterceptor, "post_delete_google_api_source" + ) as post, + mock.patch.object( + transports.EventarcRestInterceptor, + "post_delete_google_api_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EventarcRestInterceptor, "pre_delete_google_api_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32905,8 +33005,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32965,8 +33066,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33027,8 +33129,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33089,8 +33192,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33151,8 +33255,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33213,8 +33318,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33275,8 +33381,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33337,8 +33444,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -33399,8 +33507,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34395,11 +34504,14 @@ def test_eventarc_base_transport(): def test_eventarc_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.eventarc_v1.services.eventarc.transports.EventarcTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.eventarc_v1.services.eventarc.transports.EventarcTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EventarcTransport( @@ -34416,9 +34528,12 @@ def test_eventarc_base_transport_with_credentials_file(): def test_eventarc_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.eventarc_v1.services.eventarc.transports.EventarcTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.eventarc_v1.services.eventarc.transports.EventarcTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EventarcTransport() @@ -34490,11 +34605,12 @@ def test_eventarc_transport_auth_gdch_credentials(transport_class): def test_eventarc_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -35573,6 +35689,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -35712,6 +35860,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -35857,6 +36037,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36002,6 +36216,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36147,6 +36395,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36288,6 +36570,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36452,6 +36768,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = EventarcClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36619,6 +36970,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = EventarcClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36796,6 +37182,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = EventarcClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py index e459e3a8dba1..4afc3bf3b308 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py @@ -226,7 +226,7 @@ def transport(self) -> CloudFilestoreManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2677,7 +2677,7 @@ async def sample_promote_replica(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2703,8 +2703,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2713,7 +2717,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2721,7 +2725,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2732,7 +2736,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2758,8 +2762,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2768,7 +2776,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2776,7 +2784,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2787,7 +2795,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2817,8 +2825,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2827,7 +2839,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2835,7 +2847,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2843,7 +2855,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2872,8 +2884,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2882,7 +2898,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2890,7 +2906,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2898,7 +2914,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2924,8 +2940,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2934,7 +2954,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2942,7 +2962,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2953,7 +2973,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2979,8 +2999,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2989,7 +3013,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2997,7 +3021,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py index 64ab2d4e4ff9..e8410cde6f5a 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py @@ -142,7 +142,7 @@ class CloudFilestoreManagerClient(metaclass=CloudFilestoreManagerClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -150,7 +150,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -160,6 +160,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -513,7 +517,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -612,7 +616,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -712,7 +716,7 @@ def __init__( self._universe_domain = CloudFilestoreManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3110,7 +3114,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3136,8 +3140,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3146,7 +3154,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3155,7 +3163,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3169,7 +3177,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3195,8 +3203,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3205,7 +3217,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3214,7 +3226,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3228,7 +3240,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3258,8 +3270,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3268,7 +3284,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3276,7 +3292,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3284,7 +3300,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3313,8 +3329,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3323,7 +3343,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3331,7 +3351,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3339,7 +3359,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3365,8 +3385,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3375,7 +3399,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3384,7 +3408,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3398,7 +3422,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3424,8 +3448,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3434,7 +3462,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3443,7 +3471,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/README.rst b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/README.rst index 058692bad816..d96e7f5d9c0c 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/README.rst +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudFilestoreManagerTransport` is the ABC for all transports. -- public child `CloudFilestoreManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudFilestoreManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudFilestoreManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudFilestoreManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudFilestoreManagerTransport`` is the ABC for all transports. + +- public child ``CloudFilestoreManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudFilestoreManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudFilestoreManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudFilestoreManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py index a5b716df01ca..31616c59187e 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py index f7a5bb271104..5ad03a5f553e 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -208,6 +208,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py index 8ecf149df40f..66a6a9fb2198 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -259,6 +259,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py index d46707a1524c..e65dcdc17551 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py @@ -1354,6 +1354,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudFilestoreManagerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index 60967b2922b7..f319b986cf81 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-filestore/setup.py b/packages/google-cloud-filestore/setup.py index 05d1df34cb02..c5cd15cb7b07 100644 --- a/packages/google-cloud-filestore/setup.py +++ b/packages/google-cloud-filestore/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -48,7 +48,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-filestore" @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-filestore/testing/constraints-3.7.txt b/packages/google-cloud-filestore/testing/constraints-3.7.txt deleted file mode 100644 index 1267011b16cb..000000000000 --- a/packages/google-cloud-filestore/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-cloud-common==1.0.0 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-filestore/testing/constraints-3.8.txt b/packages/google-cloud-filestore/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-filestore/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-filestore/testing/constraints-3.9.txt b/packages/google-cloud-filestore/testing/constraints-3.9.txt index 7599dea499ed..11fcf4f341b2 100644 --- a/packages/google-cloud-filestore/testing/constraints-3.9.txt +++ b/packages/google-cloud-filestore/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-cloud-common==1.0.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py b/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py index e92885476a17..46051dc68662 100644 --- a/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py +++ b/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudFilestoreManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): CloudFilestoreManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudFilestoreManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1353,11 +1358,13 @@ def test_cloud_filestore_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -12193,8 +12200,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12259,18 +12267,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_list_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12328,8 +12338,9 @@ def test_get_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12420,18 +12431,20 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_get_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_get_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12486,8 +12499,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12677,20 +12691,21 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_create_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_create_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12745,8 +12760,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12938,20 +12954,21 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_update_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_update_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13004,8 +13021,9 @@ def test_restore_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13062,20 +13080,21 @@ def test_restore_instance_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_restore_instance" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_restore_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_restore_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_restore_instance" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_restore_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_restore_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13128,8 +13147,9 @@ def test_revert_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13186,20 +13206,21 @@ def test_revert_instance_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_revert_instance" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_revert_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_revert_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_revert_instance" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_revert_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_revert_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13252,8 +13273,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13310,20 +13332,21 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_delete_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_delete_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13376,8 +13399,9 @@ def test_list_snapshots_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13442,18 +13466,20 @@ def test_list_snapshots_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_list_snapshots" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_list_snapshots_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_list_snapshots" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_list_snapshots" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_list_snapshots_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_list_snapshots" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13513,8 +13539,9 @@ def test_get_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13585,18 +13612,20 @@ def test_get_snapshot_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_get_snapshot" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_get_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_get_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_get_snapshot" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_get_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_get_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13651,8 +13680,9 @@ def test_create_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13785,20 +13815,21 @@ def test_create_snapshot_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_create_snapshot" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_create_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_create_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_create_snapshot" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_create_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_create_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13853,8 +13884,9 @@ def test_delete_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13913,20 +13945,21 @@ def test_delete_snapshot_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_delete_snapshot" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_delete_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_delete_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_delete_snapshot" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_delete_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_delete_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13983,8 +14016,9 @@ def test_update_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14121,20 +14155,21 @@ def test_update_snapshot_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_update_snapshot" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_update_snapshot_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_update_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_update_snapshot" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_update_snapshot_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_update_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14187,8 +14222,9 @@ def test_list_backups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14253,18 +14289,20 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_list_backups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_list_backups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14322,8 +14360,9 @@ def test_get_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14413,17 +14452,20 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_get_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14478,8 +14520,9 @@ def test_create_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14621,20 +14664,21 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_create_backup_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_create_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14687,8 +14731,9 @@ def test_delete_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14745,20 +14790,21 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_delete_backup_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_delete_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14813,8 +14859,9 @@ def test_update_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14958,20 +15005,21 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_update_backup_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_update_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_update_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15024,8 +15072,9 @@ def test_promote_replica_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15082,20 +15131,21 @@ def test_promote_replica_rest_interceptors(null_interceptor): ) client = CloudFilestoreManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "post_promote_replica" - ) as post, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, - "post_promote_replica_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFilestoreManagerRestInterceptor, "pre_promote_replica" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "post_promote_replica" + ) as post, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, + "post_promote_replica_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFilestoreManagerRestInterceptor, "pre_promote_replica" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15148,8 +15198,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15208,8 +15259,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15270,8 +15322,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15332,8 +15385,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15394,8 +15448,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15456,8 +15511,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -15970,11 +16026,14 @@ def test_cloud_filestore_manager_base_transport(): def test_cloud_filestore_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.filestore_v1.services.cloud_filestore_manager.transports.CloudFilestoreManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.filestore_v1.services.cloud_filestore_manager.transports.CloudFilestoreManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudFilestoreManagerTransport( @@ -15991,9 +16050,12 @@ def test_cloud_filestore_manager_base_transport_with_credentials_file(): def test_cloud_filestore_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.filestore_v1.services.cloud_filestore_manager.transports.CloudFilestoreManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.filestore_v1.services.cloud_filestore_manager.transports.CloudFilestoreManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudFilestoreManagerTransport() @@ -16067,11 +16129,12 @@ def test_cloud_filestore_manager_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16776,6 +16839,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -16915,6 +17010,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17060,6 +17187,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17205,6 +17366,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17350,6 +17545,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -17493,6 +17722,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CloudFilestoreManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudFilestoreManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CloudFilestoreManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/async_client.py b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/async_client.py index 36f3b074cc20..93a46ff3ca07 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/async_client.py +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/async_client.py @@ -224,7 +224,7 @@ def transport(self) -> AMLTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5527,7 +5527,7 @@ async def sample_delete_backtest_result(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5553,8 +5553,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5563,7 +5567,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5571,7 +5575,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5582,7 +5586,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5608,8 +5612,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5618,7 +5626,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5626,7 +5634,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5637,7 +5645,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5667,8 +5675,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5677,7 +5689,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5685,7 +5697,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5693,7 +5705,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5722,8 +5734,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5732,7 +5748,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5740,7 +5756,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5748,7 +5764,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5774,8 +5790,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5784,7 +5804,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5792,7 +5812,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5803,7 +5823,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5829,8 +5849,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5839,7 +5863,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5847,7 +5871,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/client.py b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/client.py index c588cc620f5b..5bd16be4ed57 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/client.py +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/client.py @@ -146,7 +146,7 @@ class AMLClient(metaclass=AMLClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -154,7 +154,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -164,6 +164,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -615,7 +619,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -712,7 +716,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -808,7 +812,7 @@ def __init__( self._universe_domain = AMLClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6011,7 +6015,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6037,8 +6041,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6047,7 +6055,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6056,7 +6064,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6070,7 +6078,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6096,8 +6104,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6106,7 +6118,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6115,7 +6127,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6129,7 +6141,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6159,8 +6171,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6169,7 +6185,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6177,7 +6193,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6185,7 +6201,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6214,8 +6230,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6224,7 +6244,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6232,7 +6252,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6240,7 +6260,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6266,8 +6286,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6276,7 +6300,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6285,7 +6309,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6299,7 +6323,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6325,8 +6349,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6335,7 +6363,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6344,7 +6372,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/README.rst b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/README.rst index 04277a1d0475..aa5cf7d6c68d 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/README.rst +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AMLTransport` is the ABC for all transports. -- public child `AMLGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AMLGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAMLRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AMLRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AMLTransport`` is the ABC for all transports. + +- public child ``AMLGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AMLGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAMLRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AMLRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/base.py b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/base.py index 1bf82ae7edf3..749631591141 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/base.py +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/base.py @@ -100,6 +100,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -149,6 +153,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc.py b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc.py index 4724405799ab..4506d055fdab 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc.py +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc.py @@ -74,7 +74,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -109,7 +109,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -205,6 +205,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc_asyncio.py b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc_asyncio.py index 8e236598d2f5..a49406b89c9c 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc_asyncio.py +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/grpc_asyncio.py @@ -80,7 +80,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -115,7 +115,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -256,6 +256,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/rest.py b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/rest.py index 6ae4164c5969..81acccf8961d 100644 --- a/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/rest.py +++ b/packages/google-cloud-financialservices/google/cloud/financialservices_v1/services/aml/transports/rest.py @@ -2439,6 +2439,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AMLRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-financialservices/noxfile.py b/packages/google-cloud-financialservices/noxfile.py index e2c3fda17fd2..4ce3f0533277 100644 --- a/packages/google-cloud-financialservices/noxfile.py +++ b/packages/google-cloud-financialservices/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-financialservices/setup.py b/packages/google-cloud-financialservices/setup.py index 38d74e8e7154..01509b011bbb 100644 --- a/packages/google-cloud-financialservices/setup.py +++ b/packages/google-cloud-financialservices/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-financialservices" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-financialservices/testing/constraints-3.7.txt b/packages/google-cloud-financialservices/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-financialservices/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-financialservices/testing/constraints-3.8.txt b/packages/google-cloud-financialservices/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-financialservices/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-financialservices/testing/constraints-3.9.txt b/packages/google-cloud-financialservices/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-financialservices/testing/constraints-3.9.txt +++ b/packages/google-cloud-financialservices/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-financialservices/tests/unit/gapic/financialservices_v1/test_aml.py b/packages/google-cloud-financialservices/tests/unit/gapic/financialservices_v1/test_aml.py index 6bb78d1c866c..3ddd3eeda302 100644 --- a/packages/google-cloud-financialservices/tests/unit/gapic/financialservices_v1/test_aml.py +++ b/packages/google-cloud-financialservices/tests/unit/gapic/financialservices_v1/test_aml.py @@ -155,6 +155,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AMLClient._get_default_mtls_endpoint(None) is None assert AMLClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -167,6 +168,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AMLClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AMLClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1219,11 +1221,13 @@ def test_aml_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -25905,8 +25909,9 @@ def test_list_instances_rest_bad_request(request_type=instance.ListInstancesRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25969,17 +25974,15 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AMLRestInterceptor, "post_list_instances") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_list_instances") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26030,8 +26033,9 @@ def test_get_instance_rest_bad_request(request_type=instance.GetInstanceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26096,17 +26100,15 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AMLRestInterceptor, "post_get_instance") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_get_instance") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26157,8 +26159,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26288,19 +26291,18 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_create_instance") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26355,8 +26357,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26488,19 +26491,18 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_update_instance") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26551,8 +26553,9 @@ def test_delete_instance_rest_bad_request(request_type=instance.DeleteInstanceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26607,19 +26610,18 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_delete_instance") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26670,8 +26672,9 @@ def test_import_registered_parties_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26726,19 +26729,21 @@ def test_import_registered_parties_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_import_registered_parties" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_import_registered_parties_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_import_registered_parties" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_import_registered_parties" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, + "post_import_registered_parties_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_import_registered_parties" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26791,8 +26796,9 @@ def test_export_registered_parties_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26847,19 +26853,21 @@ def test_export_registered_parties_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_export_registered_parties" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_export_registered_parties_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_export_registered_parties" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_export_registered_parties" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, + "post_export_registered_parties_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_export_registered_parties" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26910,8 +26918,9 @@ def test_list_datasets_rest_bad_request(request_type=dataset.ListDatasetsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26974,17 +26983,15 @@ def test_list_datasets_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_datasets" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_datasets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_datasets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AMLRestInterceptor, "post_list_datasets") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_datasets_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_list_datasets") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27037,8 +27044,9 @@ def test_get_dataset_rest_bad_request(request_type=dataset.GetDatasetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27103,17 +27111,15 @@ def test_get_dataset_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_dataset" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AMLRestInterceptor, "post_get_dataset") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_get_dataset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27162,8 +27168,9 @@ def test_create_dataset_rest_bad_request(request_type=gcf_dataset.CreateDatasetR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27295,19 +27302,16 @@ def test_create_dataset_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_create_dataset" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_create_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_create_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AMLRestInterceptor, "post_create_dataset") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_create_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_create_dataset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27362,8 +27366,9 @@ def test_update_dataset_rest_bad_request(request_type=gcf_dataset.UpdateDatasetR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27499,19 +27504,16 @@ def test_update_dataset_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_update_dataset" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_update_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_update_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AMLRestInterceptor, "post_update_dataset") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_update_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_update_dataset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27564,8 +27566,9 @@ def test_delete_dataset_rest_bad_request(request_type=dataset.DeleteDatasetReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27622,19 +27625,16 @@ def test_delete_dataset_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_delete_dataset" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_delete_dataset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_delete_dataset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AMLRestInterceptor, "post_delete_dataset") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_dataset_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_delete_dataset") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27683,8 +27683,9 @@ def test_list_models_rest_bad_request(request_type=model.ListModelsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27747,17 +27748,15 @@ def test_list_models_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_models" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_models_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AMLRestInterceptor, "post_list_models") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_models_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_list_models") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27808,8 +27807,9 @@ def test_get_model_rest_bad_request(request_type=model.GetModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27882,17 +27882,15 @@ def test_get_model_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_model" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.AMLRestInterceptor, "post_get_model") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_get_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27941,8 +27939,9 @@ def test_create_model_rest_bad_request(request_type=gcf_model.CreateModelRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28076,19 +28075,16 @@ def test_create_model_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_create_model" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_create_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_create_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AMLRestInterceptor, "post_create_model") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_create_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_create_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28141,8 +28137,9 @@ def test_update_model_rest_bad_request(request_type=gcf_model.UpdateModelRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28280,19 +28277,16 @@ def test_update_model_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_update_model" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_update_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_update_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AMLRestInterceptor, "post_update_model") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_update_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_update_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28345,8 +28339,9 @@ def test_export_model_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28403,19 +28398,20 @@ def test_export_model_metadata_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_export_model_metadata" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_export_model_metadata_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_export_model_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_export_model_metadata" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_export_model_metadata_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_export_model_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28468,8 +28464,9 @@ def test_delete_model_rest_bad_request(request_type=model.DeleteModelRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28526,19 +28523,16 @@ def test_delete_model_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_delete_model" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_delete_model_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_delete_model" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.AMLRestInterceptor, "post_delete_model") as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_model_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.AMLRestInterceptor, "pre_delete_model") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28589,8 +28583,9 @@ def test_list_engine_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28653,17 +28648,19 @@ def test_list_engine_configs_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_engine_configs" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_engine_configs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_engine_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_engine_configs" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_engine_configs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_list_engine_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28723,8 +28720,9 @@ def test_get_engine_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28798,17 +28796,19 @@ def test_get_engine_config_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_engine_config" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_engine_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_engine_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_engine_config" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_engine_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_get_engine_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28861,8 +28861,9 @@ def test_create_engine_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29002,19 +29003,20 @@ def test_create_engine_config_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_create_engine_config" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_create_engine_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_create_engine_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_create_engine_config" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_create_engine_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_create_engine_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29071,8 +29073,9 @@ def test_update_engine_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29216,19 +29219,20 @@ def test_update_engine_config_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_update_engine_config" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_update_engine_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_update_engine_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_update_engine_config" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_update_engine_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_update_engine_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29283,8 +29287,9 @@ def test_export_engine_config_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29341,20 +29346,21 @@ def test_export_engine_config_metadata_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_export_engine_config_metadata" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, - "post_export_engine_config_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_export_engine_config_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_export_engine_config_metadata" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, + "post_export_engine_config_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_export_engine_config_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29409,8 +29415,9 @@ def test_delete_engine_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29467,19 +29474,20 @@ def test_delete_engine_config_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_delete_engine_config" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_delete_engine_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_delete_engine_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_engine_config" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_engine_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_delete_engine_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29534,8 +29542,9 @@ def test_get_engine_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29602,17 +29611,19 @@ def test_get_engine_version_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_engine_version" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_engine_version_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_engine_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_engine_version" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_engine_version_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_get_engine_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29667,8 +29678,9 @@ def test_list_engine_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29731,17 +29743,19 @@ def test_list_engine_versions_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_engine_versions" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_engine_versions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_engine_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_engine_versions" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_engine_versions_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_list_engine_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29799,8 +29813,9 @@ def test_list_prediction_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29863,17 +29878,19 @@ def test_list_prediction_results_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_prediction_results" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_prediction_results_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_prediction_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_prediction_results" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_prediction_results_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_list_prediction_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29933,8 +29950,9 @@ def test_get_prediction_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30007,17 +30025,19 @@ def test_get_prediction_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_prediction_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_prediction_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_prediction_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_prediction_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_prediction_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_get_prediction_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30072,8 +30092,9 @@ def test_create_prediction_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30216,19 +30237,20 @@ def test_create_prediction_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_create_prediction_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_create_prediction_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_create_prediction_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_create_prediction_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_create_prediction_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_create_prediction_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30285,8 +30307,9 @@ def test_update_prediction_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30433,19 +30456,20 @@ def test_update_prediction_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_update_prediction_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_update_prediction_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_update_prediction_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_update_prediction_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_update_prediction_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_update_prediction_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30500,8 +30524,9 @@ def test_export_prediction_result_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30558,20 +30583,21 @@ def test_export_prediction_result_metadata_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_export_prediction_result_metadata" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, - "post_export_prediction_result_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_export_prediction_result_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_export_prediction_result_metadata" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, + "post_export_prediction_result_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_export_prediction_result_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30626,8 +30652,9 @@ def test_delete_prediction_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30684,19 +30711,20 @@ def test_delete_prediction_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_delete_prediction_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_delete_prediction_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_delete_prediction_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_prediction_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_prediction_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_delete_prediction_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30749,8 +30777,9 @@ def test_list_backtest_results_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30813,17 +30842,19 @@ def test_list_backtest_results_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_list_backtest_results" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_list_backtest_results_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_list_backtest_results" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_backtest_results" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_list_backtest_results_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_list_backtest_results" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30883,8 +30914,9 @@ def test_get_backtest_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30957,17 +30989,19 @@ def test_get_backtest_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AMLRestInterceptor, "post_get_backtest_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_get_backtest_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_get_backtest_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_backtest_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_get_backtest_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_get_backtest_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31022,8 +31056,9 @@ def test_create_backtest_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31160,19 +31195,20 @@ def test_create_backtest_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_create_backtest_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_create_backtest_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_create_backtest_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_create_backtest_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_create_backtest_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_create_backtest_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31229,8 +31265,9 @@ def test_update_backtest_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31371,19 +31408,20 @@ def test_update_backtest_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_update_backtest_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_update_backtest_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_update_backtest_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_update_backtest_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_update_backtest_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_update_backtest_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31438,8 +31476,9 @@ def test_export_backtest_result_metadata_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31496,20 +31535,21 @@ def test_export_backtest_result_metadata_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_export_backtest_result_metadata" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, - "post_export_backtest_result_metadata_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_export_backtest_result_metadata" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_export_backtest_result_metadata" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, + "post_export_backtest_result_metadata_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_export_backtest_result_metadata" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31564,8 +31604,9 @@ def test_delete_backtest_result_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31622,19 +31663,20 @@ def test_delete_backtest_result_rest_interceptors(null_interceptor): ) client = AMLClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AMLRestInterceptor, "post_delete_backtest_result" - ) as post, mock.patch.object( - transports.AMLRestInterceptor, "post_delete_backtest_result_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AMLRestInterceptor, "pre_delete_backtest_result" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_backtest_result" + ) as post, + mock.patch.object( + transports.AMLRestInterceptor, "post_delete_backtest_result_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AMLRestInterceptor, "pre_delete_backtest_result" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31687,8 +31729,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31747,8 +31790,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31809,8 +31853,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31871,8 +31916,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31933,8 +31979,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31995,8 +32042,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32975,11 +33023,14 @@ def test_aml_base_transport(): def test_aml_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.financialservices_v1.services.aml.transports.AMLTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.financialservices_v1.services.aml.transports.AMLTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AMLTransport( @@ -32996,9 +33047,12 @@ def test_aml_base_transport_with_credentials_file(): def test_aml_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.financialservices_v1.services.aml.transports.AMLTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.financialservices_v1.services.aml.transports.AMLTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AMLTransport() @@ -33070,11 +33124,12 @@ def test_aml_transport_auth_gdch_credentials(transport_class): def test_aml_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -33946,6 +34001,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AMLClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AMLAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AMLClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34085,6 +34172,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AMLClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AMLAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AMLClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34230,6 +34349,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AMLClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AMLAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AMLClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34375,6 +34528,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AMLClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AMLAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = AMLClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34520,6 +34707,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AMLClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AMLAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AMLClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34661,6 +34882,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AMLClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AMLAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = AMLClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py index b76fcc3e33cc..8524da1538a6 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py @@ -259,7 +259,7 @@ def transport(self) -> FirestoreAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4261,7 +4261,7 @@ async def sample_clone_database(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4287,8 +4287,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4297,7 +4301,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4305,7 +4309,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4316,7 +4320,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4342,8 +4346,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4352,7 +4360,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4360,7 +4368,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4371,7 +4379,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4401,8 +4409,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4411,7 +4423,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4419,7 +4431,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4427,7 +4439,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4456,8 +4468,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4466,7 +4482,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4474,7 +4490,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/client.py b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/client.py index b8c680bd3a35..cebc74d3a6f8 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/client.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/client.py @@ -163,7 +163,7 @@ class FirestoreAdminClient(metaclass=FirestoreAdminClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -171,7 +171,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -181,6 +181,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -658,7 +662,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -755,7 +759,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -851,7 +855,7 @@ def __init__( self._universe_domain = FirestoreAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4760,7 +4764,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4786,8 +4790,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4796,7 +4804,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4805,7 +4813,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4819,7 +4827,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4845,8 +4853,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4855,7 +4867,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4864,7 +4876,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4878,7 +4890,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4908,8 +4920,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4918,7 +4934,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4926,7 +4942,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4934,7 +4950,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4963,8 +4979,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4973,7 +4993,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4981,7 +5001,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/README.rst b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/README.rst index ffcad7a891ce..133d87654700 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/README.rst +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirestoreAdminTransport` is the ABC for all transports. -- public child `FirestoreAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirestoreAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirestoreAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirestoreAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirestoreAdminTransport`` is the ABC for all transports. + +- public child ``FirestoreAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirestoreAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirestoreAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirestoreAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py index 1ec032171d2d..c3788cf2dcb5 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py @@ -95,6 +95,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -144,6 +148,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py index 37c28b10fd42..7ca0817b2969 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py @@ -66,7 +66,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -226,6 +226,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py index 5e73ba1c451b..a2772dd26712 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py @@ -72,7 +72,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -107,7 +107,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -277,6 +277,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/rest.py b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/rest.py index 9337cb3c0b21..2907ca15320e 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/rest.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_admin_v1/services/firestore_admin/transports/rest.py @@ -1929,6 +1929,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirestoreAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/async_client.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/async_client.py index f338af786bb3..81659180b61c 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/async_client.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> FirestoreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2082,7 +2082,7 @@ async def sample_create_document(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2108,8 +2108,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2118,7 +2122,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2126,7 +2130,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2137,7 +2141,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2163,8 +2167,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2173,7 +2181,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2181,7 +2189,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2192,7 +2200,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2222,8 +2230,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2232,7 +2244,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2240,7 +2252,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2248,7 +2260,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2277,8 +2289,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2287,7 +2303,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2295,7 +2311,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/client.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/client.py index c6b3310b41e2..2e6c01c043e8 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/client.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/client.py @@ -135,7 +135,7 @@ class FirestoreClient(metaclass=FirestoreClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -143,7 +143,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -153,6 +153,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -438,7 +442,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -535,7 +539,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -631,7 +635,7 @@ def __init__( self._universe_domain = FirestoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2475,7 +2479,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2501,8 +2505,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2511,7 +2519,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2520,7 +2528,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2534,7 +2542,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2560,8 +2568,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2570,7 +2582,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2579,7 +2591,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2593,7 +2605,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2623,8 +2635,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2633,7 +2649,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2641,7 +2657,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2649,7 +2665,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2678,8 +2694,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2688,7 +2708,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2696,7 +2716,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/README.rst b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/README.rst index 1823b6773c00..6e277ac57101 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/README.rst +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FirestoreTransport` is the ABC for all transports. -- public child `FirestoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FirestoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFirestoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FirestoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FirestoreTransport`` is the ABC for all transports. + +- public child ``FirestoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FirestoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFirestoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FirestoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/base.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/base.py index 3c2bd1707bc8..814bd378bd2e 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/base.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc.py index 50e9db803e64..810c245ef1ab 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -196,6 +196,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py index a54b2a56eebd..69231a41203e 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -247,6 +247,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/rest.py b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/rest.py index f14ff21bfa86..ccddc25f0ab0 100644 --- a/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/rest.py +++ b/packages/google-cloud-firestore/google/cloud/firestore_v1/services/firestore/transports/rest.py @@ -1017,6 +1017,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FirestoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-firestore/noxfile.py b/packages/google-cloud-firestore/noxfile.py index 2cc73c62cee7..07e7accad4d3 100644 --- a/packages/google-cloud-firestore/noxfile.py +++ b/packages/google-cloud-firestore/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -154,8 +152,9 @@ def system_emulated(session): @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -165,6 +164,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -356,7 +357,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -586,7 +590,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -681,7 +685,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-firestore/setup.py b/packages/google-cloud-firestore/setup.py index 805b2e8a908d..0008c88c7f1f 100644 --- a/packages/google-cloud-firestore/setup.py +++ b/packages/google-cloud-firestore/setup.py @@ -39,16 +39,16 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "google-cloud-core >= 1.4.1, <3.0.0", + "google-cloud-core >= 1.7.3, <3.0.0", "grpcio >= 1.33.2, < 2.0.0", "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-firestore" @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-firestore/testing/constraints-3.7.txt b/packages/google-cloud-firestore/testing/constraints-3.7.txt deleted file mode 100644 index 4900b89439f3..000000000000 --- a/packages/google-cloud-firestore/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -google-cloud-core==1.4.1 -protobuf==3.20.2 diff --git a/packages/google-cloud-firestore/testing/constraints-3.8.txt b/packages/google-cloud-firestore/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-firestore/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-firestore/testing/constraints-3.9.txt b/packages/google-cloud-firestore/testing/constraints-3.9.txt index 7599dea499ed..a0c02608865b 100644 --- a/packages/google-cloud-firestore/testing/constraints-3.9.txt +++ b/packages/google-cloud-firestore/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +google-cloud-core==1.7.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-firestore/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py b/packages/google-cloud-firestore/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py index 70c8f45736ec..5541cbda77fe 100644 --- a/packages/google-cloud-firestore/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py +++ b/packages/google-cloud-firestore/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py @@ -145,6 +145,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirestoreAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -166,6 +167,10 @@ def test__get_default_mtls_endpoint(): assert ( FirestoreAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FirestoreAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1306,11 +1311,13 @@ def test_firestore_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -20023,8 +20030,9 @@ def test_create_index_rest_bad_request(request_type=firestore_admin.CreateIndexR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20168,19 +20176,20 @@ def test_create_index_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_index" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_index_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_create_index" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_create_index" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_create_index_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_create_index" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20233,8 +20242,9 @@ def test_list_indexes_rest_bad_request(request_type=firestore_admin.ListIndexesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20299,17 +20309,19 @@ def test_list_indexes_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_indexes" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_indexes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_list_indexes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_indexes" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_indexes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_list_indexes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20367,8 +20379,9 @@ def test_get_index_rest_bad_request(request_type=firestore_admin.GetIndexRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20447,17 +20460,19 @@ def test_get_index_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_index" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_index_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_get_index" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_index" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_index_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_get_index" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20510,8 +20525,9 @@ def test_delete_index_rest_bad_request(request_type=firestore_admin.DeleteIndexR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20570,13 +20586,13 @@ def test_delete_index_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_delete_index" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_delete_index" + ) as pre, + ): pre.assert_not_called() pb_message = firestore_admin.DeleteIndexRequest.pb( firestore_admin.DeleteIndexRequest() @@ -20621,8 +20637,9 @@ def test_get_field_rest_bad_request(request_type=firestore_admin.GetFieldRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20687,17 +20704,19 @@ def test_get_field_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_field" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_field_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_get_field" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_field" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_field_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_get_field" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20752,8 +20771,9 @@ def test_update_field_rest_bad_request(request_type=firestore_admin.UpdateFieldR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20910,19 +20930,20 @@ def test_update_field_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_update_field" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_update_field_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_update_field" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_update_field" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_update_field_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_update_field" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20975,8 +20996,9 @@ def test_list_fields_rest_bad_request(request_type=firestore_admin.ListFieldsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21041,17 +21063,19 @@ def test_list_fields_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_fields" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_fields_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_list_fields" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_fields" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_fields_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_list_fields" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21106,8 +21130,9 @@ def test_export_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21164,19 +21189,21 @@ def test_export_documents_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_export_documents" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_export_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_export_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_export_documents" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_export_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_export_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21229,8 +21256,9 @@ def test_import_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21287,19 +21315,21 @@ def test_import_documents_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_import_documents" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_import_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_import_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_import_documents" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_import_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_import_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21352,8 +21382,9 @@ def test_bulk_delete_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21410,20 +21441,21 @@ def test_bulk_delete_documents_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_bulk_delete_documents" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_bulk_delete_documents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_bulk_delete_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_bulk_delete_documents" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_bulk_delete_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_bulk_delete_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21476,8 +21508,9 @@ def test_create_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21636,19 +21669,21 @@ def test_create_database_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_database" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_create_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_create_database" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_create_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_create_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21699,8 +21734,9 @@ def test_get_database_rest_bad_request(request_type=firestore_admin.GetDatabaseR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21811,17 +21847,19 @@ def test_get_database_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_database" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_get_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_database" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_database_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_get_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -21874,8 +21912,9 @@ def test_list_databases_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -21938,17 +21977,20 @@ def test_list_databases_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_databases" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_databases_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_list_databases" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_databases" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_list_databases_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_list_databases" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22006,8 +22048,9 @@ def test_update_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22166,19 +22209,21 @@ def test_update_database_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_update_database" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_update_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_update_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_update_database" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_update_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_update_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22231,8 +22276,9 @@ def test_delete_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22289,19 +22335,21 @@ def test_delete_database_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_delete_database" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_delete_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_delete_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_delete_database" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_delete_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_delete_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22354,8 +22402,9 @@ def test_create_user_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22497,17 +22546,20 @@ def test_create_user_creds_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_user_creds" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_user_creds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_create_user_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_create_user_creds" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_create_user_creds_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_create_user_creds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22560,8 +22612,9 @@ def test_get_user_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22628,17 +22681,20 @@ def test_get_user_creds_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_user_creds" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_user_creds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_get_user_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_user_creds" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_get_user_creds_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_get_user_creds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22691,8 +22747,9 @@ def test_list_user_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22752,17 +22809,20 @@ def test_list_user_creds_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_user_creds" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_user_creds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_list_user_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_user_creds" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_list_user_creds_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_list_user_creds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22820,8 +22880,9 @@ def test_enable_user_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22888,17 +22949,20 @@ def test_enable_user_creds_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_enable_user_creds" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_enable_user_creds_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_enable_user_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_enable_user_creds" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_enable_user_creds_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_enable_user_creds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22951,8 +23015,9 @@ def test_disable_user_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23019,18 +23084,20 @@ def test_disable_user_creds_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_disable_user_creds" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_disable_user_creds_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_disable_user_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_disable_user_creds" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_disable_user_creds_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_disable_user_creds" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23083,8 +23150,9 @@ def test_reset_user_password_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23151,18 +23219,20 @@ def test_reset_user_password_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_reset_user_password" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_reset_user_password_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_reset_user_password" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_reset_user_password" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_reset_user_password_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_reset_user_password" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23215,8 +23285,9 @@ def test_delete_user_creds_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23273,13 +23344,13 @@ def test_delete_user_creds_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_delete_user_creds" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_delete_user_creds" + ) as pre, + ): pre.assert_not_called() pb_message = firestore_admin.DeleteUserCredsRequest.pb( firestore_admin.DeleteUserCredsRequest() @@ -23322,8 +23393,9 @@ def test_get_backup_rest_bad_request(request_type=firestore_admin.GetBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23392,17 +23464,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23453,8 +23527,9 @@ def test_list_backups_rest_bad_request(request_type=firestore_admin.ListBackupsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23517,17 +23592,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23585,8 +23662,9 @@ def test_delete_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23643,13 +23721,13 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() pb_message = firestore_admin.DeleteBackupRequest.pb( firestore_admin.DeleteBackupRequest() @@ -23694,8 +23772,9 @@ def test_restore_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23752,19 +23831,21 @@ def test_restore_database_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_restore_database" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_restore_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_restore_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_restore_database" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_restore_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_restore_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23817,8 +23898,9 @@ def test_create_backup_schedule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23958,18 +24040,20 @@ def test_create_backup_schedule_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_create_backup_schedule" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_create_backup_schedule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_create_backup_schedule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_create_backup_schedule" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_create_backup_schedule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_create_backup_schedule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24024,8 +24108,9 @@ def test_get_backup_schedule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24090,18 +24175,20 @@ def test_get_backup_schedule_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_get_backup_schedule" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_get_backup_schedule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_get_backup_schedule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_get_backup_schedule" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_get_backup_schedule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_get_backup_schedule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24154,8 +24241,9 @@ def test_list_backup_schedules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24215,18 +24303,20 @@ def test_list_backup_schedules_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_list_backup_schedules" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_list_backup_schedules_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_list_backup_schedules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_list_backup_schedules" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_list_backup_schedules_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_list_backup_schedules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24288,8 +24378,9 @@ def test_update_backup_schedule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24433,18 +24524,20 @@ def test_update_backup_schedule_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_update_backup_schedule" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, - "post_update_backup_schedule_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_update_backup_schedule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_update_backup_schedule" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_update_backup_schedule_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_update_backup_schedule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24499,8 +24592,9 @@ def test_delete_backup_schedule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24559,13 +24653,13 @@ def test_delete_backup_schedule_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_delete_backup_schedule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_delete_backup_schedule" + ) as pre, + ): pre.assert_not_called() pb_message = firestore_admin.DeleteBackupScheduleRequest.pb( firestore_admin.DeleteBackupScheduleRequest() @@ -24610,8 +24704,9 @@ def test_clone_database_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24668,19 +24763,21 @@ def test_clone_database_rest_interceptors(null_interceptor): ) client = FirestoreAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_clone_database" - ) as post, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "post_clone_database_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreAdminRestInterceptor, "pre_clone_database" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "post_clone_database" + ) as post, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, + "post_clone_database_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreAdminRestInterceptor, "pre_clone_database" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24735,8 +24832,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24797,8 +24895,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24859,8 +24958,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -24921,8 +25021,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -25811,11 +25912,14 @@ def test_firestore_admin_base_transport(): def test_firestore_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.firestore_admin_v1.services.firestore_admin.transports.FirestoreAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.firestore_admin_v1.services.firestore_admin.transports.FirestoreAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirestoreAdminTransport( @@ -25835,9 +25939,12 @@ def test_firestore_admin_base_transport_with_credentials_file(): def test_firestore_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.firestore_admin_v1.services.firestore_admin.transports.FirestoreAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.firestore_admin_v1.services.firestore_admin.transports.FirestoreAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirestoreAdminTransport() @@ -25915,11 +26022,12 @@ def test_firestore_admin_transport_auth_gdch_credentials(transport_class): def test_firestore_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -26824,6 +26932,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = FirestoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = FirestoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = FirestoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -26963,6 +27103,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FirestoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FirestoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FirestoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27108,6 +27280,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FirestoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FirestoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FirestoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -27253,6 +27459,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FirestoreAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FirestoreAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = FirestoreAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-firestore/tests/unit/gapic/firestore_v1/test_firestore.py b/packages/google-cloud-firestore/tests/unit/gapic/firestore_v1/test_firestore.py index 7f09a92ef5f2..b44e0ccb5d50 100644 --- a/packages/google-cloud-firestore/tests/unit/gapic/firestore_v1/test_firestore.py +++ b/packages/google-cloud-firestore/tests/unit/gapic/firestore_v1/test_firestore.py @@ -137,6 +137,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FirestoreClient._get_default_mtls_endpoint(None) is None assert FirestoreClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -153,6 +154,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert FirestoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + FirestoreClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1253,11 +1257,13 @@ def test_firestore_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -9734,8 +9740,9 @@ def test_get_document_rest_bad_request(request_type=firestore.GetDocumentRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9798,17 +9805,19 @@ def test_get_document_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_get_document" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_get_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_get_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_get_document" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_get_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_get_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9860,8 +9869,9 @@ def test_list_documents_rest_bad_request(request_type=firestore.ListDocumentsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9925,17 +9935,19 @@ def test_list_documents_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_list_documents" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_list_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_list_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_list_documents" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_list_documents_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_list_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9990,8 +10002,9 @@ def test_update_document_rest_bad_request(request_type=firestore.UpdateDocumentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10129,17 +10142,19 @@ def test_update_document_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_update_document" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_update_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_update_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_update_document" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_update_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_update_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10192,8 +10207,9 @@ def test_delete_document_rest_bad_request(request_type=firestore.DeleteDocumentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10250,13 +10266,13 @@ def test_delete_document_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_delete_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_delete_document" + ) as pre, + ): pre.assert_not_called() pb_message = firestore.DeleteDocumentRequest.pb( firestore.DeleteDocumentRequest() @@ -10301,8 +10317,9 @@ def test_batch_get_documents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10368,17 +10385,20 @@ def test_batch_get_documents_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_batch_get_documents" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_batch_get_documents_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_batch_get_documents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_batch_get_documents" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, + "post_batch_get_documents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_batch_get_documents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10436,8 +10456,9 @@ def test_begin_transaction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10498,17 +10519,19 @@ def test_begin_transaction_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_begin_transaction" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_begin_transaction_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_begin_transaction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_begin_transaction" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_begin_transaction_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_begin_transaction" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10561,8 +10584,9 @@ def test_commit_rest_bad_request(request_type=firestore.CommitRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10620,17 +10644,15 @@ def test_commit_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_commit" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_commit_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_commit" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirestoreRestInterceptor, "post_commit") as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_commit_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirestoreRestInterceptor, "pre_commit") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10679,8 +10701,9 @@ def test_rollback_rest_bad_request(request_type=firestore.RollbackRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10735,13 +10758,11 @@ def test_rollback_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_rollback" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.FirestoreRestInterceptor, "pre_rollback") as pre, + ): pre.assert_not_called() pb_message = firestore.RollbackRequest.pb(firestore.RollbackRequest()) transcode.return_value = { @@ -10782,8 +10803,9 @@ def test_run_query_rest_bad_request(request_type=firestore.RunQueryRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10851,17 +10873,17 @@ def test_run_query_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_run_query" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_run_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_run_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_run_query" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_run_query_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.FirestoreRestInterceptor, "pre_run_query") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10912,8 +10934,9 @@ def test_execute_pipeline_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10978,17 +11001,19 @@ def test_execute_pipeline_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_execute_pipeline" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_execute_pipeline_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_execute_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_execute_pipeline" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_execute_pipeline_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_execute_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11043,8 +11068,9 @@ def test_run_aggregation_query_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11109,17 +11135,20 @@ def test_run_aggregation_query_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_run_aggregation_query" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_run_aggregation_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_run_aggregation_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_run_aggregation_query" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, + "post_run_aggregation_query_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_run_aggregation_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11175,8 +11204,9 @@ def test_partition_query_rest_bad_request(request_type=firestore.PartitionQueryR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11237,17 +11267,19 @@ def test_partition_query_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_partition_query" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_partition_query_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_partition_query" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_partition_query" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_partition_query_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_partition_query" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11326,8 +11358,9 @@ def test_list_collection_ids_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11390,17 +11423,20 @@ def test_list_collection_ids_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_list_collection_ids" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_list_collection_ids_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_list_collection_ids" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_list_collection_ids" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, + "post_list_collection_ids_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_list_collection_ids" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11456,8 +11492,9 @@ def test_batch_write_rest_bad_request(request_type=firestore.BatchWriteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11515,17 +11552,19 @@ def test_batch_write_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_batch_write" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_batch_write_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_batch_write" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_batch_write" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_batch_write_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_batch_write" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11579,8 +11618,9 @@ def test_create_document_rest_bad_request(request_type=firestore.CreateDocumentR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11717,17 +11757,19 @@ def test_create_document_rest_interceptors(null_interceptor): ) client = FirestoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FirestoreRestInterceptor, "post_create_document" - ) as post, mock.patch.object( - transports.FirestoreRestInterceptor, "post_create_document_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FirestoreRestInterceptor, "pre_create_document" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_create_document" + ) as post, + mock.patch.object( + transports.FirestoreRestInterceptor, "post_create_document_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FirestoreRestInterceptor, "pre_create_document" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11782,8 +11824,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11844,8 +11887,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11906,8 +11950,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11968,8 +12013,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12457,11 +12503,14 @@ def test_firestore_base_transport(): def test_firestore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.firestore_v1.services.firestore.transports.FirestoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.firestore_v1.services.firestore.transports.FirestoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirestoreTransport( @@ -12481,9 +12530,12 @@ def test_firestore_base_transport_with_credentials_file(): def test_firestore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.firestore_v1.services.firestore.transports.FirestoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.firestore_v1.services.firestore.transports.FirestoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FirestoreTransport() @@ -12561,11 +12613,12 @@ def test_firestore_transport_auth_gdch_credentials(transport_class): def test_firestore_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13142,6 +13195,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = FirestoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = FirestoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = FirestoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13281,6 +13366,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = FirestoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = FirestoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = FirestoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13426,6 +13543,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FirestoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FirestoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FirestoreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13571,6 +13722,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FirestoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FirestoreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = FirestoreClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py index 0633fc337344..00e437ed6bb3 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> CloudFunctionsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1589,7 +1589,7 @@ async def sample_test_iam_permissions(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1615,8 +1615,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1625,7 +1629,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1633,7 +1637,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1644,7 +1648,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1670,8 +1674,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1680,7 +1688,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1688,7 +1696,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1699,7 +1707,7 @@ async def get_operation( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1725,8 +1733,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1735,7 +1747,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1743,7 +1755,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py index fe00bc36cab2..86432b39b63d 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py @@ -125,7 +125,7 @@ class CloudFunctionsServiceClient(metaclass=CloudFunctionsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -498,7 +502,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -597,7 +601,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -697,7 +701,7 @@ def __init__( self._universe_domain = CloudFunctionsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2045,7 +2049,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2071,8 +2075,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2081,7 +2089,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2090,7 +2098,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2104,7 +2112,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2130,8 +2138,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2140,7 +2152,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2149,7 +2161,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2163,7 +2175,7 @@ def get_operation( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2189,8 +2201,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2199,7 +2215,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2208,7 +2224,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/README.rst b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/README.rst index b80dfe39a67a..bfa12c64154f 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/README.rst +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudFunctionsServiceTransport` is the ABC for all transports. -- public child `CloudFunctionsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudFunctionsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudFunctionsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudFunctionsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudFunctionsServiceTransport`` is the ABC for all transports. + +- public child ``CloudFunctionsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudFunctionsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudFunctionsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudFunctionsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py index d4577ea380ba..0de9d6ff2bc8 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py index a5cdedf61a3a..8cc4288e29fa 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py @@ -62,7 +62,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py index ab0d9a68387a..df73c9522762 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py @@ -68,7 +68,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -103,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py index 558c3c702b70..9ebff7ba1b60 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py @@ -845,6 +845,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudFunctionsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py index 3a1b1a47e432..34c40029bd95 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> FunctionServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1304,7 +1304,7 @@ async def sample_list_runtimes(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1330,8 +1330,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1340,7 +1344,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1348,7 +1352,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1359,7 +1363,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1385,8 +1389,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1395,7 +1403,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1403,7 +1411,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1414,7 +1422,7 @@ async def get_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1506,8 +1514,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1516,7 +1528,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1524,7 +1538,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1535,7 +1549,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1628,8 +1642,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1638,7 +1656,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1646,7 +1666,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1657,7 +1677,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1688,8 +1708,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1700,7 +1724,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1708,7 +1734,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1719,7 +1745,7 @@ async def test_iam_permissions( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1745,8 +1771,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1755,7 +1785,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1763,7 +1793,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py index 80c54311aecc..3ef96d915be2 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py @@ -127,7 +127,7 @@ class FunctionServiceClient(metaclass=FunctionServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -651,7 +655,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -748,7 +752,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -846,7 +850,7 @@ def __init__( self._universe_domain = FunctionServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1906,7 +1910,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1932,8 +1936,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1942,7 +1950,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1951,7 +1959,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1965,7 +1973,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1991,8 +1999,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2001,7 +2013,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2010,7 +2022,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2024,7 +2036,7 @@ def get_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2116,8 +2128,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2126,7 +2142,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2135,7 +2153,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2149,7 +2167,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2242,8 +2260,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2252,7 +2274,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2261,7 +2285,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2275,7 +2299,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2306,8 +2330,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2316,7 +2344,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2325,7 +2355,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2339,7 +2369,7 @@ def test_iam_permissions( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2365,8 +2395,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2375,7 +2409,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2384,7 +2418,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/README.rst b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/README.rst index aaeaceacf025..bfbee387bee8 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/README.rst +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`FunctionServiceTransport` is the ABC for all transports. -- public child `FunctionServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `FunctionServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseFunctionServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `FunctionServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``FunctionServiceTransport`` is the ABC for all transports. + +- public child ``FunctionServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``FunctionServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseFunctionServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``FunctionServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py index 29953094aebc..056e1f84131b 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py index 03ecd4468196..9bc68305893d 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py index 516347fbe416..55f842d89f03 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py index 4961363d0138..fb71564f4f35 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py @@ -749,6 +749,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[FunctionServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-functions/noxfile.py b/packages/google-cloud-functions/noxfile.py index 5eeaa2c429f6..26158518c308 100644 --- a/packages/google-cloud-functions/noxfile.py +++ b/packages/google-cloud-functions/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-functions/setup.py b/packages/google-cloud-functions/setup.py index befc59882915..e58d47a024dc 100644 --- a/packages/google-cloud-functions/setup.py +++ b/packages/google-cloud-functions/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-functions/testing/constraints-3.7.txt b/packages/google-cloud-functions/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-functions/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-functions/testing/constraints-3.8.txt b/packages/google-cloud-functions/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-functions/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-functions/testing/constraints-3.9.txt b/packages/google-cloud-functions/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-functions/testing/constraints-3.9.txt +++ b/packages/google-cloud-functions/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py b/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py index 89ffb1ba10d7..1b8f00714358 100644 --- a/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py +++ b/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py @@ -138,6 +138,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudFunctionsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -160,6 +161,10 @@ def test__get_default_mtls_endpoint(): CloudFunctionsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudFunctionsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1361,11 +1366,13 @@ def test_cloud_functions_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7062,8 +7069,9 @@ def test_list_functions_rest_bad_request(request_type=functions.ListFunctionsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7128,18 +7136,20 @@ def test_list_functions_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_list_functions" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_list_functions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_list_functions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_list_functions" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_list_functions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_list_functions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7190,8 +7200,9 @@ def test_get_function_rest_bad_request(request_type=functions.GetFunctionRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7305,18 +7316,20 @@ def test_get_function_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_get_function" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_get_function_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_get_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_get_function" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_get_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_get_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7365,8 +7378,9 @@ def test_create_function_rest_bad_request(request_type=functions.CreateFunctionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7547,20 +7561,21 @@ def test_create_function_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_create_function" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_create_function_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_create_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_create_function" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_create_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_create_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7613,8 +7628,9 @@ def test_update_function_rest_bad_request(request_type=functions.UpdateFunctionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7797,20 +7813,21 @@ def test_update_function_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_update_function" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_update_function_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_update_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_update_function" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_update_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_update_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7861,8 +7878,9 @@ def test_delete_function_rest_bad_request(request_type=functions.DeleteFunctionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7919,20 +7937,21 @@ def test_delete_function_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_delete_function" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_delete_function_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_delete_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_delete_function" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_delete_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_delete_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7983,8 +8002,9 @@ def test_call_function_rest_bad_request(request_type=functions.CallFunctionReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8051,18 +8071,20 @@ def test_call_function_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_call_function" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_call_function_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_call_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_call_function" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_call_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_call_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8115,8 +8137,9 @@ def test_generate_upload_url_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8179,18 +8202,20 @@ def test_generate_upload_url_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_generate_upload_url" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_generate_upload_url_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_generate_upload_url" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_generate_upload_url" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_generate_upload_url_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_generate_upload_url" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8248,8 +8273,9 @@ def test_generate_download_url_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8312,18 +8338,21 @@ def test_generate_download_url_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_generate_download_url" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_generate_download_url_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_generate_download_url" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_generate_download_url", + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_generate_download_url_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_generate_download_url" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8381,8 +8410,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8444,18 +8474,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8506,8 +8538,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8569,18 +8602,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8631,8 +8666,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8692,18 +8728,20 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = CloudFunctionsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "post_test_iam_permissions" - ) as post, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudFunctionsServiceRestInterceptor, "pre_test_iam_permissions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "post_test_iam_permissions" + ) as post, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudFunctionsServiceRestInterceptor, "pre_test_iam_permissions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8759,8 +8797,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8819,8 +8858,9 @@ def test_get_operation_rest_bad_request( request = json_format.ParseDict({"name": "operations/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8879,8 +8919,9 @@ def test_list_operations_rest_bad_request( request = json_format.ParseDict({}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9249,11 +9290,14 @@ def test_cloud_functions_service_base_transport(): def test_cloud_functions_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudFunctionsServiceTransport( @@ -9270,9 +9314,12 @@ def test_cloud_functions_service_base_transport_with_credentials_file(): def test_cloud_functions_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudFunctionsServiceTransport() @@ -9346,11 +9393,12 @@ def test_cloud_functions_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10046,6 +10094,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudFunctionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudFunctionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudFunctionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10191,6 +10273,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudFunctionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudFunctionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CloudFunctionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10336,6 +10452,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudFunctionsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudFunctionsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_transport_close_grpc(): client = CloudFunctionsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py b/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py index c8c017eed270..7b9478d387b0 100644 --- a/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py +++ b/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert FunctionServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): assert ( FunctionServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + FunctionServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1318,11 +1323,13 @@ def test_function_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5996,8 +6003,9 @@ def test_get_function_rest_bad_request(request_type=functions.GetFunctionRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6072,17 +6080,19 @@ def test_get_function_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_get_function" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_get_function_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_get_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_get_function" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_get_function_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_get_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6131,8 +6141,9 @@ def test_list_functions_rest_bad_request(request_type=functions.ListFunctionsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6197,17 +6208,20 @@ def test_list_functions_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_list_functions" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_list_functions_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_list_functions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_list_functions" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_list_functions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_list_functions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6258,8 +6272,9 @@ def test_create_function_rest_bad_request(request_type=functions.CreateFunctionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6485,19 +6500,21 @@ def test_create_function_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_create_function" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_create_function_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_create_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_create_function" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_create_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_create_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6550,8 +6567,9 @@ def test_update_function_rest_bad_request(request_type=functions.UpdateFunctionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6779,19 +6797,21 @@ def test_update_function_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_update_function" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_update_function_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_update_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_update_function" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_update_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_update_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6842,8 +6862,9 @@ def test_delete_function_rest_bad_request(request_type=functions.DeleteFunctionR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6900,19 +6921,21 @@ def test_delete_function_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_delete_function" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_delete_function_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_delete_function" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_delete_function" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_delete_function_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_delete_function" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6965,8 +6988,9 @@ def test_generate_upload_url_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7029,18 +7053,20 @@ def test_generate_upload_url_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_generate_upload_url" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, - "post_generate_upload_url_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_generate_upload_url" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_generate_upload_url" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_generate_upload_url_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_generate_upload_url" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7098,8 +7124,9 @@ def test_generate_download_url_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7162,18 +7189,20 @@ def test_generate_download_url_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_generate_download_url" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, - "post_generate_download_url_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_generate_download_url" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_generate_download_url" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_generate_download_url_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_generate_download_url" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7229,8 +7258,9 @@ def test_list_runtimes_rest_bad_request(request_type=functions.ListRuntimesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7290,17 +7320,20 @@ def test_list_runtimes_rest_interceptors(null_interceptor): ) client = FunctionServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_list_runtimes" - ) as post, mock.patch.object( - transports.FunctionServiceRestInterceptor, "post_list_runtimes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.FunctionServiceRestInterceptor, "pre_list_runtimes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "post_list_runtimes" + ) as post, + mock.patch.object( + transports.FunctionServiceRestInterceptor, + "post_list_runtimes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.FunctionServiceRestInterceptor, "pre_list_runtimes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7353,8 +7386,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7415,8 +7449,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7477,8 +7512,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7539,8 +7575,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7601,8 +7638,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7663,8 +7701,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7971,11 +8010,14 @@ def test_function_service_base_transport(): def test_function_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.functions_v2.services.function_service.transports.FunctionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.functions_v2.services.function_service.transports.FunctionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FunctionServiceTransport( @@ -7992,9 +8034,12 @@ def test_function_service_base_transport_with_credentials_file(): def test_function_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.functions_v2.services.function_service.transports.FunctionServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.functions_v2.services.function_service.transports.FunctionServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FunctionServiceTransport() @@ -8066,11 +8111,12 @@ def test_function_service_transport_auth_gdch_credentials(transport_class): def test_function_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8934,6 +8980,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = FunctionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = FunctionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = FunctionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9079,6 +9159,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = FunctionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = FunctionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = FunctionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9224,6 +9338,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = FunctionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = FunctionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = FunctionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9388,6 +9536,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = FunctionServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = FunctionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = FunctionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9555,6 +9738,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = FunctionServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = FunctionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = FunctionServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9732,6 +9950,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = FunctionServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = FunctionServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = FunctionServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py index e8dd7214dcae..be7b4e698d89 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> GDCHardwareManagementTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5200,7 +5200,7 @@ async def sample_request_order_date_change(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5226,8 +5226,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5236,7 +5240,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5244,7 +5248,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5255,7 +5259,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5281,8 +5285,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5291,7 +5299,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5299,7 +5307,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5310,7 +5318,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5340,8 +5348,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5350,7 +5362,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5358,7 +5370,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5366,7 +5378,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5395,8 +5407,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5405,7 +5421,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5413,7 +5429,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5421,7 +5437,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5447,8 +5463,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5457,7 +5477,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5465,7 +5485,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5476,7 +5496,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5502,8 +5522,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5512,7 +5536,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5520,7 +5544,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py index 6430f3e7144f..0f1246cc53ef 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/client.py @@ -120,7 +120,7 @@ class GDCHardwareManagementClient(metaclass=GDCHardwareManagementClientMeta): """The GDC Hardware Management service.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -605,7 +609,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -704,7 +708,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -804,7 +808,7 @@ def __init__( self._universe_domain = GDCHardwareManagementClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5679,7 +5683,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5705,8 +5709,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5715,7 +5723,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5724,7 +5732,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5738,7 +5746,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5764,8 +5772,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5774,7 +5786,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5783,7 +5795,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5797,7 +5809,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5827,8 +5839,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5837,7 +5853,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5845,7 +5861,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5853,7 +5869,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5882,8 +5898,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5892,7 +5912,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5900,7 +5920,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5908,7 +5928,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5934,8 +5954,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5944,7 +5968,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5953,7 +5977,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5967,7 +5991,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5993,8 +6017,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6003,7 +6031,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6012,7 +6040,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/README.rst b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/README.rst index d95d5f9c40cd..6ed12a9c7e79 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/README.rst +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GDCHardwareManagementTransport` is the ABC for all transports. -- public child `GDCHardwareManagementGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GDCHardwareManagementGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGDCHardwareManagementRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GDCHardwareManagementRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GDCHardwareManagementTransport`` is the ABC for all transports. + +- public child ``GDCHardwareManagementGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GDCHardwareManagementGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGDCHardwareManagementRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GDCHardwareManagementRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py index 3de3bc85c133..69a5d0163eb9 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py index 1f99b5a2eec1..5f6f4f4a761c 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py index fb971f8aad19..407855fd020c 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py index 6bab872ba9d7..2f49ad3ed7cd 100644 --- a/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py +++ b/packages/google-cloud-gdchardwaremanagement/google/cloud/gdchardwaremanagement_v1alpha/services/gdc_hardware_management/transports/rest.py @@ -2299,6 +2299,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GDCHardwareManagementRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gdchardwaremanagement/noxfile.py b/packages/google-cloud-gdchardwaremanagement/noxfile.py index fd22446c5e80..4b66ce08225c 100644 --- a/packages/google-cloud-gdchardwaremanagement/noxfile.py +++ b/packages/google-cloud-gdchardwaremanagement/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gdchardwaremanagement/setup.py b/packages/google-cloud-gdchardwaremanagement/setup.py index 1a792b7602c3..64d7671ebac6 100644 --- a/packages/google-cloud-gdchardwaremanagement/setup.py +++ b/packages/google-cloud-gdchardwaremanagement/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-gdchardwaremanagement" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.7.txt b/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.8.txt b/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.9.txt b/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.9.txt +++ b/packages/google-cloud-gdchardwaremanagement/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py b/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py index 25290653cde4..f65b36a47c3d 100644 --- a/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py +++ b/packages/google-cloud-gdchardwaremanagement/tests/unit/gapic/gdchardwaremanagement_v1alpha/test_gdc_hardware_management.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GDCHardwareManagementClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): GDCHardwareManagementClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GDCHardwareManagementClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1356,11 +1361,13 @@ def test_gdc_hardware_management_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -25097,8 +25104,9 @@ def test_list_orders_rest_bad_request(request_type=service.ListOrdersRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25163,18 +25171,20 @@ def test_list_orders_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_orders" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_list_orders_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_orders" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_orders" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_orders_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_orders" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25223,8 +25233,9 @@ def test_get_order_rest_bad_request(request_type=service.GetOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25309,17 +25320,20 @@ def test_get_order_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_order" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_order_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_order" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25368,8 +25382,9 @@ def test_create_order_rest_bad_request(request_type=service.CreateOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25564,20 +25579,21 @@ def test_create_order_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_order" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_create_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_order" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_create_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25628,8 +25644,9 @@ def test_update_order_rest_bad_request(request_type=service.UpdateOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25826,20 +25843,21 @@ def test_update_order_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_order" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_update_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_update_order" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_update_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_update_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25888,8 +25906,9 @@ def test_delete_order_rest_bad_request(request_type=service.DeleteOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25946,20 +25965,21 @@ def test_delete_order_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_order" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_delete_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_delete_order" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_delete_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_delete_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26008,8 +26028,9 @@ def test_submit_order_rest_bad_request(request_type=service.SubmitOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26066,20 +26087,21 @@ def test_submit_order_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_submit_order" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_submit_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_submit_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_submit_order" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_submit_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_submit_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26128,8 +26150,9 @@ def test_cancel_order_rest_bad_request(request_type=service.CancelOrderRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26186,20 +26209,21 @@ def test_cancel_order_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_cancel_order" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_cancel_order_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_cancel_order" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_cancel_order" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_cancel_order_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_cancel_order" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26248,8 +26272,9 @@ def test_list_sites_rest_bad_request(request_type=service.ListSitesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26314,17 +26339,20 @@ def test_list_sites_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_sites" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_sites_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_sites" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_sites" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_sites_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_sites" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26373,8 +26401,9 @@ def test_get_site_rest_bad_request(request_type=service.GetSiteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26447,17 +26476,20 @@ def test_get_site_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_site" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_site_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_site" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26506,8 +26538,9 @@ def test_create_site_rest_bad_request(request_type=service.CreateSiteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26681,20 +26714,21 @@ def test_create_site_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_site" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_create_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_site" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_create_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26745,8 +26779,9 @@ def test_update_site_rest_bad_request(request_type=service.UpdateSiteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26922,20 +26957,21 @@ def test_update_site_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_site" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_update_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_update_site" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_update_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_update_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26984,8 +27020,9 @@ def test_delete_site_rest_bad_request(request_type=service.DeleteSiteRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27042,20 +27079,21 @@ def test_delete_site_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_site" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_delete_site_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_site" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_delete_site" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_delete_site_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_delete_site" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27106,8 +27144,9 @@ def test_list_hardware_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27172,18 +27211,20 @@ def test_list_hardware_groups_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_hardware_groups" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_list_hardware_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_hardware_groups" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_hardware_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27240,8 +27281,9 @@ def test_get_hardware_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27314,18 +27356,20 @@ def test_get_hardware_group_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_hardware_group" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_get_hardware_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_hardware_group" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_hardware_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27378,8 +27422,9 @@ def test_create_hardware_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27519,20 +27564,22 @@ def test_create_hardware_group_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_hardware_group" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_create_hardware_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_hardware_group", + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_hardware_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27589,8 +27636,9 @@ def test_update_hardware_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27734,20 +27782,22 @@ def test_update_hardware_group_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_hardware_group" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_update_hardware_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_update_hardware_group", + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_update_hardware_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27802,8 +27852,9 @@ def test_delete_hardware_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27862,20 +27913,22 @@ def test_delete_hardware_group_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware_group" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_delete_hardware_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_delete_hardware_group", + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_delete_hardware_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27926,8 +27979,9 @@ def test_list_hardware_rest_bad_request(request_type=service.ListHardwareRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27992,18 +28046,20 @@ def test_list_hardware_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_hardware" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_list_hardware_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_hardware" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_hardware_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_hardware" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28054,8 +28110,9 @@ def test_get_hardware_rest_bad_request(request_type=service.GetHardwareRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28132,18 +28189,20 @@ def test_get_hardware_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_hardware" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_get_hardware_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_hardware" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_hardware_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_hardware" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28192,8 +28251,9 @@ def test_create_hardware_rest_bad_request(request_type=service.CreateHardwareReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28380,20 +28440,21 @@ def test_create_hardware_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_hardware" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_create_hardware_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_hardware" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_hardware_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_create_hardware" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28444,8 +28505,9 @@ def test_update_hardware_rest_bad_request(request_type=service.UpdateHardwareReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28634,20 +28696,21 @@ def test_update_hardware_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_hardware" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_update_hardware_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_update_hardware" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_update_hardware_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_update_hardware" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28696,8 +28759,9 @@ def test_delete_hardware_rest_bad_request(request_type=service.DeleteHardwareReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28754,20 +28818,21 @@ def test_delete_hardware_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_delete_hardware_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_delete_hardware" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_delete_hardware_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_delete_hardware" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28816,8 +28881,9 @@ def test_list_comments_rest_bad_request(request_type=service.ListCommentsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28882,18 +28948,20 @@ def test_list_comments_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_comments" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_list_comments_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_comments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_comments" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_comments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_comments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28946,8 +29014,9 @@ def test_get_comment_rest_bad_request(request_type=service.GetCommentRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29018,18 +29087,20 @@ def test_get_comment_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_comment" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_get_comment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_comment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_comment" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_comment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_comment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29078,8 +29149,9 @@ def test_create_comment_rest_bad_request(request_type=service.CreateCommentReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29212,20 +29284,21 @@ def test_create_comment_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_comment" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_create_comment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_comment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_comment" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_comment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_create_comment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29278,8 +29351,9 @@ def test_record_action_on_comment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29350,18 +29424,22 @@ def test_record_action_on_comment_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_record_action_on_comment" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_record_action_on_comment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_record_action_on_comment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_record_action_on_comment", + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_record_action_on_comment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "pre_record_action_on_comment", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29414,8 +29492,9 @@ def test_list_change_log_entries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29480,18 +29559,22 @@ def test_list_change_log_entries_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_change_log_entries" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_list_change_log_entries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_change_log_entries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_change_log_entries", + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_change_log_entries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "pre_list_change_log_entries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29551,8 +29634,9 @@ def test_get_change_log_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29619,18 +29703,20 @@ def test_get_change_log_entry_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_change_log_entry" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_get_change_log_entry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_change_log_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_change_log_entry" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_change_log_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_change_log_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29681,8 +29767,9 @@ def test_list_skus_rest_bad_request(request_type=service.ListSkusRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29747,17 +29834,20 @@ def test_list_skus_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_skus" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_skus_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_skus" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_skus" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_skus_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_skus" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29806,8 +29896,9 @@ def test_get_sku_rest_bad_request(request_type=service.GetSkuRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29882,17 +29973,20 @@ def test_get_sku_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_sku" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_sku_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_sku" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_sku" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_sku_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_sku" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29941,8 +30035,9 @@ def test_list_zones_rest_bad_request(request_type=service.ListZonesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30007,17 +30102,20 @@ def test_list_zones_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_zones" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_list_zones_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_list_zones" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_list_zones" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_list_zones_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_list_zones" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30066,8 +30164,9 @@ def test_get_zone_rest_bad_request(request_type=service.GetZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30149,17 +30248,20 @@ def test_get_zone_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_zone" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_get_zone_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_get_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_get_zone" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_get_zone_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_get_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30208,8 +30310,9 @@ def test_create_zone_rest_bad_request(request_type=service.CreateZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30390,20 +30493,21 @@ def test_create_zone_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_create_zone" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_create_zone_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_create_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_create_zone" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_create_zone_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_create_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30454,8 +30558,9 @@ def test_update_zone_rest_bad_request(request_type=service.UpdateZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30638,20 +30743,21 @@ def test_update_zone_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_update_zone" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_update_zone_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_update_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_update_zone" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_update_zone_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_update_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30700,8 +30806,9 @@ def test_delete_zone_rest_bad_request(request_type=service.DeleteZoneRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30758,20 +30865,21 @@ def test_delete_zone_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_delete_zone" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_delete_zone_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_delete_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_delete_zone" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_delete_zone_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_delete_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30822,8 +30930,9 @@ def test_signal_zone_state_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30880,20 +30989,21 @@ def test_signal_zone_state_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "post_signal_zone_state" - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_signal_zone_state_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_signal_zone_state" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "post_signal_zone_state" + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_signal_zone_state_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, "pre_signal_zone_state" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30944,8 +31054,9 @@ def test_request_order_date_change_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31002,21 +31113,23 @@ def test_request_order_date_change_rest_interceptors(null_interceptor): ) client = GDCHardwareManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_request_order_date_change", - ) as post, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, - "post_request_order_date_change_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GDCHardwareManagementRestInterceptor, "pre_request_order_date_change" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_request_order_date_change", + ) as post, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "post_request_order_date_change_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GDCHardwareManagementRestInterceptor, + "pre_request_order_date_change", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31069,8 +31182,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31129,8 +31243,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31191,8 +31306,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31253,8 +31369,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31315,8 +31432,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -31377,8 +31495,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -32310,11 +32429,14 @@ def test_gdc_hardware_management_base_transport(): def test_gdc_hardware_management_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gdchardwaremanagement_v1alpha.services.gdc_hardware_management.transports.GDCHardwareManagementTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gdchardwaremanagement_v1alpha.services.gdc_hardware_management.transports.GDCHardwareManagementTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GDCHardwareManagementTransport( @@ -32331,9 +32453,12 @@ def test_gdc_hardware_management_base_transport_with_credentials_file(): def test_gdc_hardware_management_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gdchardwaremanagement_v1alpha.services.gdc_hardware_management.transports.GDCHardwareManagementTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gdchardwaremanagement_v1alpha.services.gdc_hardware_management.transports.GDCHardwareManagementTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GDCHardwareManagementTransport() @@ -32407,11 +32532,12 @@ def test_gdc_hardware_management_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -33313,6 +33439,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33452,6 +33610,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33597,6 +33787,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33742,6 +33966,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -33887,6 +34145,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -34030,6 +34322,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GDCHardwareManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GDCHardwareManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = GDCHardwareManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/async_client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/async_client.py index 9ad0a4f0dec3..c97c95c9f1f3 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/async_client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> DataAgentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1730,7 +1730,7 @@ async def sample_set_iam_policy(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1756,8 +1756,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1766,7 +1770,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1774,7 +1778,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1785,7 +1789,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1811,8 +1815,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1821,7 +1829,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1829,7 +1837,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1840,7 +1848,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1870,8 +1878,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1880,7 +1892,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1888,7 +1900,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1896,7 +1908,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1925,8 +1937,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1935,7 +1951,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1943,7 +1959,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1951,7 +1967,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1977,8 +1993,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1987,7 +2007,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1995,7 +2015,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2006,7 +2026,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2032,8 +2052,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2042,7 +2066,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2050,7 +2074,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/client.py index 2b1805c4642c..4828c07805b5 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/client.py @@ -124,7 +124,7 @@ class DataAgentServiceClient(metaclass=DataAgentServiceClientMeta): """Service describing handlers for resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -546,7 +550,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = DataAgentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2151,7 +2155,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2177,8 +2181,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2187,7 +2195,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2196,7 +2204,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2210,7 +2218,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2236,8 +2244,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2246,7 +2258,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2255,7 +2267,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2269,7 +2281,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2299,8 +2311,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2309,7 +2325,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2317,7 +2333,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2325,7 +2341,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2354,8 +2370,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2364,7 +2384,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2372,7 +2392,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2380,7 +2400,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2406,8 +2426,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2416,7 +2440,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2425,7 +2449,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2439,7 +2463,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2465,8 +2489,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2475,7 +2503,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2484,7 +2512,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/README.rst b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/README.rst index b56655e7b17d..667c1c5f4dec 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/README.rst +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataAgentServiceTransport` is the ABC for all transports. -- public child `DataAgentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataAgentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataAgentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataAgentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataAgentServiceTransport`` is the ABC for all transports. + +- public child ``DataAgentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataAgentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataAgentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataAgentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/base.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/base.py index 1bf10b8b6d8f..8ff604b9f054 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/base.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc.py index bf83e1233c7b..ad7a7783a9bb 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc_asyncio.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc_asyncio.py index 4e1418cf90b1..792a97b7ccb1 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/rest.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/rest.py index 3506c939e563..5c8a2c06c76f 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/rest.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_agent_service/transports/rest.py @@ -888,6 +888,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataAgentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/async_client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/async_client.py index fbbc7e00e4a7..7655ebceba74 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/async_client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> DataChatServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1092,7 +1092,7 @@ async def sample_query_data(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1118,8 +1118,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1128,7 +1132,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1136,7 +1140,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1147,7 +1151,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1173,8 +1177,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1183,7 +1191,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1191,7 +1199,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1202,7 +1210,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1232,8 +1240,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1242,7 +1254,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1250,7 +1262,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1258,7 +1270,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1287,8 +1299,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1297,7 +1313,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1305,7 +1321,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1313,7 +1329,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1339,8 +1355,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1349,7 +1369,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1357,7 +1377,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1368,7 +1388,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1394,8 +1414,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1404,7 +1428,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1412,7 +1436,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/client.py index 436996facaf8..0a48982c9c05 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/client.py @@ -123,7 +123,7 @@ class DataChatServiceClient(metaclass=DataChatServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -470,7 +474,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = DataChatServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1535,7 +1539,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1561,8 +1565,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1571,7 +1579,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1580,7 +1588,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1594,7 +1602,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1620,8 +1628,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1630,7 +1642,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1639,7 +1651,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1653,7 +1665,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1683,8 +1695,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1693,7 +1709,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1701,7 +1717,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1709,7 +1725,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1738,8 +1754,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1748,7 +1768,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1756,7 +1776,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1764,7 +1784,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1790,8 +1810,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1800,7 +1824,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1809,7 +1833,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1823,7 +1847,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1849,8 +1873,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1859,7 +1887,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1868,7 +1896,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/README.rst b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/README.rst index 79624d124af2..bd5c50295f27 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/README.rst +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataChatServiceTransport` is the ABC for all transports. -- public child `DataChatServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataChatServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataChatServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataChatServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataChatServiceTransport`` is the ABC for all transports. + +- public child ``DataChatServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataChatServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataChatServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataChatServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/base.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/base.py index f805c1214b57..92aa70e46f7b 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/base.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc.py index fc4592e93703..94f75a5a3b8a 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc_asyncio.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc_asyncio.py index 42f54d79accf..1a75625af713 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/rest.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/rest.py index 9ab4154c447d..dc12687e9268 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/rest.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1alpha/services/data_chat_service/transports/rest.py @@ -663,6 +663,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataChatServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/async_client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/async_client.py index 282a0373aa2f..b2df4dae88ae 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/async_client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/async_client.py @@ -200,7 +200,7 @@ def transport(self) -> DataAgentServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1730,7 +1730,7 @@ async def sample_set_iam_policy(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1756,8 +1756,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1766,7 +1770,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1774,7 +1778,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1785,7 +1789,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1811,8 +1815,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1821,7 +1829,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1829,7 +1837,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1840,7 +1848,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1870,8 +1878,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1880,7 +1892,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1888,7 +1900,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1896,7 +1908,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1925,8 +1937,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1935,7 +1951,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1943,7 +1959,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1951,7 +1967,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1977,8 +1993,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1987,7 +2007,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1995,7 +2015,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2006,7 +2026,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2032,8 +2052,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2042,7 +2066,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2050,7 +2074,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/client.py index c473386e883e..495b0f906855 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/client.py @@ -124,7 +124,7 @@ class DataAgentServiceClient(metaclass=DataAgentServiceClientMeta): """Service describing handlers for resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -546,7 +550,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -644,7 +648,7 @@ def __init__( self._universe_domain = DataAgentServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2151,7 +2155,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2177,8 +2181,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2187,7 +2195,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2196,7 +2204,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2210,7 +2218,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2236,8 +2244,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2246,7 +2258,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2255,7 +2267,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2269,7 +2281,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2299,8 +2311,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2309,7 +2325,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2317,7 +2333,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2325,7 +2341,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2354,8 +2370,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2364,7 +2384,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2372,7 +2392,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2380,7 +2400,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2406,8 +2426,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2416,7 +2440,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2425,7 +2449,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2439,7 +2463,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2465,8 +2489,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2475,7 +2503,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2484,7 +2512,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/README.rst b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/README.rst index b56655e7b17d..667c1c5f4dec 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/README.rst +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataAgentServiceTransport` is the ABC for all transports. -- public child `DataAgentServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataAgentServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataAgentServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataAgentServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataAgentServiceTransport`` is the ABC for all transports. + +- public child ``DataAgentServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataAgentServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataAgentServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataAgentServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/base.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/base.py index 8bd2d14cb878..834d4e380f24 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/base.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc.py index 271c27a5a487..d481f5afc99c 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc_asyncio.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc_asyncio.py index 3b6a45a5349f..5655b280477a 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/rest.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/rest.py index e9284fbb0062..6eea3275441c 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/rest.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_agent_service/transports/rest.py @@ -885,6 +885,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataAgentServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/async_client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/async_client.py index a3c5c76b276a..f1182eb79615 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/async_client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> DataChatServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1092,7 +1092,7 @@ async def sample_query_data(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1118,8 +1118,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1128,7 +1132,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1136,7 +1140,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1147,7 +1151,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1173,8 +1177,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1183,7 +1191,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1191,7 +1199,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1202,7 +1210,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1232,8 +1240,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1242,7 +1254,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1250,7 +1262,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1258,7 +1270,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1287,8 +1299,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1297,7 +1313,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1305,7 +1321,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1313,7 +1329,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1339,8 +1355,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1349,7 +1369,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1357,7 +1377,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1368,7 +1388,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1394,8 +1414,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1404,7 +1428,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1412,7 +1436,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/client.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/client.py index 5ecfd88da76a..5ba17bce3e93 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/client.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/client.py @@ -123,7 +123,7 @@ class DataChatServiceClient(metaclass=DataChatServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -470,7 +474,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = DataChatServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1535,7 +1539,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1561,8 +1565,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1571,7 +1579,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1580,7 +1588,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1594,7 +1602,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1620,8 +1628,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1630,7 +1642,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1639,7 +1651,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1653,7 +1665,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1683,8 +1695,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1693,7 +1709,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1701,7 +1717,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1709,7 +1725,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1738,8 +1754,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1748,7 +1768,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1756,7 +1776,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1764,7 +1784,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1790,8 +1810,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1800,7 +1824,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1809,7 +1833,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1823,7 +1847,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1849,8 +1873,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1859,7 +1887,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1868,7 +1896,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/README.rst b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/README.rst index 79624d124af2..bd5c50295f27 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/README.rst +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataChatServiceTransport` is the ABC for all transports. -- public child `DataChatServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataChatServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataChatServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataChatServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataChatServiceTransport`` is the ABC for all transports. + +- public child ``DataChatServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataChatServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataChatServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataChatServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/base.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/base.py index 10147c4db8f4..74ac51cd7fe3 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/base.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc.py index f0e10c6ad02a..b24abf8511e4 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc_asyncio.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc_asyncio.py index 0ca93a1bdfa3..687ad04eda09 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/rest.py b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/rest.py index 8ecd080712d8..469d0a3fc35c 100644 --- a/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/rest.py +++ b/packages/google-cloud-geminidataanalytics/google/cloud/geminidataanalytics_v1beta/services/data_chat_service/transports/rest.py @@ -663,6 +663,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DataChatServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-geminidataanalytics/noxfile.py b/packages/google-cloud-geminidataanalytics/noxfile.py index e6d6329e34bd..6682fffcb476 100644 --- a/packages/google-cloud-geminidataanalytics/noxfile.py +++ b/packages/google-cloud-geminidataanalytics/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-geminidataanalytics/setup.py b/packages/google-cloud-geminidataanalytics/setup.py index 33e31eef23e8..0dc75b57d1e8 100644 --- a/packages/google-cloud-geminidataanalytics/setup.py +++ b/packages/google-cloud-geminidataanalytics/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-geminidataanalytics/testing/constraints-3.7.txt b/packages/google-cloud-geminidataanalytics/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-geminidataanalytics/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-geminidataanalytics/testing/constraints-3.8.txt b/packages/google-cloud-geminidataanalytics/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-geminidataanalytics/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-geminidataanalytics/testing/constraints-3.9.txt b/packages/google-cloud-geminidataanalytics/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-geminidataanalytics/testing/constraints-3.9.txt +++ b/packages/google-cloud-geminidataanalytics/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_agent_service.py b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_agent_service.py index 283608ef3f0d..9d6e42f528d0 100644 --- a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_agent_service.py +++ b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_agent_service.py @@ -142,6 +142,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataAgentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -164,6 +165,10 @@ def test__get_default_mtls_endpoint(): DataAgentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataAgentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1333,11 +1338,13 @@ def test_data_agent_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8718,8 +8725,9 @@ def test_list_data_agents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8784,18 +8792,20 @@ def test_list_data_agents_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_list_data_agents" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_list_data_agents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_list_data_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_list_data_agents" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_list_data_agents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_list_data_agents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8853,8 +8863,9 @@ def test_list_accessible_data_agents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8921,18 +8932,22 @@ def test_list_accessible_data_agents_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_list_accessible_data_agents" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_list_accessible_data_agents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_list_accessible_data_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_list_accessible_data_agents", + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_list_accessible_data_agents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "pre_list_accessible_data_agents", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8990,8 +9005,9 @@ def test_get_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9058,17 +9074,20 @@ def test_get_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_data_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_get_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_get_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_get_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_get_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9121,8 +9140,9 @@ def test_create_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9412,20 +9432,21 @@ def test_create_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_create_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_create_data_agent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_create_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_create_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_create_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_create_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9478,8 +9499,9 @@ def test_create_data_agent_sync_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9779,18 +9801,20 @@ def test_create_data_agent_sync_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_create_data_agent_sync" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_create_data_agent_sync_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_create_data_agent_sync" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_create_data_agent_sync" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_create_data_agent_sync_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_create_data_agent_sync" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9845,8 +9869,9 @@ def test_update_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10138,20 +10163,21 @@ def test_update_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_update_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_update_data_agent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_update_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_update_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_update_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_update_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10206,8 +10232,9 @@ def test_update_data_agent_sync_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10509,18 +10536,20 @@ def test_update_data_agent_sync_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_update_data_agent_sync" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_update_data_agent_sync_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_update_data_agent_sync" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_update_data_agent_sync" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_update_data_agent_sync_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_update_data_agent_sync" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10573,8 +10602,9 @@ def test_delete_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10631,20 +10661,21 @@ def test_delete_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_delete_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_delete_data_agent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_delete_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_delete_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10697,8 +10728,9 @@ def test_delete_data_agent_sync_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10755,13 +10787,13 @@ def test_delete_data_agent_sync_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent_sync" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent_sync" + ) as pre, + ): pre.assert_not_called() pb_message = data_agent_service.DeleteDataAgentRequest.pb( data_agent_service.DeleteDataAgentRequest() @@ -10806,8 +10838,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10869,17 +10902,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10930,8 +10966,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10993,17 +11030,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11054,8 +11094,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11114,8 +11155,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11176,8 +11218,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11238,8 +11281,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11300,8 +11344,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11362,8 +11407,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11743,11 +11789,14 @@ def test_data_agent_service_base_transport(): def test_data_agent_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.geminidataanalytics_v1alpha.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.geminidataanalytics_v1alpha.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataAgentServiceTransport( @@ -11764,9 +11813,12 @@ def test_data_agent_service_base_transport_with_credentials_file(): def test_data_agent_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.geminidataanalytics_v1alpha.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.geminidataanalytics_v1alpha.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataAgentServiceTransport() @@ -11838,11 +11890,12 @@ def test_data_agent_service_transport_auth_gdch_credentials(transport_class): def test_data_agent_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12469,6 +12522,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12608,6 +12693,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12753,6 +12870,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12898,6 +13049,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13043,6 +13228,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13184,6 +13403,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_chat_service.py b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_chat_service.py index b57f7633598f..95f3a7616d9d 100644 --- a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_chat_service.py +++ b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1alpha/test_data_chat_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataChatServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( DataChatServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataChatServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1319,11 +1324,13 @@ def test_data_chat_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5770,8 +5777,9 @@ def test_chat_rest_bad_request(request_type=data_chat_service.ChatRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5838,17 +5846,17 @@ def test_chat_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_chat" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_chat_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_chat" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_chat" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_chat_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataChatServiceRestInterceptor, "pre_chat") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5899,8 +5907,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6039,18 +6048,20 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_create_conversation" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_create_conversation" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_create_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6105,8 +6116,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6163,13 +6175,13 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_delete_conversation" + ) as pre, + ): pre.assert_not_called() pb_message = conversation.DeleteConversationRequest.pb( conversation.DeleteConversationRequest() @@ -6214,8 +6226,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6280,17 +6293,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_get_conversation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6343,8 +6359,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6407,18 +6424,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6478,8 +6497,9 @@ def test_list_messages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6544,17 +6564,20 @@ def test_list_messages_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_list_messages" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_list_messages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_list_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_list_messages" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_list_messages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_list_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6610,8 +6633,9 @@ def test_query_data_rest_bad_request(request_type=data_chat_service.QueryDataReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6680,17 +6704,19 @@ def test_query_data_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_query_data" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_query_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_query_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_query_data" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_query_data_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_query_data" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6748,8 +6774,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6808,8 +6835,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6870,8 +6898,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6932,8 +6961,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6994,8 +7024,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7056,8 +7087,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7323,11 +7355,14 @@ def test_data_chat_service_base_transport(): def test_data_chat_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.geminidataanalytics_v1alpha.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.geminidataanalytics_v1alpha.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataChatServiceTransport( @@ -7344,9 +7379,12 @@ def test_data_chat_service_base_transport_with_credentials_file(): def test_data_chat_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.geminidataanalytics_v1alpha.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.geminidataanalytics_v1alpha.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataChatServiceTransport() @@ -7418,11 +7456,12 @@ def test_data_chat_service_transport_auth_gdch_credentials(transport_class): def test_data_chat_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8031,6 +8070,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8170,6 +8241,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8315,6 +8418,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8460,6 +8597,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8605,6 +8776,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8746,6 +8951,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_agent_service.py b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_agent_service.py index 9ae58f4eecb5..f5b8d56885c0 100644 --- a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_agent_service.py +++ b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_agent_service.py @@ -142,6 +142,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataAgentServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -164,6 +165,10 @@ def test__get_default_mtls_endpoint(): DataAgentServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataAgentServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1333,11 +1338,13 @@ def test_data_agent_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -8718,8 +8725,9 @@ def test_list_data_agents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8784,18 +8792,20 @@ def test_list_data_agents_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_list_data_agents" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_list_data_agents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_list_data_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_list_data_agents" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_list_data_agents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_list_data_agents" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8853,8 +8863,9 @@ def test_list_accessible_data_agents_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8921,18 +8932,22 @@ def test_list_accessible_data_agents_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_list_accessible_data_agents" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_list_accessible_data_agents_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_list_accessible_data_agents" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_list_accessible_data_agents", + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_list_accessible_data_agents_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "pre_list_accessible_data_agents", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8990,8 +9005,9 @@ def test_get_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9058,17 +9074,20 @@ def test_get_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_data_agent_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_get_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_get_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_get_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_get_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9121,8 +9140,9 @@ def test_create_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9412,20 +9432,21 @@ def test_create_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_create_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_create_data_agent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_create_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_create_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_create_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_create_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9478,8 +9499,9 @@ def test_create_data_agent_sync_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9779,18 +9801,20 @@ def test_create_data_agent_sync_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_create_data_agent_sync" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_create_data_agent_sync_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_create_data_agent_sync" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_create_data_agent_sync" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_create_data_agent_sync_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_create_data_agent_sync" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9845,8 +9869,9 @@ def test_update_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10138,20 +10163,21 @@ def test_update_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_update_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_update_data_agent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_update_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_update_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_update_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_update_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10206,8 +10232,9 @@ def test_update_data_agent_sync_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10509,18 +10536,20 @@ def test_update_data_agent_sync_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_update_data_agent_sync" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_update_data_agent_sync_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_update_data_agent_sync" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_update_data_agent_sync" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_update_data_agent_sync_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_update_data_agent_sync" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10573,8 +10602,9 @@ def test_delete_data_agent_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10631,20 +10661,21 @@ def test_delete_data_agent_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_delete_data_agent" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, - "post_delete_data_agent_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_delete_data_agent" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_delete_data_agent_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10697,8 +10728,9 @@ def test_delete_data_agent_sync_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10755,13 +10787,13 @@ def test_delete_data_agent_sync_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent_sync" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_delete_data_agent_sync" + ) as pre, + ): pre.assert_not_called() pb_message = data_agent_service.DeleteDataAgentRequest.pb( data_agent_service.DeleteDataAgentRequest() @@ -10806,8 +10838,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10869,17 +10902,20 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_get_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_get_iam_policy" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_get_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10930,8 +10966,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10993,17 +11030,20 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = DataAgentServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "post_set_iam_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataAgentServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "post_set_iam_policy" + ) as post, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataAgentServiceRestInterceptor, "pre_set_iam_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11054,8 +11094,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11114,8 +11155,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11176,8 +11218,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11238,8 +11281,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11300,8 +11344,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11362,8 +11407,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -11743,11 +11789,14 @@ def test_data_agent_service_base_transport(): def test_data_agent_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.geminidataanalytics_v1beta.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.geminidataanalytics_v1beta.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataAgentServiceTransport( @@ -11764,9 +11813,12 @@ def test_data_agent_service_base_transport_with_credentials_file(): def test_data_agent_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.geminidataanalytics_v1beta.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.geminidataanalytics_v1beta.services.data_agent_service.transports.DataAgentServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataAgentServiceTransport() @@ -11838,11 +11890,12 @@ def test_data_agent_service_transport_auth_gdch_credentials(transport_class): def test_data_agent_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12469,6 +12522,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12608,6 +12693,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12753,6 +12870,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -12898,6 +13049,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13043,6 +13228,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13184,6 +13403,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataAgentServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataAgentServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataAgentServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_chat_service.py b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_chat_service.py index 063af54c2f80..552a0b0d300f 100644 --- a/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_chat_service.py +++ b/packages/google-cloud-geminidataanalytics/tests/unit/gapic/geminidataanalytics_v1beta/test_data_chat_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DataChatServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -155,6 +156,10 @@ def test__get_default_mtls_endpoint(): assert ( DataChatServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DataChatServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1319,11 +1324,13 @@ def test_data_chat_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5770,8 +5777,9 @@ def test_chat_rest_bad_request(request_type=data_chat_service.ChatRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5838,17 +5846,17 @@ def test_chat_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_chat" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_chat_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_chat" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_chat" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_chat_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.DataChatServiceRestInterceptor, "pre_chat") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5899,8 +5907,9 @@ def test_create_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6039,18 +6048,20 @@ def test_create_conversation_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_create_conversation" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, - "post_create_conversation_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_create_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_create_conversation" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_create_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_create_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6105,8 +6116,9 @@ def test_delete_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6163,13 +6175,13 @@ def test_delete_conversation_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_delete_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_delete_conversation" + ) as pre, + ): pre.assert_not_called() pb_message = conversation.DeleteConversationRequest.pb( conversation.DeleteConversationRequest() @@ -6214,8 +6226,9 @@ def test_get_conversation_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6280,17 +6293,20 @@ def test_get_conversation_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_get_conversation" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_get_conversation_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_get_conversation" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_get_conversation" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_get_conversation_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_get_conversation" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6343,8 +6359,9 @@ def test_list_conversations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6407,18 +6424,20 @@ def test_list_conversations_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_list_conversations" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, - "post_list_conversations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_list_conversations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_list_conversations" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_list_conversations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_list_conversations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6478,8 +6497,9 @@ def test_list_messages_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6544,17 +6564,20 @@ def test_list_messages_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_list_messages" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_list_messages_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_list_messages" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_list_messages" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, + "post_list_messages_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_list_messages" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6610,8 +6633,9 @@ def test_query_data_rest_bad_request(request_type=data_chat_service.QueryDataReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6680,17 +6704,19 @@ def test_query_data_rest_interceptors(null_interceptor): ) client = DataChatServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_query_data" - ) as post, mock.patch.object( - transports.DataChatServiceRestInterceptor, "post_query_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DataChatServiceRestInterceptor, "pre_query_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_query_data" + ) as post, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "post_query_data_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.DataChatServiceRestInterceptor, "pre_query_data" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6748,8 +6774,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6808,8 +6835,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6870,8 +6898,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6932,8 +6961,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6994,8 +7024,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7056,8 +7087,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7323,11 +7355,14 @@ def test_data_chat_service_base_transport(): def test_data_chat_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.geminidataanalytics_v1beta.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.geminidataanalytics_v1beta.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataChatServiceTransport( @@ -7344,9 +7379,12 @@ def test_data_chat_service_base_transport_with_credentials_file(): def test_data_chat_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.geminidataanalytics_v1beta.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.geminidataanalytics_v1beta.services.data_chat_service.transports.DataChatServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DataChatServiceTransport() @@ -7418,11 +7456,12 @@ def test_data_chat_service_transport_auth_gdch_credentials(transport_class): def test_data_chat_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8031,6 +8070,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8170,6 +8241,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8315,6 +8418,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8460,6 +8597,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8605,6 +8776,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8746,6 +8951,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = DataChatServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = DataChatServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = DataChatServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py index d262ffbffebf..68f210b80e80 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py @@ -248,7 +248,7 @@ def transport(self) -> BackupForGKETransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -5534,7 +5534,7 @@ async def sample_get_backup_index_download_url(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5560,8 +5560,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5570,7 +5574,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5578,7 +5582,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5589,7 +5593,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5615,8 +5619,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5625,7 +5633,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5633,7 +5641,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5644,7 +5652,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5674,8 +5682,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5684,7 +5696,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5692,7 +5704,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5700,7 +5712,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5729,8 +5741,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5739,7 +5755,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5747,7 +5763,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5755,7 +5771,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5847,8 +5863,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5857,7 +5877,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5865,7 +5887,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5876,7 +5898,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5969,8 +5991,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5979,7 +6005,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5987,7 +6015,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5998,7 +6026,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6029,8 +6057,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6041,7 +6073,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6049,7 +6083,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6060,7 +6094,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6086,8 +6120,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6096,7 +6134,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6104,7 +6142,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6115,7 +6153,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6141,8 +6179,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6151,7 +6193,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6159,7 +6201,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py index bbfb0f26f755..a1a033b53b49 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py @@ -142,7 +142,7 @@ class BackupForGKEClient(metaclass=BackupForGKEClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -150,7 +150,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -160,6 +160,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -729,7 +733,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -826,7 +830,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -922,7 +926,7 @@ def __init__( self._universe_domain = BackupForGKEClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6095,7 +6099,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6121,8 +6125,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6131,7 +6139,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6140,7 +6148,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6154,7 +6162,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6180,8 +6188,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6190,7 +6202,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6199,7 +6211,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6213,7 +6225,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6243,8 +6255,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6253,7 +6269,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6261,7 +6277,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6269,7 +6285,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6298,8 +6314,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6308,7 +6328,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6316,7 +6336,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6324,7 +6344,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6416,8 +6436,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6426,7 +6450,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6435,7 +6461,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6449,7 +6475,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6542,8 +6568,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6552,7 +6582,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6561,7 +6593,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6575,7 +6607,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6606,8 +6638,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6616,7 +6652,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -6625,7 +6663,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6639,7 +6677,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6665,8 +6703,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6675,7 +6717,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6684,7 +6726,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6698,7 +6740,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6724,8 +6766,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6734,7 +6780,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6743,7 +6789,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/README.rst b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/README.rst index f3632b418479..a49e6b90f0a7 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/README.rst +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BackupForGKETransport` is the ABC for all transports. -- public child `BackupForGKEGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BackupForGKEGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBackupForGKERestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BackupForGKERestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BackupForGKETransport`` is the ABC for all transports. + +- public child ``BackupForGKEGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BackupForGKEGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBackupForGKERestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BackupForGKERestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py index c04afa057b01..0146d7e04543 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py @@ -97,6 +97,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -146,6 +150,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py index 88e31bf7606b..3ff616632a24 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py @@ -71,7 +71,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -106,7 +106,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -203,6 +203,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py index 18a5da2ab93a..c78e73980fde 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py @@ -77,7 +77,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -112,7 +112,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -254,6 +254,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py index ea1a4f2c2751..e1380834389d 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py @@ -2565,6 +2565,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BackupForGKERestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index c2e59ee8d4fa..43404705b6af 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gke-backup/setup.py b/packages/google-cloud-gke-backup/setup.py index 6e2a7ae74193..ebbc554fdd57 100644 --- a/packages/google-cloud-gke-backup/setup.py +++ b/packages/google-cloud-gke-backup/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gke-backup/testing/constraints-3.7.txt b/packages/google-cloud-gke-backup/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-gke-backup/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-gke-backup/testing/constraints-3.8.txt b/packages/google-cloud-gke-backup/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-gke-backup/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-gke-backup/testing/constraints-3.9.txt b/packages/google-cloud-gke-backup/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-gke-backup/testing/constraints-3.9.txt +++ b/packages/google-cloud-gke-backup/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py b/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py index 5ade1db7e3ee..be9c33a75428 100644 --- a/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py +++ b/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py @@ -155,6 +155,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BackupForGKEClient._get_default_mtls_endpoint(None) is None assert ( @@ -173,6 +174,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BackupForGKEClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + BackupForGKEClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1293,11 +1298,13 @@ def test_backup_for_gke_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -27395,8 +27402,9 @@ def test_create_backup_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27586,19 +27594,21 @@ def test_create_backup_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_backup_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_create_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_backup_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_create_backup_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_create_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27651,8 +27661,9 @@ def test_list_backup_plans_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27717,17 +27728,20 @@ def test_list_backup_plans_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_backup_plans" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_backup_plans_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_backup_plans" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_backup_plans" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_backup_plans_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_backup_plans" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27780,8 +27794,9 @@ def test_get_backup_plan_rest_bad_request(request_type=gkebackup.GetBackupPlanRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27866,17 +27881,19 @@ def test_get_backup_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup_plan_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27931,8 +27948,9 @@ def test_update_backup_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28126,19 +28144,21 @@ def test_update_backup_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_backup_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_update_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_backup_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_update_backup_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_update_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28191,8 +28211,9 @@ def test_delete_backup_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28249,19 +28270,21 @@ def test_delete_backup_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_backup_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_backup_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_delete_backup_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_backup_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_delete_backup_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_delete_backup_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28314,8 +28337,9 @@ def test_create_backup_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28450,20 +28474,21 @@ def test_create_backup_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_backup_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_create_backup_channel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_create_backup_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_backup_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_create_backup_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_create_backup_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28516,8 +28541,9 @@ def test_list_backup_channels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28582,18 +28608,20 @@ def test_list_backup_channels_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_backup_channels" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_list_backup_channels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_backup_channels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_backup_channels" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_backup_channels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_backup_channels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28651,8 +28679,9 @@ def test_get_backup_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28725,17 +28754,20 @@ def test_get_backup_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_channel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_backup_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_backup_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_backup_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -28794,8 +28826,9 @@ def test_update_backup_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -28934,20 +28967,21 @@ def test_update_backup_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_backup_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_update_backup_channel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_update_backup_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_backup_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_update_backup_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_update_backup_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29000,8 +29034,9 @@ def test_delete_backup_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29058,20 +29093,21 @@ def test_delete_backup_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_backup_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_delete_backup_channel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_delete_backup_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_backup_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_delete_backup_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_delete_backup_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29126,8 +29162,9 @@ def test_list_backup_plan_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29194,18 +29231,20 @@ def test_list_backup_plan_bindings_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_backup_plan_bindings" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_list_backup_plan_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_backup_plan_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_backup_plan_bindings" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_backup_plan_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_backup_plan_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29265,8 +29304,9 @@ def test_get_backup_plan_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29339,18 +29379,20 @@ def test_get_backup_plan_binding_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_plan_binding" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_get_backup_plan_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_backup_plan_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup_plan_binding" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_backup_plan_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_backup_plan_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29406,8 +29448,9 @@ def test_create_backup_rest_bad_request(request_type=gkebackup.CreateBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29573,19 +29616,20 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_create_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29634,8 +29678,9 @@ def test_list_backups_rest_bad_request(request_type=gkebackup.ListBackupsRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29700,17 +29745,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29763,8 +29810,9 @@ def test_get_backup_rest_bad_request(request_type=gkebackup.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29866,17 +29914,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29929,8 +29979,9 @@ def test_update_backup_rest_bad_request(request_type=gkebackup.UpdateBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30100,19 +30151,20 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_update_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30163,8 +30215,9 @@ def test_delete_backup_rest_bad_request(request_type=gkebackup.DeleteBackupReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30223,19 +30276,20 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30288,8 +30342,9 @@ def test_list_volume_backups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30354,17 +30409,20 @@ def test_list_volume_backups_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_volume_backups" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_volume_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_volume_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_volume_backups" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_volume_backups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_volume_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30424,8 +30482,9 @@ def test_get_volume_backup_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30512,17 +30571,20 @@ def test_get_volume_backup_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_volume_backup" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_volume_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_volume_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_volume_backup" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_volume_backup_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_volume_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30575,8 +30637,9 @@ def test_create_restore_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30775,19 +30838,21 @@ def test_create_restore_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_restore_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_restore_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_create_restore_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_restore_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_create_restore_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_create_restore_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30840,8 +30905,9 @@ def test_list_restore_plans_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30906,17 +30972,20 @@ def test_list_restore_plans_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_restore_plans" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_restore_plans_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_restore_plans" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_restore_plans" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_restore_plans_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_restore_plans" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30971,8 +31040,9 @@ def test_get_restore_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31051,17 +31121,20 @@ def test_get_restore_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_restore_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_restore_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_restore_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_restore_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31118,8 +31191,9 @@ def test_update_restore_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31322,19 +31396,21 @@ def test_update_restore_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_restore_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_restore_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_update_restore_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_restore_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_update_restore_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_update_restore_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31387,8 +31463,9 @@ def test_delete_restore_plan_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31445,19 +31522,21 @@ def test_delete_restore_plan_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_restore_plan" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_restore_plan_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_delete_restore_plan" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_restore_plan" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_delete_restore_plan_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_delete_restore_plan" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31510,8 +31589,9 @@ def test_create_restore_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31646,20 +31726,21 @@ def test_create_restore_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_restore_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_create_restore_channel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_create_restore_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_restore_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_create_restore_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_create_restore_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31712,8 +31793,9 @@ def test_list_restore_channels_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31778,18 +31860,20 @@ def test_list_restore_channels_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_restore_channels" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_list_restore_channels_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_restore_channels" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_restore_channels" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_restore_channels_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_restore_channels" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31849,8 +31933,9 @@ def test_get_restore_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31925,17 +32010,20 @@ def test_get_restore_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore_channel_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_restore_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_restore_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_restore_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_restore_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31994,8 +32082,9 @@ def test_update_restore_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32134,20 +32223,21 @@ def test_update_restore_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_restore_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_update_restore_channel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_update_restore_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_restore_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_update_restore_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_update_restore_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32202,8 +32292,9 @@ def test_delete_restore_channel_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32262,20 +32353,21 @@ def test_delete_restore_channel_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_restore_channel" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_delete_restore_channel_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_delete_restore_channel" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_restore_channel" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_delete_restore_channel_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_delete_restore_channel" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32330,8 +32422,9 @@ def test_list_restore_plan_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32398,18 +32491,20 @@ def test_list_restore_plan_bindings_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_restore_plan_bindings" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_list_restore_plan_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_restore_plan_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_restore_plan_bindings" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_restore_plan_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_restore_plan_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32469,8 +32564,9 @@ def test_get_restore_plan_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32543,18 +32639,20 @@ def test_get_restore_plan_binding_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore_plan_binding" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_get_restore_plan_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_restore_plan_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_restore_plan_binding" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_restore_plan_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_restore_plan_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32610,8 +32708,9 @@ def test_create_restore_rest_bad_request(request_type=gkebackup.CreateRestoreReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32826,19 +32925,20 @@ def test_create_restore_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_restore" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_create_restore_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_create_restore" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_restore" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_create_restore_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_create_restore" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32887,8 +32987,9 @@ def test_list_restores_rest_bad_request(request_type=gkebackup.ListRestoresReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32953,17 +33054,19 @@ def test_list_restores_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_restores" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_restores_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_restores" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_restores" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_restores_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_restores" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33016,8 +33119,9 @@ def test_get_restore_rest_bad_request(request_type=gkebackup.GetRestoreRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33104,17 +33208,19 @@ def test_get_restore_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_restore_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_restore" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_restore" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_restore_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_restore" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33167,8 +33273,9 @@ def test_update_restore_rest_bad_request(request_type=gkebackup.UpdateRestoreReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33387,19 +33494,20 @@ def test_update_restore_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_restore" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_update_restore_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_update_restore" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_restore" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_update_restore_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_update_restore" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33450,8 +33558,9 @@ def test_delete_restore_rest_bad_request(request_type=gkebackup.DeleteRestoreReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33510,19 +33619,20 @@ def test_delete_restore_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_restore" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_delete_restore_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_delete_restore" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_restore" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_delete_restore_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_delete_restore" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33575,8 +33685,9 @@ def test_list_volume_restores_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33641,18 +33752,20 @@ def test_list_volume_restores_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_list_volume_restores" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_list_volume_restores_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_list_volume_restores" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_list_volume_restores" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_list_volume_restores_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_list_volume_restores" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33712,8 +33825,9 @@ def test_get_volume_restore_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33792,17 +33906,20 @@ def test_get_volume_restore_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_volume_restore" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_volume_restore_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_volume_restore" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_volume_restore" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_volume_restore_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_volume_restore" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33857,8 +33974,9 @@ def test_get_backup_index_download_url_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33923,18 +34041,20 @@ def test_get_backup_index_download_url_rest_interceptors(null_interceptor): ) client = BackupForGKEClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.BackupForGKERestInterceptor, "post_get_backup_index_download_url" - ) as post, mock.patch.object( - transports.BackupForGKERestInterceptor, - "post_get_backup_index_download_url_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.BackupForGKERestInterceptor, "pre_get_backup_index_download_url" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.BackupForGKERestInterceptor, "post_get_backup_index_download_url" + ) as post, + mock.patch.object( + transports.BackupForGKERestInterceptor, + "post_get_backup_index_download_url_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.BackupForGKERestInterceptor, "pre_get_backup_index_download_url" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33992,8 +34112,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34052,8 +34173,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34114,8 +34236,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34178,8 +34301,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34242,8 +34366,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34306,8 +34431,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34368,8 +34494,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34430,8 +34557,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -34492,8 +34620,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -35504,11 +35633,14 @@ def test_backup_for_gke_base_transport(): def test_backup_for_gke_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gke_backup_v1.services.backup_for_gke.transports.BackupForGKETransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gke_backup_v1.services.backup_for_gke.transports.BackupForGKETransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackupForGKETransport( @@ -35525,9 +35657,12 @@ def test_backup_for_gke_base_transport_with_credentials_file(): def test_backup_for_gke_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gke_backup_v1.services.backup_for_gke.transports.BackupForGKETransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gke_backup_v1.services.backup_for_gke.transports.BackupForGKETransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BackupForGKETransport() @@ -35599,11 +35734,12 @@ def test_backup_for_gke_transport_auth_gdch_credentials(transport_class): def test_backup_for_gke_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -36628,6 +36764,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = BackupForGKEClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36767,6 +36935,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = BackupForGKEClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -36912,6 +37112,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = BackupForGKEClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -37057,6 +37291,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = BackupForGKEClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -37202,6 +37470,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = BackupForGKEClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -37343,6 +37645,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = BackupForGKEClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -37507,6 +37843,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = BackupForGKEClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -37674,6 +38045,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = BackupForGKEClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), @@ -37851,6 +38257,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = BackupForGKEClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = BackupForGKEAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = BackupForGKEClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/client.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/client.py index 6ba26b256281..bae607ef081c 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/client.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/client.py @@ -104,7 +104,7 @@ class GatewayControlClient(metaclass=GatewayControlClientMeta): """GatewayControl is the control plane API for Connect Gateway.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -600,7 +604,7 @@ def __init__( self._universe_domain = GatewayControlClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/README.rst b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/README.rst index ac11ac9134e5..1bd539e34b9c 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/README.rst +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GatewayControlTransport` is the ABC for all transports. -- public child `GatewayControlGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GatewayControlGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGatewayControlRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GatewayControlRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GatewayControlTransport`` is the ABC for all transports. + +- public child ``GatewayControlGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GatewayControlGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGatewayControlRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GatewayControlRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/base.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/base.py index c5dc6a333d11..b3e1da9a2601 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/base.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/rest.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/rest.py index 9bdcb7e0e6b5..04103c5a23b2 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/rest.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1/services/gateway_control/transports/rest.py @@ -203,6 +203,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GatewayControlRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/client.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/client.py index a972711d3963..137f0069c620 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/client.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/client.py @@ -104,7 +104,7 @@ class GatewayControlClient(metaclass=GatewayControlClientMeta): """GatewayControl is the control plane API for Connect Gateway.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -407,7 +411,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -504,7 +508,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -603,7 +607,7 @@ def __init__( self._universe_domain = GatewayControlClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/README.rst b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/README.rst index ac11ac9134e5..1bd539e34b9c 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/README.rst +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GatewayControlTransport` is the ABC for all transports. -- public child `GatewayControlGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GatewayControlGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGatewayControlRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GatewayControlRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GatewayControlTransport`` is the ABC for all transports. + +- public child ``GatewayControlGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GatewayControlGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGatewayControlRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GatewayControlRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/base.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/base.py index a892d6e35504..07d67baaeb45 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/base.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/rest.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/rest.py index 8faac542bfef..561400e8c5d1 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/rest.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_control/transports/rest.py @@ -207,6 +207,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GatewayControlRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index 26891d84a9a3..624a5f5c99ce 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gke-connect-gateway/setup.py b/packages/google-cloud-gke-connect-gateway/setup.py index ce68efc6a9af..a871814ba715 100644 --- a/packages/google-cloud-gke-connect-gateway/setup.py +++ b/packages/google-cloud-gke-connect-gateway/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-gke-connect-gateway" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gke-connect-gateway/testing/constraints-3.7.txt b/packages/google-cloud-gke-connect-gateway/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-gke-connect-gateway/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-gke-connect-gateway/testing/constraints-3.8.txt b/packages/google-cloud-gke-connect-gateway/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-gke-connect-gateway/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-gke-connect-gateway/testing/constraints-3.9.txt b/packages/google-cloud-gke-connect-gateway/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-gke-connect-gateway/testing/constraints-3.9.txt +++ b/packages/google-cloud-gke-connect-gateway/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1/test_gateway_control.py b/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1/test_gateway_control.py index e91c21611187..90bef8cbeccb 100644 --- a/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1/test_gateway_control.py +++ b/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1/test_gateway_control.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GatewayControlClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): assert ( GatewayControlClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GatewayControlClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1378,8 +1383,9 @@ def test_generate_credentials_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1444,18 +1450,20 @@ def test_generate_credentials_rest_interceptors(null_interceptor): ) client = GatewayControlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GatewayControlRestInterceptor, "post_generate_credentials" - ) as post, mock.patch.object( - transports.GatewayControlRestInterceptor, - "post_generate_credentials_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GatewayControlRestInterceptor, "pre_generate_credentials" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GatewayControlRestInterceptor, "post_generate_credentials" + ) as post, + mock.patch.object( + transports.GatewayControlRestInterceptor, + "post_generate_credentials_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GatewayControlRestInterceptor, "pre_generate_credentials" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1571,11 +1579,14 @@ def test_gateway_control_base_transport(): def test_gateway_control_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gkeconnect.gateway_v1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gkeconnect.gateway_v1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GatewayControlTransport( @@ -1592,9 +1603,12 @@ def test_gateway_control_base_transport_with_credentials_file(): def test_gateway_control_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gkeconnect.gateway_v1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gkeconnect.gateway_v1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GatewayControlTransport() diff --git a/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_control.py b/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_control.py index e900b5900ae6..4c09b14ecc03 100644 --- a/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_control.py +++ b/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_control.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GatewayControlClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): assert ( GatewayControlClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GatewayControlClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1378,8 +1383,9 @@ def test_generate_credentials_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1444,18 +1450,20 @@ def test_generate_credentials_rest_interceptors(null_interceptor): ) client = GatewayControlClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GatewayControlRestInterceptor, "post_generate_credentials" - ) as post, mock.patch.object( - transports.GatewayControlRestInterceptor, - "post_generate_credentials_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GatewayControlRestInterceptor, "pre_generate_credentials" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GatewayControlRestInterceptor, "post_generate_credentials" + ) as post, + mock.patch.object( + transports.GatewayControlRestInterceptor, + "post_generate_credentials_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GatewayControlRestInterceptor, "pre_generate_credentials" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -1571,11 +1579,14 @@ def test_gateway_control_base_transport(): def test_gateway_control_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gkeconnect.gateway_v1beta1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gkeconnect.gateway_v1beta1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GatewayControlTransport( @@ -1592,9 +1603,12 @@ def test_gateway_control_base_transport_with_credentials_file(): def test_gateway_control_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gkeconnect.gateway_v1beta1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gkeconnect.gateway_v1beta1.services.gateway_control.transports.GatewayControlTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GatewayControlTransport() diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py index 31b11edfcc5a..8c7b47221023 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py @@ -215,7 +215,7 @@ def transport(self) -> GkeHubTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py index 37c08e4b0e18..adbc04fbd183 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py @@ -133,7 +133,7 @@ class GkeHubClient(metaclass=GkeHubClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -141,7 +141,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -151,6 +151,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -598,7 +602,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -695,7 +699,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -791,7 +795,7 @@ def __init__( self._universe_domain = GkeHubClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/README.rst b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/README.rst index 4d09d766ff19..6c3d15679bcc 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/README.rst +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GkeHubTransport` is the ABC for all transports. -- public child `GkeHubGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GkeHubGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGkeHubRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GkeHubRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GkeHubTransport`` is the ABC for all transports. + +- public child ``GkeHubGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GkeHubGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGkeHubRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GkeHubRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py index 31af1198c854..5ec94aa8efb1 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py index 7bc6c3e5c2af..2a00458b569c 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -201,6 +201,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py index e2259d42f3a7..1190726b3692 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -252,6 +252,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py index ac21fa0b4244..d5d606c0c05b 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py @@ -2611,6 +2611,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GkeHubRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py index 2ead1663a8d3..cfd607443c53 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/async_client.py @@ -220,7 +220,7 @@ def transport(self) -> GkeHubMembershipServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1311,7 +1311,7 @@ async def sample_generate_exclusivity_manifest(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1337,8 +1337,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1347,7 +1351,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1355,7 +1359,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1366,7 +1370,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1392,8 +1396,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1402,7 +1410,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1410,7 +1418,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1421,7 +1429,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1451,8 +1459,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1461,7 +1473,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1469,7 +1481,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1477,7 +1489,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1506,8 +1518,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1516,7 +1532,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1524,7 +1540,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1532,7 +1548,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1624,8 +1640,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1634,7 +1654,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1642,7 +1664,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1653,7 +1675,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1746,8 +1768,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1756,7 +1782,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1764,7 +1792,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1775,7 +1803,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1806,8 +1834,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1818,7 +1850,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1826,7 +1860,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1837,7 +1871,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1863,8 +1897,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1873,7 +1911,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1881,7 +1919,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1892,7 +1930,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1918,8 +1956,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1928,7 +1970,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1936,7 +1978,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py index 2957ac297086..94af9941213c 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/client.py @@ -132,7 +132,7 @@ class GkeHubMembershipServiceClient(metaclass=GkeHubMembershipServiceClientMeta) """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -140,7 +140,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -150,6 +150,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = GkeHubMembershipServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1732,7 +1736,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1758,8 +1762,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1768,7 +1776,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1777,7 +1785,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1791,7 +1799,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1817,8 +1825,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1827,7 +1839,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1836,7 +1848,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1850,7 +1862,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1880,8 +1892,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1890,7 +1906,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1898,7 +1914,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1906,7 +1922,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1935,8 +1951,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1945,7 +1965,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1953,7 +1973,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1961,7 +1981,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2053,8 +2073,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2063,7 +2087,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2072,7 +2098,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2086,7 +2112,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2179,8 +2205,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2189,7 +2219,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2198,7 +2230,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2212,7 +2244,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2243,8 +2275,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2253,7 +2289,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2262,7 +2300,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2276,7 +2314,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2302,8 +2340,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2312,7 +2354,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2321,7 +2363,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2335,7 +2377,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2361,8 +2403,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2371,7 +2417,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2380,7 +2426,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/README.rst b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/README.rst index 3453b2983bfb..638d8e6d772a 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/README.rst +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GkeHubMembershipServiceTransport` is the ABC for all transports. -- public child `GkeHubMembershipServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GkeHubMembershipServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGkeHubMembershipServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GkeHubMembershipServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GkeHubMembershipServiceTransport`` is the ABC for all transports. + +- public child ``GkeHubMembershipServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GkeHubMembershipServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGkeHubMembershipServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GkeHubMembershipServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py index 1c1d68366b8a..100076d67125 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py index d79d78a06333..b452603c3afc 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -199,6 +199,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py index eeaf45b8514d..595285431bfd 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -250,6 +250,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/rest.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/rest.py index 592735e24846..7949d09a9ff2 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/rest.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1beta1/services/gke_hub_membership_service/transports/rest.py @@ -838,6 +838,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GkeHubMembershipServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index df8a69c82b40..9433263863c8 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gke-hub/setup.py b/packages/google-cloud-gke-hub/setup.py index 1bdf503a588f..9e877055782f 100644 --- a/packages/google-cloud-gke-hub/setup.py +++ b/packages/google-cloud-gke-hub/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -48,7 +48,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-gke-hub" @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gke-hub/testing/constraints-3.7.txt b/packages/google-cloud-gke-hub/testing/constraints-3.7.txt deleted file mode 100644 index 2bcfa952021b..000000000000 --- a/packages/google-cloud-gke-hub/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -grpc-google-iam-v1==0.12.4 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-gke-hub/testing/constraints-3.8.txt b/packages/google-cloud-gke-hub/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-gke-hub/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-gke-hub/testing/constraints-3.9.txt b/packages/google-cloud-gke-hub/testing/constraints-3.9.txt index 7599dea499ed..36c91811afe8 100644 --- a/packages/google-cloud-gke-hub/testing/constraints-3.9.txt +++ b/packages/google-cloud-gke-hub/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +grpc-google-iam-v1==0.12.4 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py index c927630880f8..e263502b8080 100644 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py +++ b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GkeHubClient._get_default_mtls_endpoint(None) is None assert GkeHubClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -143,6 +144,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GkeHubClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert GkeHubClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1221,11 +1223,13 @@ def test_gke_hub_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -29216,8 +29220,9 @@ def test_list_memberships_rest_bad_request(request_type=service.ListMembershipsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29280,17 +29285,19 @@ def test_list_memberships_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_memberships" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_memberships_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_memberships" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_memberships" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_memberships_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_memberships" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29343,8 +29350,9 @@ def test_list_bound_memberships_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29407,17 +29415,20 @@ def test_list_bound_memberships_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_bound_memberships" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_bound_memberships_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_bound_memberships" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_bound_memberships" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_list_bound_memberships_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_bound_memberships" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29473,8 +29484,9 @@ def test_list_features_rest_bad_request(request_type=service.ListFeaturesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29535,17 +29547,17 @@ def test_list_features_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_features" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_features_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_features" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_features" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_features_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_list_features") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29596,8 +29608,9 @@ def test_get_membership_rest_bad_request(request_type=service.GetMembershipReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29664,17 +29677,19 @@ def test_get_membership_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_membership" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_membership" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_membership_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_get_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29723,8 +29738,9 @@ def test_get_feature_rest_bad_request(request_type=service.GetFeatureRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -29787,17 +29803,15 @@ def test_get_feature_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_feature" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_feature_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_feature" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.GkeHubRestInterceptor, "post_get_feature") as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_feature_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_get_feature") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -29848,8 +29862,9 @@ def test_create_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30024,19 +30039,20 @@ def test_create_membership_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_membership" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_membership" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_membership_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_create_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30087,8 +30103,9 @@ def test_create_feature_rest_bad_request(request_type=service.CreateFeatureReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30234,19 +30251,20 @@ def test_create_feature_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_feature" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_feature_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_feature" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_feature" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_feature_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_create_feature" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30297,8 +30315,9 @@ def test_delete_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30353,19 +30372,20 @@ def test_delete_membership_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_membership" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_membership" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_membership_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_delete_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30416,8 +30436,9 @@ def test_delete_feature_rest_bad_request(request_type=service.DeleteFeatureReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30472,19 +30493,20 @@ def test_delete_feature_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_feature" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_feature_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_feature" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_feature" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_feature_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_delete_feature" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30535,8 +30557,9 @@ def test_update_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30711,19 +30734,20 @@ def test_update_membership_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_membership" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_membership_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_membership" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_membership_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_update_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30774,8 +30798,9 @@ def test_update_feature_rest_bad_request(request_type=service.UpdateFeatureReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -30921,19 +30946,20 @@ def test_update_feature_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_feature" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_feature_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_feature" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_feature" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_feature_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_update_feature" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -30984,8 +31010,9 @@ def test_generate_connect_manifest_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31043,17 +31070,20 @@ def test_generate_connect_manifest_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_generate_connect_manifest" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_generate_connect_manifest_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_generate_connect_manifest" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_generate_connect_manifest" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_generate_connect_manifest_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_generate_connect_manifest" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31109,8 +31139,9 @@ def test_create_fleet_rest_bad_request(request_type=service.CreateFleetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31253,19 +31284,18 @@ def test_create_fleet_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_fleet" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_fleet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_fleet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_fleet" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_fleet_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_create_fleet") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31314,8 +31344,9 @@ def test_get_fleet_rest_bad_request(request_type=service.GetFleetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31380,17 +31411,15 @@ def test_get_fleet_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_fleet" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_fleet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_fleet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.GkeHubRestInterceptor, "post_get_fleet") as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_fleet_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_get_fleet") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31441,8 +31470,9 @@ def test_update_fleet_rest_bad_request(request_type=service.UpdateFleetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31587,19 +31617,18 @@ def test_update_fleet_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_fleet" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_fleet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_fleet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_fleet" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_fleet_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_update_fleet") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31648,8 +31677,9 @@ def test_delete_fleet_rest_bad_request(request_type=service.DeleteFleetRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31704,19 +31734,18 @@ def test_delete_fleet_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_fleet" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_fleet_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_fleet" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_fleet" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_fleet_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_delete_fleet") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31765,8 +31794,9 @@ def test_list_fleets_rest_bad_request(request_type=service.ListFleetsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31827,17 +31857,15 @@ def test_list_fleets_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_fleets" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_fleets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_fleets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.GkeHubRestInterceptor, "post_list_fleets") as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_fleets_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_list_fleets") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31890,8 +31918,9 @@ def test_get_scope_namespace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31958,17 +31987,19 @@ def test_get_scope_namespace_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_scope_namespace" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_scope_namespace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_scope_namespace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_scope_namespace" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_scope_namespace_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_get_scope_namespace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32021,8 +32052,9 @@ def test_create_scope_namespace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32155,19 +32187,21 @@ def test_create_scope_namespace_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_scope_namespace" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_scope_namespace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_scope_namespace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_scope_namespace" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_create_scope_namespace_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_create_scope_namespace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32224,8 +32258,9 @@ def test_update_scope_namespace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32362,19 +32397,21 @@ def test_update_scope_namespace_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_scope_namespace" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_scope_namespace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_scope_namespace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_scope_namespace" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_update_scope_namespace_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_update_scope_namespace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32429,8 +32466,9 @@ def test_delete_scope_namespace_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32487,19 +32525,21 @@ def test_delete_scope_namespace_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_scope_namespace" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_scope_namespace_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_scope_namespace" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_scope_namespace" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_delete_scope_namespace_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_delete_scope_namespace" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32552,8 +32592,9 @@ def test_list_scope_namespaces_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32614,17 +32655,19 @@ def test_list_scope_namespaces_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_scope_namespaces" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_scope_namespaces_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_scope_namespaces" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_scope_namespaces" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_scope_namespaces_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_scope_namespaces" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32684,8 +32727,9 @@ def test_get_scope_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32751,18 +32795,20 @@ def test_get_scope_rbac_role_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_scope_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_get_scope_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_scope_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_scope_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_get_scope_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_get_scope_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32815,8 +32861,9 @@ def test_create_scope_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32952,20 +32999,21 @@ def test_create_scope_rbac_role_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_scope_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_create_scope_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_scope_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_scope_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_create_scope_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_create_scope_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33022,8 +33070,9 @@ def test_update_scope_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33163,20 +33212,21 @@ def test_update_scope_rbac_role_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_scope_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_update_scope_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_scope_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_scope_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_update_scope_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_update_scope_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33231,8 +33281,9 @@ def test_delete_scope_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33289,20 +33340,21 @@ def test_delete_scope_rbac_role_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_scope_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_delete_scope_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_scope_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_scope_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_delete_scope_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_delete_scope_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33355,8 +33407,9 @@ def test_list_scope_rbac_role_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33417,18 +33470,20 @@ def test_list_scope_rbac_role_bindings_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_scope_rbac_role_bindings" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_list_scope_rbac_role_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_scope_rbac_role_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_scope_rbac_role_bindings" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_list_scope_rbac_role_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_scope_rbac_role_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33484,8 +33539,9 @@ def test_get_scope_rest_bad_request(request_type=service.GetScopeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33548,17 +33604,15 @@ def test_get_scope_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_scope" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_scope_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_scope" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.GkeHubRestInterceptor, "post_get_scope") as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_scope_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_get_scope") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33607,8 +33661,9 @@ def test_create_scope_rest_bad_request(request_type=service.CreateScopeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33740,19 +33795,18 @@ def test_create_scope_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_scope" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_scope_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_scope" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_scope" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_scope_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_create_scope") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33803,8 +33857,9 @@ def test_update_scope_rest_bad_request(request_type=service.UpdateScopeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33938,19 +33993,18 @@ def test_update_scope_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_scope" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_scope_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_scope" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_scope" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_scope_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_update_scope") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33999,8 +34053,9 @@ def test_delete_scope_rest_bad_request(request_type=service.DeleteScopeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34055,19 +34110,18 @@ def test_delete_scope_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_scope" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_scope_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_scope" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_scope" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_scope_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_delete_scope") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34116,8 +34170,9 @@ def test_list_scopes_rest_bad_request(request_type=service.ListScopesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34178,17 +34233,15 @@ def test_list_scopes_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_scopes" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_scopes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_scopes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.GkeHubRestInterceptor, "post_list_scopes") as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_scopes_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.GkeHubRestInterceptor, "pre_list_scopes") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34239,8 +34292,9 @@ def test_list_permitted_scopes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34301,17 +34355,19 @@ def test_list_permitted_scopes_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_permitted_scopes" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_permitted_scopes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_permitted_scopes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_permitted_scopes" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_permitted_scopes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_permitted_scopes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34371,8 +34427,9 @@ def test_get_membership_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34438,17 +34495,20 @@ def test_get_membership_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_membership_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_membership_binding_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_membership_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_membership_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_get_membership_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_get_membership_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34501,8 +34561,9 @@ def test_create_membership_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34636,19 +34697,21 @@ def test_create_membership_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_membership_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_membership_binding_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_membership_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_membership_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_create_membership_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_create_membership_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34705,8 +34768,9 @@ def test_update_membership_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34844,19 +34908,21 @@ def test_update_membership_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_membership_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_membership_binding_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_membership_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_membership_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_update_membership_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_update_membership_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34911,8 +34977,9 @@ def test_delete_membership_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34969,19 +35036,21 @@ def test_delete_membership_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_membership_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_membership_binding_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_membership_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_membership_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_delete_membership_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_delete_membership_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35034,8 +35103,9 @@ def test_list_membership_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35098,17 +35168,20 @@ def test_list_membership_bindings_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_membership_bindings" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_membership_bindings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_membership_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_membership_bindings" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_list_membership_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_membership_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35168,8 +35241,9 @@ def test_get_membership_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35235,18 +35309,20 @@ def test_get_membership_rbac_role_binding_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_get_membership_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_get_membership_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_get_membership_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_get_membership_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_get_membership_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_get_membership_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35299,8 +35375,9 @@ def test_create_membership_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35436,20 +35513,21 @@ def test_create_membership_rbac_role_binding_rest_interceptors(null_interceptor) ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_create_membership_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_create_membership_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_create_membership_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_create_membership_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_create_membership_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_create_membership_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35506,8 +35584,9 @@ def test_update_membership_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35647,20 +35726,21 @@ def test_update_membership_rbac_role_binding_rest_interceptors(null_interceptor) ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_update_membership_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_update_membership_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_update_membership_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_update_membership_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_update_membership_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_update_membership_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35715,8 +35795,9 @@ def test_delete_membership_rbac_role_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35773,20 +35854,21 @@ def test_delete_membership_rbac_role_binding_rest_interceptors(null_interceptor) ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubRestInterceptor, "post_delete_membership_rbac_role_binding" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_delete_membership_rbac_role_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_delete_membership_rbac_role_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubRestInterceptor, "post_delete_membership_rbac_role_binding" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_delete_membership_rbac_role_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_delete_membership_rbac_role_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35839,8 +35921,9 @@ def test_list_membership_rbac_role_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35903,18 +35986,20 @@ def test_list_membership_rbac_role_bindings_rest_interceptors(null_interceptor): ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, "post_list_membership_rbac_role_bindings" - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_list_membership_rbac_role_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, "pre_list_membership_rbac_role_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, "post_list_membership_rbac_role_bindings" + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_list_membership_rbac_role_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, "pre_list_membership_rbac_role_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35972,8 +36057,9 @@ def test_generate_membership_rbac_role_binding_yaml_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36117,20 +36203,22 @@ def test_generate_membership_rbac_role_binding_yaml_rest_interceptors(null_inter ) client = GkeHubClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_generate_membership_rbac_role_binding_yaml", - ) as post, mock.patch.object( - transports.GkeHubRestInterceptor, - "post_generate_membership_rbac_role_binding_yaml_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubRestInterceptor, - "pre_generate_membership_rbac_role_binding_yaml", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_generate_membership_rbac_role_binding_yaml", + ) as post, + mock.patch.object( + transports.GkeHubRestInterceptor, + "post_generate_membership_rbac_role_binding_yaml_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubRestInterceptor, + "pre_generate_membership_rbac_role_binding_yaml", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37236,11 +37324,14 @@ def test_gke_hub_base_transport(): def test_gke_hub_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gkehub_v1.services.gke_hub.transports.GkeHubTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gkehub_v1.services.gke_hub.transports.GkeHubTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeHubTransport( @@ -37257,9 +37348,12 @@ def test_gke_hub_base_transport_with_credentials_file(): def test_gke_hub_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gkehub_v1.services.gke_hub.transports.GkeHubTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gkehub_v1.services.gke_hub.transports.GkeHubTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeHubTransport() @@ -37331,11 +37425,12 @@ def test_gke_hub_transport_auth_gdch_credentials(transport_class): def test_gke_hub_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py index 71d024883dab..05e78d4eb8f3 100644 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py +++ b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1beta1/test_gke_hub_membership_service.py @@ -134,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GkeHubMembershipServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -156,6 +157,10 @@ def test__get_default_mtls_endpoint(): GkeHubMembershipServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GkeHubMembershipServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1361,11 +1366,13 @@ def test_gke_hub_membership_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6163,8 +6170,9 @@ def test_list_memberships_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6229,18 +6237,20 @@ def test_list_memberships_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "post_list_memberships" - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_list_memberships_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "pre_list_memberships" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "post_list_memberships" + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_list_memberships_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "pre_list_memberships" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6293,8 +6303,9 @@ def test_get_membership_rest_bad_request(request_type=membership.GetMembershipRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6367,18 +6378,20 @@ def test_get_membership_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "post_get_membership" - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_get_membership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "pre_get_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "post_get_membership" + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_get_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "pre_get_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6431,8 +6444,9 @@ def test_create_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6621,20 +6635,21 @@ def test_create_membership_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "post_create_membership" - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_create_membership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "pre_create_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "post_create_membership" + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_create_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "pre_create_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6687,8 +6702,9 @@ def test_delete_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6745,20 +6761,21 @@ def test_delete_membership_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "post_delete_membership" - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_delete_membership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "pre_delete_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "post_delete_membership" + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_delete_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "pre_delete_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6811,8 +6828,9 @@ def test_update_membership_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7001,20 +7019,21 @@ def test_update_membership_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "post_update_membership" - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_update_membership_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "pre_update_membership" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "post_update_membership" + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_update_membership_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, "pre_update_membership" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7067,8 +7086,9 @@ def test_generate_connect_manifest_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7128,20 +7148,22 @@ def test_generate_connect_manifest_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_generate_connect_manifest", - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_generate_connect_manifest_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "pre_generate_connect_manifest", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_generate_connect_manifest", + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_generate_connect_manifest_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "pre_generate_connect_manifest", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7199,8 +7221,9 @@ def test_validate_exclusivity_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7260,18 +7283,22 @@ def test_validate_exclusivity_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "post_validate_exclusivity" - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_validate_exclusivity_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, "pre_validate_exclusivity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_validate_exclusivity", + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_validate_exclusivity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "pre_validate_exclusivity", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7329,8 +7356,9 @@ def test_generate_exclusivity_manifest_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7395,20 +7423,22 @@ def test_generate_exclusivity_manifest_rest_interceptors(null_interceptor): ) client = GkeHubMembershipServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_generate_exclusivity_manifest", - ) as post, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "post_generate_exclusivity_manifest_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeHubMembershipServiceRestInterceptor, - "pre_generate_exclusivity_manifest", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_generate_exclusivity_manifest", + ) as post, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "post_generate_exclusivity_manifest_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeHubMembershipServiceRestInterceptor, + "pre_generate_exclusivity_manifest", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7466,8 +7496,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7526,8 +7557,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7588,8 +7620,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7652,8 +7685,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7716,8 +7750,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7780,8 +7815,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7842,8 +7878,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7904,8 +7941,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7966,8 +8004,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8285,11 +8324,14 @@ def test_gke_hub_membership_service_base_transport(): def test_gke_hub_membership_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeHubMembershipServiceTransport( @@ -8306,9 +8348,12 @@ def test_gke_hub_membership_service_base_transport_with_credentials_file(): def test_gke_hub_membership_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gkehub_v1beta1.services.gke_hub_membership_service.transports.GkeHubMembershipServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeHubMembershipServiceTransport() @@ -8382,11 +8427,12 @@ def test_gke_hub_membership_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9010,6 +9056,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = GkeHubMembershipServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9149,6 +9227,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = GkeHubMembershipServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9294,6 +9404,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = GkeHubMembershipServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9439,6 +9583,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = GkeHubMembershipServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9584,6 +9762,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = GkeHubMembershipServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9729,6 +9941,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = GkeHubMembershipServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9893,6 +10139,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = GkeHubMembershipServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10060,6 +10341,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = GkeHubMembershipServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10237,6 +10553,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = GkeHubMembershipServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = GkeHubMembershipServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = GkeHubMembershipServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py index 4fa515a1a708..3a888bb15358 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> AttachedClustersTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1607,7 +1607,7 @@ async def sample_generate_attached_cluster_agent_token(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1633,8 +1633,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1643,7 +1647,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1651,7 +1655,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1662,7 +1666,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1688,8 +1692,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1698,7 +1706,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1706,7 +1714,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1717,7 +1725,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1747,8 +1755,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1757,7 +1769,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1765,7 +1777,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1773,7 +1785,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1802,8 +1814,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1812,7 +1828,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1820,7 +1836,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py index 63293d859594..26687c89618b 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py @@ -123,7 +123,7 @@ class AttachedClustersClient(metaclass=AttachedClustersClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -565,7 +569,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -666,7 +670,7 @@ def __init__( self._universe_domain = AttachedClustersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2043,7 +2047,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2069,8 +2073,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2079,7 +2087,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2088,7 +2096,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2102,7 +2110,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2128,8 +2136,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2138,7 +2150,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2147,7 +2159,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2161,7 +2173,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2191,8 +2203,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2201,7 +2217,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2209,7 +2225,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2217,7 +2233,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2246,8 +2262,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2256,7 +2276,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2264,7 +2284,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/README.rst b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/README.rst index 6dc5686bab67..367d452bbdc3 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/README.rst +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AttachedClustersTransport` is the ABC for all transports. -- public child `AttachedClustersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AttachedClustersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAttachedClustersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AttachedClustersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AttachedClustersTransport`` is the ABC for all transports. + +- public child ``AttachedClustersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AttachedClustersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAttachedClustersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AttachedClustersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py index 490ccaca9190..5bae5abb284b 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py index 67f201c89801..1374cb7aa853 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py index 673c0ac4d4fd..d92d0a2e81c1 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py index 9961a2cac298..deb49c67b17a 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py @@ -774,6 +774,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AttachedClustersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py index 2405304c8157..282e40f89d59 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> AwsClustersTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2562,7 +2562,7 @@ async def sample_get_aws_server_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2588,8 +2588,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2598,7 +2602,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2606,7 +2610,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2617,7 +2621,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2643,8 +2647,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2653,7 +2661,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2661,7 +2669,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2672,7 +2680,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2702,8 +2710,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2712,7 +2724,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2720,7 +2732,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2728,7 +2740,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2757,8 +2769,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2767,7 +2783,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2775,7 +2791,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py index acfc6e66a89e..b93cca890c61 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py @@ -123,7 +123,7 @@ class AwsClustersClient(metaclass=AwsClustersClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -494,7 +498,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -591,7 +595,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -690,7 +694,7 @@ def __init__( self._universe_domain = AwsClustersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2997,7 +3001,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3023,8 +3027,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3033,7 +3041,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3042,7 +3050,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3056,7 +3064,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3082,8 +3090,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3092,7 +3104,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3101,7 +3113,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3115,7 +3127,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3145,8 +3157,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3155,7 +3171,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3163,7 +3179,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3171,7 +3187,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3200,8 +3216,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3210,7 +3230,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3218,7 +3238,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/README.rst b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/README.rst index 9e0624faad5d..14c82cef03ae 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/README.rst +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AwsClustersTransport` is the ABC for all transports. -- public child `AwsClustersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AwsClustersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAwsClustersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AwsClustersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AwsClustersTransport`` is the ABC for all transports. + +- public child ``AwsClustersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AwsClustersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAwsClustersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AwsClustersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py index 00b2bbf2aeb9..c0d1136c77f5 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py index 8f078f0592dc..fc7ca3d4c7f3 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py index c6ff70b05770..3bb8e9b5b717 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py index ca38b0a8f2a3..657dc7404800 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py @@ -1157,6 +1157,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AwsClustersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py index 5421b66ce71d..d1e413312147 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py @@ -214,7 +214,7 @@ def transport(self) -> AzureClustersTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3093,7 +3093,7 @@ async def sample_get_azure_server_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3119,8 +3119,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3129,7 +3133,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3137,7 +3141,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3148,7 +3152,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3174,8 +3178,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3184,7 +3192,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3192,7 +3200,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3203,7 +3211,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3233,8 +3241,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3243,7 +3255,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3251,7 +3263,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3259,7 +3271,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3288,8 +3300,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3298,7 +3314,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3306,7 +3322,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py index 15987ba9e632..28e865a5767c 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py @@ -123,7 +123,7 @@ class AzureClustersClient(metaclass=AzureClustersClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -514,7 +518,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -611,7 +615,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -710,7 +714,7 @@ def __init__( self._universe_domain = AzureClustersClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3526,7 +3530,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3552,8 +3556,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3562,7 +3570,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3571,7 +3579,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3585,7 +3593,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3611,8 +3619,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3621,7 +3633,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3630,7 +3642,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3644,7 +3656,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3674,8 +3686,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3684,7 +3700,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3692,7 +3708,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3700,7 +3716,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3729,8 +3745,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3739,7 +3759,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3747,7 +3767,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/README.rst b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/README.rst index cc9731adcaaa..10d971e53ffa 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/README.rst +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AzureClustersTransport` is the ABC for all transports. -- public child `AzureClustersGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AzureClustersGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAzureClustersRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AzureClustersRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AzureClustersTransport`` is the ABC for all transports. + +- public child ``AzureClustersGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AzureClustersGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAzureClustersRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AzureClustersRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py index c6fa966c8c1c..fc06d339cf54 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py index c1b7fc4b10f3..24bfa0741ffe 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py index 741d771149dd..9db9697df0ca 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py index 60f393914d20..96188bea2249 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py @@ -1339,6 +1339,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AzureClustersRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index c7ce48f38811..1261cf1c6354 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gke-multicloud/setup.py b/packages/google-cloud-gke-multicloud/setup.py index 324628e2f323..881023327634 100644 --- a/packages/google-cloud-gke-multicloud/setup.py +++ b/packages/google-cloud-gke-multicloud/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-gke-multicloud" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gke-multicloud/testing/constraints-3.7.txt b/packages/google-cloud-gke-multicloud/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-gke-multicloud/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-gke-multicloud/testing/constraints-3.8.txt b/packages/google-cloud-gke-multicloud/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-gke-multicloud/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-gke-multicloud/testing/constraints-3.9.txt b/packages/google-cloud-gke-multicloud/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-gke-multicloud/testing/constraints-3.9.txt +++ b/packages/google-cloud-gke-multicloud/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py index 209aeb6dfd78..38c3a6d100e2 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AttachedClustersClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): AttachedClustersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AttachedClustersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1322,11 +1327,13 @@ def test_attached_clusters_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7192,8 +7199,9 @@ def test_create_attached_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7368,20 +7376,21 @@ def test_create_attached_cluster_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_create_attached_cluster" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_create_attached_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_create_attached_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AttachedClustersRestInterceptor, "post_create_attached_cluster" + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_create_attached_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_create_attached_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7438,8 +7447,9 @@ def test_update_attached_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7618,20 +7628,21 @@ def test_update_attached_cluster_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_update_attached_cluster" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_update_attached_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_update_attached_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AttachedClustersRestInterceptor, "post_update_attached_cluster" + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_update_attached_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_update_attached_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7684,8 +7695,9 @@ def test_import_attached_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7742,20 +7754,21 @@ def test_import_attached_cluster_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_import_attached_cluster" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_import_attached_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_import_attached_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AttachedClustersRestInterceptor, "post_import_attached_cluster" + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_import_attached_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_import_attached_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7810,8 +7823,9 @@ def test_get_attached_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7894,18 +7908,20 @@ def test_get_attached_cluster_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_get_attached_cluster" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_get_attached_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_get_attached_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "post_get_attached_cluster" + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_get_attached_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_get_attached_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7960,8 +7976,9 @@ def test_list_attached_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8024,18 +8041,20 @@ def test_list_attached_clusters_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_list_attached_clusters" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_list_attached_clusters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_list_attached_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "post_list_attached_clusters" + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_list_attached_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_list_attached_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8095,8 +8114,9 @@ def test_delete_attached_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8155,20 +8175,21 @@ def test_delete_attached_cluster_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_delete_attached_cluster" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_delete_attached_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_delete_attached_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AttachedClustersRestInterceptor, "post_delete_attached_cluster" + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_delete_attached_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_delete_attached_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8221,8 +8242,9 @@ def test_get_attached_server_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8285,18 +8307,21 @@ def test_get_attached_server_config_rest_interceptors(null_interceptor): ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AttachedClustersRestInterceptor, "post_get_attached_server_config" - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_get_attached_server_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, "pre_get_attached_server_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_get_attached_server_config", + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_get_attached_server_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, "pre_get_attached_server_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8354,8 +8379,9 @@ def test_generate_attached_cluster_install_manifest_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8424,20 +8450,22 @@ def test_generate_attached_cluster_install_manifest_rest_interceptors(null_inter ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_generate_attached_cluster_install_manifest", - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_generate_attached_cluster_install_manifest_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "pre_generate_attached_cluster_install_manifest", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_generate_attached_cluster_install_manifest", + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_generate_attached_cluster_install_manifest_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "pre_generate_attached_cluster_install_manifest", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8501,8 +8529,9 @@ def test_generate_attached_cluster_agent_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8575,20 +8604,22 @@ def test_generate_attached_cluster_agent_token_rest_interceptors(null_intercepto ) client = AttachedClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_generate_attached_cluster_agent_token", - ) as post, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "post_generate_attached_cluster_agent_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AttachedClustersRestInterceptor, - "pre_generate_attached_cluster_agent_token", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_generate_attached_cluster_agent_token", + ) as post, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "post_generate_attached_cluster_agent_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AttachedClustersRestInterceptor, + "pre_generate_attached_cluster_agent_token", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8650,8 +8681,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8712,8 +8744,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8774,8 +8807,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8836,8 +8870,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9177,11 +9212,14 @@ def test_attached_clusters_base_transport(): def test_attached_clusters_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gke_multicloud_v1.services.attached_clusters.transports.AttachedClustersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gke_multicloud_v1.services.attached_clusters.transports.AttachedClustersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AttachedClustersTransport( @@ -9198,9 +9236,12 @@ def test_attached_clusters_base_transport_with_credentials_file(): def test_attached_clusters_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gke_multicloud_v1.services.attached_clusters.transports.AttachedClustersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gke_multicloud_v1.services.attached_clusters.transports.AttachedClustersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AttachedClustersTransport() @@ -9272,11 +9313,12 @@ def test_attached_clusters_transport_auth_gdch_credentials(transport_class): def test_attached_clusters_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9922,6 +9964,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AttachedClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AttachedClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10061,6 +10135,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AttachedClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AttachedClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10206,6 +10312,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AttachedClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AttachedClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10351,6 +10491,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AttachedClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AttachedClustersClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py index 19252ac05d7c..a7c3ef3a03d9 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AwsClustersClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AwsClustersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AwsClustersClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1255,11 +1259,13 @@ def test_aws_clusters_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10994,8 +11000,9 @@ def test_create_aws_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11193,19 +11200,21 @@ def test_create_aws_cluster_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_create_aws_cluster" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_create_aws_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_create_aws_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_create_aws_cluster" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_create_aws_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_create_aws_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11262,8 +11271,9 @@ def test_update_aws_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11465,19 +11475,21 @@ def test_update_aws_cluster_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_update_aws_cluster" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_update_aws_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_update_aws_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_update_aws_cluster" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_update_aws_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_update_aws_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11530,8 +11542,9 @@ def test_get_aws_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11610,17 +11623,19 @@ def test_get_aws_cluster_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_cluster" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_get_aws_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_get_aws_cluster" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_get_aws_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_get_aws_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11673,8 +11688,9 @@ def test_list_aws_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11737,17 +11753,20 @@ def test_list_aws_clusters_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_list_aws_clusters" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_list_aws_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_list_aws_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_list_aws_clusters" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_list_aws_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_list_aws_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11805,8 +11824,9 @@ def test_delete_aws_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11863,19 +11883,21 @@ def test_delete_aws_cluster_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_delete_aws_cluster" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_delete_aws_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_delete_aws_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_delete_aws_cluster" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_delete_aws_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_delete_aws_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11930,8 +11952,9 @@ def test_generate_aws_cluster_agent_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12000,18 +12023,22 @@ def test_generate_aws_cluster_agent_token_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_generate_aws_cluster_agent_token" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, - "post_generate_aws_cluster_agent_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_generate_aws_cluster_agent_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_generate_aws_cluster_agent_token", + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_generate_aws_cluster_agent_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "pre_generate_aws_cluster_agent_token", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12071,8 +12098,9 @@ def test_generate_aws_access_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12137,18 +12165,20 @@ def test_generate_aws_access_token_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_generate_aws_access_token" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, - "post_generate_aws_access_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_generate_aws_access_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_generate_aws_access_token" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_generate_aws_access_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_generate_aws_access_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12206,8 +12236,9 @@ def test_create_aws_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12390,19 +12421,21 @@ def test_create_aws_node_pool_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_create_aws_node_pool" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_create_aws_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_create_aws_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_create_aws_node_pool" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_create_aws_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_create_aws_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12459,8 +12492,9 @@ def test_update_aws_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12647,19 +12681,21 @@ def test_update_aws_node_pool_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_update_aws_node_pool" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_update_aws_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_update_aws_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_update_aws_node_pool" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_update_aws_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_update_aws_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12714,8 +12750,9 @@ def test_rollback_aws_node_pool_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12774,20 +12811,21 @@ def test_rollback_aws_node_pool_update_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_rollback_aws_node_pool_update" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, - "post_rollback_aws_node_pool_update_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_rollback_aws_node_pool_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_rollback_aws_node_pool_update" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_rollback_aws_node_pool_update_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_rollback_aws_node_pool_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12842,8 +12880,9 @@ def test_get_aws_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12920,17 +12959,20 @@ def test_get_aws_node_pool_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_node_pool" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_get_aws_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_get_aws_node_pool" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_get_aws_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_get_aws_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12983,8 +13025,9 @@ def test_list_aws_node_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13047,17 +13090,20 @@ def test_list_aws_node_pools_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_list_aws_node_pools" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_list_aws_node_pools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_list_aws_node_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_list_aws_node_pools" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_list_aws_node_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_list_aws_node_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13117,8 +13163,9 @@ def test_delete_aws_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13177,19 +13224,21 @@ def test_delete_aws_node_pool_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AwsClustersRestInterceptor, "post_delete_aws_node_pool" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_delete_aws_node_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_delete_aws_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_delete_aws_node_pool" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_delete_aws_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_delete_aws_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13244,8 +13293,9 @@ def test_get_aws_open_id_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13326,18 +13376,20 @@ def test_get_aws_open_id_config_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_open_id_config" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, - "post_get_aws_open_id_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_get_aws_open_id_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_get_aws_open_id_config" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_get_aws_open_id_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_get_aws_open_id_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13394,8 +13446,9 @@ def test_get_aws_json_web_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13457,18 +13510,20 @@ def test_get_aws_json_web_keys_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_json_web_keys" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, - "post_get_aws_json_web_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_get_aws_json_web_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_get_aws_json_web_keys" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_get_aws_json_web_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_get_aws_json_web_keys" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13523,8 +13578,9 @@ def test_get_aws_server_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13589,18 +13645,20 @@ def test_get_aws_server_config_rest_interceptors(null_interceptor): ) client = AwsClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AwsClustersRestInterceptor, "post_get_aws_server_config" - ) as post, mock.patch.object( - transports.AwsClustersRestInterceptor, - "post_get_aws_server_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AwsClustersRestInterceptor, "pre_get_aws_server_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AwsClustersRestInterceptor, "post_get_aws_server_config" + ) as post, + mock.patch.object( + transports.AwsClustersRestInterceptor, + "post_get_aws_server_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AwsClustersRestInterceptor, "pre_get_aws_server_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13657,8 +13715,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13719,8 +13778,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13781,8 +13841,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13843,8 +13904,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -14343,11 +14405,14 @@ def test_aws_clusters_base_transport(): def test_aws_clusters_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gke_multicloud_v1.services.aws_clusters.transports.AwsClustersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gke_multicloud_v1.services.aws_clusters.transports.AwsClustersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AwsClustersTransport( @@ -14364,9 +14429,12 @@ def test_aws_clusters_base_transport_with_credentials_file(): def test_aws_clusters_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gke_multicloud_v1.services.aws_clusters.transports.AwsClustersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gke_multicloud_v1.services.aws_clusters.transports.AwsClustersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AwsClustersTransport() @@ -14438,11 +14506,12 @@ def test_aws_clusters_transport_auth_gdch_credentials(transport_class): def test_aws_clusters_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -15129,6 +15198,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AwsClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AwsClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15268,6 +15369,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AwsClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AwsClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15413,6 +15546,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AwsClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AwsClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -15558,6 +15725,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AwsClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AwsClustersClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py index a7fa8d393eb5..696650c64980 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AzureClustersClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): assert ( AzureClustersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AzureClustersClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1288,11 +1293,13 @@ def test_azure_clusters_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -13468,8 +13475,9 @@ def test_create_azure_client_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13604,20 +13612,21 @@ def test_create_azure_client_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_create_azure_client" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_create_azure_client_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_create_azure_client" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_create_azure_client" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_create_azure_client_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_create_azure_client" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13670,8 +13679,9 @@ def test_get_azure_client_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13744,17 +13754,20 @@ def test_get_azure_client_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_client" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_client_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_get_azure_client" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_get_azure_client" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_get_azure_client_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_get_azure_client" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13809,8 +13822,9 @@ def test_list_azure_clients_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13873,17 +13887,20 @@ def test_list_azure_clients_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_list_azure_clients" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_list_azure_clients_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_list_azure_clients" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_list_azure_clients" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_list_azure_clients_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_list_azure_clients" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -13941,8 +13958,9 @@ def test_delete_azure_client_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -13999,20 +14017,21 @@ def test_delete_azure_client_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_delete_azure_client" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_delete_azure_client_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_delete_azure_client" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_delete_azure_client" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_delete_azure_client_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_delete_azure_client" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14065,8 +14084,9 @@ def test_create_azure_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14267,20 +14287,21 @@ def test_create_azure_cluster_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_create_azure_cluster" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_create_azure_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_create_azure_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_create_azure_cluster" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_create_azure_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_create_azure_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14337,8 +14358,9 @@ def test_update_azure_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14543,20 +14565,21 @@ def test_update_azure_cluster_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_update_azure_cluster" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_update_azure_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_update_azure_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_update_azure_cluster" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_update_azure_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_update_azure_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14609,8 +14632,9 @@ def test_get_azure_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14693,17 +14717,20 @@ def test_get_azure_cluster_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_cluster" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_get_azure_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_get_azure_cluster" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_get_azure_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_get_azure_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14758,8 +14785,9 @@ def test_list_azure_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14822,18 +14850,20 @@ def test_list_azure_clusters_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_list_azure_clusters" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_list_azure_clusters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_list_azure_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_list_azure_clusters" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_list_azure_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_list_azure_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14891,8 +14921,9 @@ def test_delete_azure_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14949,20 +14980,21 @@ def test_delete_azure_cluster_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_delete_azure_cluster" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_delete_azure_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_delete_azure_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_delete_azure_cluster" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_delete_azure_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_delete_azure_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15017,8 +15049,9 @@ def test_generate_azure_cluster_agent_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15089,20 +15122,22 @@ def test_generate_azure_cluster_agent_token_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_generate_azure_cluster_agent_token", - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_generate_azure_cluster_agent_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, - "pre_generate_azure_cluster_agent_token", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_generate_azure_cluster_agent_token", + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_generate_azure_cluster_agent_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "pre_generate_azure_cluster_agent_token", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15162,8 +15197,9 @@ def test_generate_azure_access_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15228,18 +15264,20 @@ def test_generate_azure_access_token_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_generate_azure_access_token" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_generate_azure_access_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_generate_azure_access_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_generate_azure_access_token" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_generate_azure_access_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_generate_azure_access_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15299,8 +15337,9 @@ def test_create_azure_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15460,20 +15499,21 @@ def test_create_azure_node_pool_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_create_azure_node_pool" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_create_azure_node_pool_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_create_azure_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_create_azure_node_pool" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_create_azure_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_create_azure_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15530,8 +15570,9 @@ def test_update_azure_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15693,20 +15734,21 @@ def test_update_azure_node_pool_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_update_azure_node_pool" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_update_azure_node_pool_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_update_azure_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_update_azure_node_pool" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_update_azure_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_update_azure_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15761,8 +15803,9 @@ def test_get_azure_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15841,18 +15884,20 @@ def test_get_azure_node_pool_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_node_pool" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_get_azure_node_pool_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_get_azure_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_get_azure_node_pool" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_get_azure_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_get_azure_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15909,8 +15954,9 @@ def test_list_azure_node_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15975,18 +16021,20 @@ def test_list_azure_node_pools_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_list_azure_node_pools" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_list_azure_node_pools_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_list_azure_node_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_list_azure_node_pools" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_list_azure_node_pools_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_list_azure_node_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16046,8 +16094,9 @@ def test_delete_azure_node_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16106,20 +16155,21 @@ def test_delete_azure_node_pool_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AzureClustersRestInterceptor, "post_delete_azure_node_pool" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_delete_azure_node_pool_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_delete_azure_node_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_delete_azure_node_pool" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_delete_azure_node_pool_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_delete_azure_node_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16174,8 +16224,9 @@ def test_get_azure_open_id_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16256,18 +16307,20 @@ def test_get_azure_open_id_config_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_open_id_config" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_get_azure_open_id_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_get_azure_open_id_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_get_azure_open_id_config" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_get_azure_open_id_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_get_azure_open_id_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16324,8 +16377,9 @@ def test_get_azure_json_web_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16387,18 +16441,20 @@ def test_get_azure_json_web_keys_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_json_web_keys" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_get_azure_json_web_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_get_azure_json_web_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_get_azure_json_web_keys" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_get_azure_json_web_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_get_azure_json_web_keys" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16453,8 +16509,9 @@ def test_get_azure_server_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16519,18 +16576,20 @@ def test_get_azure_server_config_rest_interceptors(null_interceptor): ) client = AzureClustersClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AzureClustersRestInterceptor, "post_get_azure_server_config" - ) as post, mock.patch.object( - transports.AzureClustersRestInterceptor, - "post_get_azure_server_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AzureClustersRestInterceptor, "pre_get_azure_server_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AzureClustersRestInterceptor, "post_get_azure_server_config" + ) as post, + mock.patch.object( + transports.AzureClustersRestInterceptor, + "post_get_azure_server_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AzureClustersRestInterceptor, "pre_get_azure_server_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16587,8 +16646,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16649,8 +16709,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16711,8 +16772,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -16773,8 +16835,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -17342,11 +17405,14 @@ def test_azure_clusters_base_transport(): def test_azure_clusters_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gke_multicloud_v1.services.azure_clusters.transports.AzureClustersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gke_multicloud_v1.services.azure_clusters.transports.AzureClustersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AzureClustersTransport( @@ -17363,9 +17429,12 @@ def test_azure_clusters_base_transport_with_credentials_file(): def test_azure_clusters_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gke_multicloud_v1.services.azure_clusters.transports.AzureClustersTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gke_multicloud_v1.services.azure_clusters.transports.AzureClustersTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AzureClustersTransport() @@ -17437,11 +17506,12 @@ def test_azure_clusters_transport_auth_gdch_credentials(transport_class): def test_azure_clusters_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -18174,6 +18244,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = AzureClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = AzureClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18313,6 +18415,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = AzureClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = AzureClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18458,6 +18592,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AzureClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = AzureClustersClient( credentials=ga_credentials.AnonymousCredentials(), @@ -18603,6 +18771,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = AzureClustersAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = AzureClustersClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/async_client.py b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/async_client.py index 4be7e915d76a..37e63f3e85cf 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/async_client.py +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/async_client.py @@ -193,7 +193,7 @@ def transport(self) -> GkeInferenceQuickstartTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/client.py b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/client.py index b45335526af0..f51b65d3b462 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/client.py +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/client.py @@ -113,7 +113,7 @@ class GkeInferenceQuickstartClient(metaclass=GkeInferenceQuickstartClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -416,7 +420,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -515,7 +519,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -615,7 +619,7 @@ def __init__( self._universe_domain = GkeInferenceQuickstartClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/README.rst b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/README.rst index bbcb4a6af96c..b6f11cfae72b 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/README.rst +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GkeInferenceQuickstartTransport` is the ABC for all transports. -- public child `GkeInferenceQuickstartGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GkeInferenceQuickstartGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGkeInferenceQuickstartRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GkeInferenceQuickstartRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GkeInferenceQuickstartTransport`` is the ABC for all transports. + +- public child ``GkeInferenceQuickstartGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GkeInferenceQuickstartGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGkeInferenceQuickstartRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GkeInferenceQuickstartRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/base.py b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/base.py index 61d445d94263..6998573de5b1 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/base.py +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc.py b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc.py index a7dafae89407..ae5f1193d196 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc.py +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc_asyncio.py b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc_asyncio.py index 4deac0db9bf6..2e6e74d955da 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc_asyncio.py +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/rest.py b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/rest.py index 7034aaf3f34c..9a110032df73 100644 --- a/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/rest.py +++ b/packages/google-cloud-gkerecommender/google/cloud/gkerecommender_v1/services/gke_inference_quickstart/transports/rest.py @@ -503,6 +503,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GkeInferenceQuickstartRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gkerecommender/noxfile.py b/packages/google-cloud-gkerecommender/noxfile.py index 506f7b52dd9f..d1f49e0a917b 100644 --- a/packages/google-cloud-gkerecommender/noxfile.py +++ b/packages/google-cloud-gkerecommender/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gkerecommender/setup.py b/packages/google-cloud-gkerecommender/setup.py index 56f6e14e9a1d..8e2b9f0e0979 100644 --- a/packages/google-cloud-gkerecommender/setup.py +++ b/packages/google-cloud-gkerecommender/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-gkerecommender" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gkerecommender/testing/constraints-3.7.txt b/packages/google-cloud-gkerecommender/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-gkerecommender/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-gkerecommender/testing/constraints-3.8.txt b/packages/google-cloud-gkerecommender/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-gkerecommender/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-gkerecommender/testing/constraints-3.9.txt b/packages/google-cloud-gkerecommender/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-gkerecommender/testing/constraints-3.9.txt +++ b/packages/google-cloud-gkerecommender/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-gkerecommender/tests/unit/gapic/gkerecommender_v1/test_gke_inference_quickstart.py b/packages/google-cloud-gkerecommender/tests/unit/gapic/gkerecommender_v1/test_gke_inference_quickstart.py index ebb9105db543..33006363d3dd 100644 --- a/packages/google-cloud-gkerecommender/tests/unit/gapic/gkerecommender_v1/test_gke_inference_quickstart.py +++ b/packages/google-cloud-gkerecommender/tests/unit/gapic/gkerecommender_v1/test_gke_inference_quickstart.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GkeInferenceQuickstartClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): GkeInferenceQuickstartClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + GkeInferenceQuickstartClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1346,11 +1351,13 @@ def test_gke_inference_quickstart_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4656,8 +4663,9 @@ def test_fetch_models_rest_bad_request(request_type=gkerecommender.FetchModelsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4722,18 +4730,20 @@ def test_fetch_models_rest_interceptors(null_interceptor): ) client = GkeInferenceQuickstartClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_models" - ) as post, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_fetch_models_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_models" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_models" + ) as post, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_models_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_models" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4788,8 +4798,9 @@ def test_fetch_model_servers_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4854,18 +4865,20 @@ def test_fetch_model_servers_rest_interceptors(null_interceptor): ) client = GkeInferenceQuickstartClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_model_servers" - ) as post, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_fetch_model_servers_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_model_servers" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_model_servers" + ) as post, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_model_servers_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_model_servers" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4923,8 +4936,9 @@ def test_fetch_model_server_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4989,20 +5003,22 @@ def test_fetch_model_server_versions_rest_interceptors(null_interceptor): ) client = GkeInferenceQuickstartClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_fetch_model_server_versions", - ) as post, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_fetch_model_server_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "pre_fetch_model_server_versions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_model_server_versions", + ) as post, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_model_server_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "pre_fetch_model_server_versions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5060,8 +5076,9 @@ def test_fetch_profiles_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5126,18 +5143,20 @@ def test_fetch_profiles_rest_interceptors(null_interceptor): ) client = GkeInferenceQuickstartClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_profiles" - ) as post, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_fetch_profiles_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_profiles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_profiles" + ) as post, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_profiles_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_profiles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5195,8 +5214,9 @@ def test_generate_optimized_manifest_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5261,20 +5281,22 @@ def test_generate_optimized_manifest_rest_interceptors(null_interceptor): ) client = GkeInferenceQuickstartClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_generate_optimized_manifest", - ) as post, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_generate_optimized_manifest_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "pre_generate_optimized_manifest", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_generate_optimized_manifest", + ) as post, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_generate_optimized_manifest_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "pre_generate_optimized_manifest", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5332,8 +5354,9 @@ def test_fetch_benchmarking_data_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5393,18 +5416,22 @@ def test_fetch_benchmarking_data_rest_interceptors(null_interceptor): ) client = GkeInferenceQuickstartClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "post_fetch_benchmarking_data" - ) as post, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, - "post_fetch_benchmarking_data_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.GkeInferenceQuickstartRestInterceptor, "pre_fetch_benchmarking_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_benchmarking_data", + ) as post, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "post_fetch_benchmarking_data_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GkeInferenceQuickstartRestInterceptor, + "pre_fetch_benchmarking_data", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5644,11 +5671,14 @@ def test_gke_inference_quickstart_base_transport(): def test_gke_inference_quickstart_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gkerecommender_v1.services.gke_inference_quickstart.transports.GkeInferenceQuickstartTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gkerecommender_v1.services.gke_inference_quickstart.transports.GkeInferenceQuickstartTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeInferenceQuickstartTransport( @@ -5665,9 +5695,12 @@ def test_gke_inference_quickstart_base_transport_with_credentials_file(): def test_gke_inference_quickstart_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gkerecommender_v1.services.gke_inference_quickstart.transports.GkeInferenceQuickstartTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gkerecommender_v1.services.gke_inference_quickstart.transports.GkeInferenceQuickstartTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GkeInferenceQuickstartTransport() @@ -5741,11 +5774,12 @@ def test_gke_inference_quickstart_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py index 5dfd67a0d294..9381f6471873 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py @@ -224,7 +224,7 @@ def transport(self) -> GSuiteAddOnsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py index 17893d449cef..19cbbeec18d4 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py @@ -146,7 +146,7 @@ class GSuiteAddOnsClient(metaclass=GSuiteAddOnsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -154,7 +154,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -164,6 +164,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -503,7 +507,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -600,7 +604,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -696,7 +700,7 @@ def __init__( self._universe_domain = GSuiteAddOnsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/README.rst b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/README.rst index 498eddcc1377..3f3c1bc10426 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/README.rst +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GSuiteAddOnsTransport` is the ABC for all transports. -- public child `GSuiteAddOnsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GSuiteAddOnsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGSuiteAddOnsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GSuiteAddOnsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GSuiteAddOnsTransport`` is the ABC for all transports. + +- public child ``GSuiteAddOnsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GSuiteAddOnsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGSuiteAddOnsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GSuiteAddOnsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py index 5aab5b8f99f7..b67bc8d4b926 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py index 60b937b7b5d2..e20aee462368 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -219,6 +219,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py index a2bf53a09f88..8af9dee3ed57 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -270,6 +270,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py index 3367d453a79e..a23e10dfa782 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py @@ -572,6 +572,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[GSuiteAddOnsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index 92d9fccab09f..873842cc280d 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-gsuiteaddons/setup.py b/packages/google-cloud-gsuiteaddons/setup.py index cd420c0b0ccc..b8fe9484984a 100644 --- a/packages/google-cloud-gsuiteaddons/setup.py +++ b/packages/google-cloud-gsuiteaddons/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "google-apps-script-type >= 0.2.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-gsuiteaddons/testing/constraints-3.7.txt b/packages/google-cloud-gsuiteaddons/testing/constraints-3.7.txt deleted file mode 100644 index 6d3e0a3337f3..000000000000 --- a/packages/google-cloud-gsuiteaddons/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -google-apps-script-type==0.2.0 diff --git a/packages/google-cloud-gsuiteaddons/testing/constraints-3.8.txt b/packages/google-cloud-gsuiteaddons/testing/constraints-3.8.txt deleted file mode 100644 index ffb95b6193b0..000000000000 --- a/packages/google-cloud-gsuiteaddons/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-apps-script-type diff --git a/packages/google-cloud-gsuiteaddons/testing/constraints-3.9.txt b/packages/google-cloud-gsuiteaddons/testing/constraints-3.9.txt index ffb95b6193b0..b84195e269ac 100644 --- a/packages/google-cloud-gsuiteaddons/testing/constraints-3.9.txt +++ b/packages/google-cloud-gsuiteaddons/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-apps-script-type +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +google-apps-script-type==0.2.0 diff --git a/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py b/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py index c7180a6bbba6..8774ddf10696 100644 --- a/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py +++ b/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GSuiteAddOnsClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GSuiteAddOnsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + GSuiteAddOnsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1270,11 +1275,13 @@ def test_g_suite_add_ons_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6839,8 +6846,9 @@ def test_get_authorization_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6907,17 +6915,20 @@ def test_get_authorization_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_get_authorization" - ) as post, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_get_authorization_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_get_authorization" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_get_authorization" + ) as post, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, + "post_get_authorization_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_get_authorization" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6970,8 +6981,9 @@ def test_create_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7204,17 +7216,20 @@ def test_create_deployment_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_create_deployment" - ) as post, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_create_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_create_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_create_deployment" + ) as post, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, + "post_create_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_create_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7267,8 +7282,9 @@ def test_replace_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7501,17 +7517,20 @@ def test_replace_deployment_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_replace_deployment" - ) as post, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_replace_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_replace_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_replace_deployment" + ) as post, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, + "post_replace_deployment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_replace_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7564,8 +7583,9 @@ def test_get_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7632,17 +7652,19 @@ def test_get_deployment_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_get_deployment" - ) as post, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_get_deployment_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_get_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_get_deployment" + ) as post, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_get_deployment_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_get_deployment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7695,8 +7717,9 @@ def test_list_deployments_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7759,17 +7782,20 @@ def test_list_deployments_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_list_deployments" - ) as post, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_list_deployments_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_list_deployments" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_list_deployments" + ) as post, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, + "post_list_deployments_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_list_deployments" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7827,8 +7853,9 @@ def test_delete_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7885,13 +7912,13 @@ def test_delete_deployment_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_delete_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_delete_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = gsuiteaddons.DeleteDeploymentRequest.pb( gsuiteaddons.DeleteDeploymentRequest() @@ -7936,8 +7963,9 @@ def test_install_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7994,13 +8022,13 @@ def test_install_deployment_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_install_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_install_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = gsuiteaddons.InstallDeploymentRequest.pb( gsuiteaddons.InstallDeploymentRequest() @@ -8045,8 +8073,9 @@ def test_uninstall_deployment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8103,13 +8132,13 @@ def test_uninstall_deployment_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_uninstall_deployment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_uninstall_deployment" + ) as pre, + ): pre.assert_not_called() pb_message = gsuiteaddons.UninstallDeploymentRequest.pb( gsuiteaddons.UninstallDeploymentRequest() @@ -8154,8 +8183,9 @@ def test_get_install_status_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8218,17 +8248,20 @@ def test_get_install_status_rest_interceptors(null_interceptor): ) client = GSuiteAddOnsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_get_install_status" - ) as post, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "post_get_install_status_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.GSuiteAddOnsRestInterceptor, "pre_get_install_status" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "post_get_install_status" + ) as post, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, + "post_get_install_status_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.GSuiteAddOnsRestInterceptor, "pre_get_install_status" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8532,11 +8565,14 @@ def test_g_suite_add_ons_base_transport(): def test_g_suite_add_ons_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.gsuiteaddons_v1.services.g_suite_add_ons.transports.GSuiteAddOnsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.gsuiteaddons_v1.services.g_suite_add_ons.transports.GSuiteAddOnsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GSuiteAddOnsTransport( @@ -8553,9 +8589,12 @@ def test_g_suite_add_ons_base_transport_with_credentials_file(): def test_g_suite_add_ons_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.gsuiteaddons_v1.services.g_suite_add_ons.transports.GSuiteAddOnsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.gsuiteaddons_v1.services.g_suite_add_ons.transports.GSuiteAddOnsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GSuiteAddOnsTransport() @@ -8627,11 +8666,12 @@ def test_g_suite_add_ons_transport_auth_gdch_credentials(transport_class): def test_g_suite_add_ons_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/async_client.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/async_client.py index c98ca65f0a35..9fb48433d089 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/async_client.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/async_client.py @@ -224,7 +224,7 @@ def transport(self) -> HypercomputeClusterTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1022,7 +1022,7 @@ async def sample_delete_cluster(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1048,8 +1048,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1058,7 +1062,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1066,7 +1070,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1077,7 +1081,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1103,8 +1107,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1113,7 +1121,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1121,7 +1129,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1132,7 +1140,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1162,8 +1170,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1172,7 +1184,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1180,7 +1192,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1188,7 +1200,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1217,8 +1229,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1227,7 +1243,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1235,7 +1251,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1243,7 +1259,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1269,8 +1285,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1279,7 +1299,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1287,7 +1307,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1298,7 +1318,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1324,8 +1344,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1334,7 +1358,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1342,7 +1366,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/client.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/client.py index 769118df2ec3..857d157c3f06 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/client.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/client.py @@ -120,7 +120,7 @@ class HypercomputeClusterClient(metaclass=HypercomputeClusterClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -613,7 +617,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -710,7 +714,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -810,7 +814,7 @@ def __init__( self._universe_domain = HypercomputeClusterClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1591,7 +1595,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1617,8 +1621,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1627,7 +1635,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1636,7 +1644,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1650,7 +1658,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1676,8 +1684,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1686,7 +1698,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1695,7 +1707,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1709,7 +1721,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1739,8 +1751,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1749,7 +1765,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1757,7 +1773,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1765,7 +1781,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1794,8 +1810,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1804,7 +1824,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1812,7 +1832,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1820,7 +1840,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1846,8 +1866,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1856,7 +1880,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1865,7 +1889,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1879,7 +1903,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1905,8 +1929,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1915,7 +1943,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1924,7 +1952,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/README.rst b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/README.rst index d2bd7a88e4be..84ddae1c5f7c 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/README.rst +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HypercomputeClusterTransport` is the ABC for all transports. -- public child `HypercomputeClusterGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HypercomputeClusterGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHypercomputeClusterRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HypercomputeClusterRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HypercomputeClusterTransport`` is the ABC for all transports. + +- public child ``HypercomputeClusterGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HypercomputeClusterGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHypercomputeClusterRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HypercomputeClusterRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/base.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/base.py index 813187d28473..4c049175bac6 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/base.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc.py index 338c82b6fe17..8b50c96ea5c5 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc_asyncio.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc_asyncio.py index 8ea533019260..065e6c2bea51 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc_asyncio.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/rest.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/rest.py index 983c7b090dd1..b6005e6aa85b 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/rest.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1/services/hypercompute_cluster/transports/rest.py @@ -580,6 +580,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[HypercomputeClusterRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/async_client.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/async_client.py index 3f43b04df27e..3fe0f0cc7d4e 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/async_client.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/async_client.py @@ -226,7 +226,7 @@ def transport(self) -> HypercomputeClusterTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1024,7 +1024,7 @@ async def sample_delete_cluster(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1050,8 +1050,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1060,7 +1064,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1068,7 +1072,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1079,7 +1083,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1105,8 +1109,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1115,7 +1123,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1123,7 +1131,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1134,7 +1142,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1164,8 +1172,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1174,7 +1186,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1182,7 +1194,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1190,7 +1202,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1219,8 +1231,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1229,7 +1245,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1237,7 +1253,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1245,7 +1261,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1271,8 +1287,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1281,7 +1301,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1289,7 +1309,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1300,7 +1320,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1326,8 +1346,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1336,7 +1360,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1344,7 +1368,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/client.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/client.py index 1208e3c0e0aa..fcfb0134407a 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/client.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/client.py @@ -120,7 +120,7 @@ class HypercomputeClusterClient(metaclass=HypercomputeClusterClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -613,7 +617,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -710,7 +714,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -810,7 +814,7 @@ def __init__( self._universe_domain = HypercomputeClusterClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1591,7 +1595,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1617,8 +1621,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1627,7 +1635,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1636,7 +1644,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1650,7 +1658,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1676,8 +1684,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1686,7 +1698,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1695,7 +1707,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1709,7 +1721,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1739,8 +1751,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1749,7 +1765,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1757,7 +1773,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1765,7 +1781,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1794,8 +1810,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1804,7 +1824,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1812,7 +1832,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1820,7 +1840,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1846,8 +1866,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1856,7 +1880,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1865,7 +1889,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1879,7 +1903,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1905,8 +1929,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1915,7 +1943,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1924,7 +1952,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/README.rst b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/README.rst index d2bd7a88e4be..84ddae1c5f7c 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/README.rst +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HypercomputeClusterTransport` is the ABC for all transports. -- public child `HypercomputeClusterGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HypercomputeClusterGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHypercomputeClusterRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HypercomputeClusterRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HypercomputeClusterTransport`` is the ABC for all transports. + +- public child ``HypercomputeClusterGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HypercomputeClusterGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHypercomputeClusterRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HypercomputeClusterRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/base.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/base.py index 82d119d4dcff..e1267bd04bd8 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/base.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc.py index ef7e2588bd28..b272ff9ae298 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc_asyncio.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc_asyncio.py index dd358f58de24..25e25618e0f0 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc_asyncio.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/rest.py b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/rest.py index 000598d31420..cf7b03a589f7 100644 --- a/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/rest.py +++ b/packages/google-cloud-hypercomputecluster/google/cloud/hypercomputecluster_v1beta/services/hypercompute_cluster/transports/rest.py @@ -580,6 +580,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[HypercomputeClusterRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-hypercomputecluster/noxfile.py b/packages/google-cloud-hypercomputecluster/noxfile.py index f4afdd80dbc6..428be23a5713 100644 --- a/packages/google-cloud-hypercomputecluster/noxfile.py +++ b/packages/google-cloud-hypercomputecluster/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-hypercomputecluster/setup.py b/packages/google-cloud-hypercomputecluster/setup.py index 3771987287e4..23dfeadbdb18 100644 --- a/packages/google-cloud-hypercomputecluster/setup.py +++ b/packages/google-cloud-hypercomputecluster/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-hypercomputecluster" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-hypercomputecluster/testing/constraints-3.7.txt b/packages/google-cloud-hypercomputecluster/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-hypercomputecluster/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-hypercomputecluster/testing/constraints-3.8.txt b/packages/google-cloud-hypercomputecluster/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-hypercomputecluster/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-hypercomputecluster/testing/constraints-3.9.txt b/packages/google-cloud-hypercomputecluster/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-hypercomputecluster/testing/constraints-3.9.txt +++ b/packages/google-cloud-hypercomputecluster/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1/test_hypercompute_cluster.py b/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1/test_hypercompute_cluster.py index 78012607e8ab..10d5f348a4ab 100644 --- a/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1/test_hypercompute_cluster.py +++ b/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1/test_hypercompute_cluster.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert HypercomputeClusterClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): HypercomputeClusterClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + HypercomputeClusterClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1353,11 +1358,13 @@ def test_hypercompute_cluster_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4646,8 +4653,9 @@ def test_list_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4712,18 +4720,20 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_list_clusters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_list_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4781,8 +4791,9 @@ def test_get_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4849,17 +4860,20 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_get_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4914,8 +4928,9 @@ def test_create_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5097,20 +5112,21 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_create_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_create_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5165,8 +5181,9 @@ def test_update_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5350,20 +5367,21 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_update_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_update_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5416,8 +5434,9 @@ def test_delete_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5474,20 +5493,21 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_delete_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_delete_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5540,8 +5560,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5600,8 +5621,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5662,8 +5684,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5724,8 +5747,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5786,8 +5810,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5848,8 +5873,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6089,11 +6115,14 @@ def test_hypercompute_cluster_base_transport(): def test_hypercompute_cluster_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.hypercomputecluster_v1.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.hypercomputecluster_v1.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HypercomputeClusterTransport( @@ -6110,9 +6139,12 @@ def test_hypercompute_cluster_base_transport_with_credentials_file(): def test_hypercompute_cluster_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.hypercomputecluster_v1.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.hypercomputecluster_v1.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HypercomputeClusterTransport() @@ -6184,11 +6216,12 @@ def test_hypercompute_cluster_transport_auth_gdch_credentials(transport_class): def test_hypercompute_cluster_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7001,6 +7034,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7140,6 +7205,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7285,6 +7382,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7430,6 +7561,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7575,6 +7740,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7718,6 +7917,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1beta/test_hypercompute_cluster.py b/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1beta/test_hypercompute_cluster.py index 1afadc12f5eb..cd3be4429e24 100644 --- a/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1beta/test_hypercompute_cluster.py +++ b/packages/google-cloud-hypercomputecluster/tests/unit/gapic/hypercomputecluster_v1beta/test_hypercompute_cluster.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert HypercomputeClusterClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): HypercomputeClusterClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + HypercomputeClusterClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1353,11 +1358,13 @@ def test_hypercompute_cluster_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4650,8 +4657,9 @@ def test_list_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4716,18 +4724,20 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_list_clusters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_list_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4785,8 +4795,9 @@ def test_get_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4853,17 +4864,20 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_get_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4918,8 +4932,9 @@ def test_create_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5101,20 +5116,21 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_create_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_create_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5169,8 +5185,9 @@ def test_update_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5354,20 +5371,21 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_update_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_update_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5420,8 +5438,9 @@ def test_delete_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5478,20 +5497,21 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = HypercomputeClusterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, - "post_delete_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HypercomputeClusterRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, + "post_delete_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HypercomputeClusterRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5544,8 +5564,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5604,8 +5625,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5666,8 +5688,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5728,8 +5751,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5790,8 +5814,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5852,8 +5877,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6093,11 +6119,14 @@ def test_hypercompute_cluster_base_transport(): def test_hypercompute_cluster_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.hypercomputecluster_v1beta.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.hypercomputecluster_v1beta.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HypercomputeClusterTransport( @@ -6114,9 +6143,12 @@ def test_hypercompute_cluster_base_transport_with_credentials_file(): def test_hypercompute_cluster_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.hypercomputecluster_v1beta.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.hypercomputecluster_v1beta.services.hypercompute_cluster.transports.HypercomputeClusterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HypercomputeClusterTransport() @@ -6188,11 +6220,12 @@ def test_hypercompute_cluster_transport_auth_gdch_credentials(transport_class): def test_hypercompute_cluster_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7005,6 +7038,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7144,6 +7209,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7289,6 +7386,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7434,6 +7565,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7579,6 +7744,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -7722,6 +7921,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = HypercomputeClusterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = HypercomputeClusterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = HypercomputeClusterClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iam-logging/noxfile.py b/packages/google-cloud-iam-logging/noxfile.py index 878adf92b909..4781784ec314 100644 --- a/packages/google-cloud-iam-logging/noxfile.py +++ b/packages/google-cloud-iam-logging/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-iam-logging/setup.py b/packages/google-cloud-iam-logging/setup.py index 46bbea39c8fe..0f18b42b6026 100644 --- a/packages/google-cloud-iam-logging/setup.py +++ b/packages/google-cloud-iam-logging/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-iam-logging/testing/constraints-3.7.txt b/packages/google-cloud-iam-logging/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-iam-logging/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-iam-logging/testing/constraints-3.8.txt b/packages/google-cloud-iam-logging/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-iam-logging/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-iam-logging/testing/constraints-3.9.txt b/packages/google-cloud-iam-logging/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-iam-logging/testing/constraints-3.9.txt +++ b/packages/google-cloud-iam-logging/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/async_client.py b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/async_client.py index d4c79293b96c..e5debd1132bd 100644 --- a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> IAMTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/client.py b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/client.py index 5f0e25a4e1d3..c465ac99dc88 100644 --- a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/client.py @@ -141,7 +141,7 @@ class IAMClient(metaclass=IAMClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -149,7 +149,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -159,6 +159,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -486,7 +490,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -583,7 +587,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -679,7 +683,7 @@ def __init__( self._universe_domain = IAMClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/README.rst index cb18b04ffba8..7c0131e29db9 100644 --- a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IAMTransport` is the ABC for all transports. -- public child `IAMGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IAMGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIAMRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IAMRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IAMTransport`` is the ABC for all transports. + +- public child ``IAMGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IAMGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIAMRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IAMRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/base.py index a10c812f43ea..bc215de42e00 100644 --- a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc.py index c2b79256b946..6feb1b205de6 100644 --- a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -216,6 +216,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc_asyncio.py index 6345576ee1dc..92ced69c6d65 100644 --- a/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_admin_v1/services/iam/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -267,6 +267,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py index 157a4c2fadc4..cfd5a7b2dce6 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py @@ -199,7 +199,7 @@ def transport(self) -> IAMCredentialsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py index d3d342308e38..db33e92d2c1d 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py @@ -121,7 +121,7 @@ class IAMCredentialsClient(metaclass=IAMCredentialsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -444,7 +448,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -541,7 +545,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -637,7 +641,7 @@ def __init__( self._universe_domain = IAMCredentialsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/README.rst index b4c630e83951..a297f649e6f9 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IAMCredentialsTransport` is the ABC for all transports. -- public child `IAMCredentialsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IAMCredentialsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIAMCredentialsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IAMCredentialsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IAMCredentialsTransport`` is the ABC for all transports. + +- public child ``IAMCredentialsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IAMCredentialsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIAMCredentialsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IAMCredentialsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py index 3f110d50a81a..9eaf10c10ffe 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py index e3c505cdba44..538ea7436ff8 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py index c265affb206e..97da99bf009a 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py index 923726aefacb..9f0031cf53af 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py @@ -372,6 +372,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IAMCredentialsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py index 6fa7fe2f7b3c..8f242ac62ab1 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> PoliciesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -956,7 +956,7 @@ async def sample_delete_policy(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -982,8 +982,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -992,7 +996,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1000,7 +1004,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py index 24532526e102..16b2dcb59777 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py @@ -117,7 +117,7 @@ class PoliciesClient(metaclass=PoliciesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -420,7 +424,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -517,7 +521,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -613,7 +617,7 @@ def __init__( self._universe_domain = PoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1370,7 +1374,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1396,8 +1400,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1406,7 +1414,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1415,7 +1423,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/README.rst index 2d1866387a31..46b936b7b345 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PoliciesTransport` is the ABC for all transports. -- public child `PoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PoliciesTransport`` is the ABC for all transports. + +- public child ``PoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py index 058a38866f4c..cc1733c65e41 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py index 3c5c312406b2..2de58f7229fe 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py index 7074aeaa5624..efffd3af56fc 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py index b341cbecc3f9..2b2649a9e0f7 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py @@ -439,6 +439,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py index f40a25ca5ff1..ad02c6fa19ea 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py @@ -183,7 +183,7 @@ def transport(self) -> PoliciesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -956,7 +956,7 @@ async def sample_delete_policy(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -982,8 +982,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -992,7 +996,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1000,7 +1004,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py index f91d54658658..ad98836be96d 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py @@ -115,7 +115,7 @@ class PoliciesClient(metaclass=PoliciesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -418,7 +422,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -515,7 +519,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -611,7 +615,7 @@ def __init__( self._universe_domain = PoliciesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1368,7 +1372,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1394,8 +1398,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1404,7 +1412,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1413,7 +1421,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/README.rst index 2d1866387a31..46b936b7b345 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PoliciesTransport` is the ABC for all transports. -- public child `PoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PoliciesTransport`` is the ABC for all transports. + +- public child ``PoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py index 5d6efea36657..1e86a2cf7045 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py index f7e4c686964f..78c12b678db0 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py index eb72ec35548d..f035c4bee1ff 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/async_client.py index 212aeaafd539..28fcd3139ab9 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> PolicyBindingsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1191,7 +1191,7 @@ async def sample_search_target_policy_bindings(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1217,8 +1217,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1227,7 +1231,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1235,7 +1239,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/client.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/client.py index 43868be62355..4f71e3514abf 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/client.py @@ -124,7 +124,7 @@ class PolicyBindingsClient(metaclass=PolicyBindingsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -546,7 +550,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -642,7 +646,7 @@ def __init__( self._universe_domain = PolicyBindingsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1616,7 +1620,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1642,8 +1646,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1652,7 +1660,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1661,7 +1669,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/README.rst index e7ddf4a1a8b6..0b32d5803cb7 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PolicyBindingsTransport` is the ABC for all transports. -- public child `PolicyBindingsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PolicyBindingsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePolicyBindingsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PolicyBindingsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PolicyBindingsTransport`` is the ABC for all transports. + +- public child ``PolicyBindingsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PolicyBindingsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePolicyBindingsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PolicyBindingsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/base.py index adcfd2c81f5c..bd22e891505b 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc.py index 85c7ddeed506..d2fdc72f349b 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc_asyncio.py index 66d20aa4a85f..ac6a3ca09b7c 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/rest.py index e98cedb36168..b385fd6584aa 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/policy_bindings/transports/rest.py @@ -523,6 +523,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PolicyBindingsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/async_client.py index 1f274821b6f0..3f8d9429710d 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/async_client.py @@ -227,7 +227,7 @@ def transport(self) -> PrincipalAccessBoundaryPoliciesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1226,7 +1226,7 @@ async def sample_search_principal_access_boundary_policy_bindings(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1252,8 +1252,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1262,7 +1266,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1270,7 +1274,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/client.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/client.py index e16af90c4b35..4118759bc726 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/client.py @@ -131,7 +131,7 @@ class PrincipalAccessBoundaryPoliciesClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -482,7 +486,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -581,7 +585,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -685,7 +689,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1684,7 +1688,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1710,8 +1714,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1720,7 +1728,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1729,7 +1737,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/README.rst index df9408ef0e5b..99e616390f45 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PrincipalAccessBoundaryPoliciesTransport` is the ABC for all transports. -- public child `PrincipalAccessBoundaryPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PrincipalAccessBoundaryPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePrincipalAccessBoundaryPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PrincipalAccessBoundaryPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PrincipalAccessBoundaryPoliciesTransport`` is the ABC for all transports. + +- public child ``PrincipalAccessBoundaryPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PrincipalAccessBoundaryPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePrincipalAccessBoundaryPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PrincipalAccessBoundaryPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/base.py index d44c8f935747..63a7c3b91d3f 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc.py index b59bbff9a0d7..1c5e1ba4baa7 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc_asyncio.py index d343d431a181..2968ad1613fc 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/rest.py index 6fae4c7654a6..2efc80013205 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3/services/principal_access_boundary_policies/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PrincipalAccessBoundaryPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/async_client.py index 01412e3d9e7d..46f846bc892d 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/async_client.py @@ -202,7 +202,7 @@ def transport(self) -> PolicyBindingsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1191,7 +1191,7 @@ async def sample_search_target_policy_bindings(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1217,8 +1217,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1227,7 +1231,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1235,7 +1239,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/client.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/client.py index 000d387752cc..0bbc1c8de412 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/client.py @@ -124,7 +124,7 @@ class PolicyBindingsClient(metaclass=PolicyBindingsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -546,7 +550,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -642,7 +646,7 @@ def __init__( self._universe_domain = PolicyBindingsClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1616,7 +1620,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1642,8 +1646,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1652,7 +1660,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1661,7 +1669,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/README.rst index e7ddf4a1a8b6..0b32d5803cb7 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PolicyBindingsTransport` is the ABC for all transports. -- public child `PolicyBindingsGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PolicyBindingsGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePolicyBindingsRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PolicyBindingsRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PolicyBindingsTransport`` is the ABC for all transports. + +- public child ``PolicyBindingsGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PolicyBindingsGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePolicyBindingsRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PolicyBindingsRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/base.py index 5a9929c737b7..f28baab156da 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc.py index 6ac8496408a0..0a5cb039af84 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc_asyncio.py index 14a25d0e153e..5598743b10ed 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/rest.py index 9137b276e850..464d3948d20f 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/policy_bindings/transports/rest.py @@ -526,6 +526,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PolicyBindingsRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/async_client.py index bd088f89081d..83794c2bbec5 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/async_client.py @@ -227,7 +227,7 @@ def transport(self) -> PrincipalAccessBoundaryPoliciesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1226,7 +1226,7 @@ async def sample_search_principal_access_boundary_policy_bindings(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1252,8 +1252,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1262,7 +1266,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1270,7 +1274,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/client.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/client.py index d3c977b7502d..08d34d9da505 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/client.py @@ -131,7 +131,7 @@ class PrincipalAccessBoundaryPoliciesClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -482,7 +486,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -581,7 +585,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -685,7 +689,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1684,7 +1688,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1710,8 +1714,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1720,7 +1728,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1729,7 +1737,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/README.rst b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/README.rst index df9408ef0e5b..99e616390f45 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/README.rst +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`PrincipalAccessBoundaryPoliciesTransport` is the ABC for all transports. -- public child `PrincipalAccessBoundaryPoliciesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `PrincipalAccessBoundaryPoliciesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BasePrincipalAccessBoundaryPoliciesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `PrincipalAccessBoundaryPoliciesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``PrincipalAccessBoundaryPoliciesTransport`` is the ABC for all transports. + +- public child ``PrincipalAccessBoundaryPoliciesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``PrincipalAccessBoundaryPoliciesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BasePrincipalAccessBoundaryPoliciesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``PrincipalAccessBoundaryPoliciesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/base.py index 1859d733de0b..66a82bcb3dff 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc.py index 4989312dcd8b..66769bc1b90d 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc.py @@ -59,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc_asyncio.py index 7c79fde33a98..7f3cc22b2230 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -100,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/rest.py index a3bb2a317ce4..26fe003561c7 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_v3beta/services/principal_access_boundary_policies/transports/rest.py @@ -532,6 +532,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[PrincipalAccessBoundaryPoliciesRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 9e920fced555..3a2c8c38a990 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-iam/setup.py b/packages/google-cloud-iam/setup.py index f2b7b72b0386..7ca098b742c7 100644 --- a/packages/google-cloud-iam/setup.py +++ b/packages/google-cloud-iam/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -48,7 +48,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-iam" @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-iam/testing/constraints-3.7.txt b/packages/google-cloud-iam/testing/constraints-3.7.txt deleted file mode 100644 index 2bcfa952021b..000000000000 --- a/packages/google-cloud-iam/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -grpc-google-iam-v1==0.12.4 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-iam/testing/constraints-3.8.txt b/packages/google-cloud-iam/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-iam/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-iam/testing/constraints-3.9.txt b/packages/google-cloud-iam/testing/constraints-3.9.txt index 7599dea499ed..36c91811afe8 100644 --- a/packages/google-cloud-iam/testing/constraints-3.9.txt +++ b/packages/google-cloud-iam/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +grpc-google-iam-v1==0.12.4 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_admin_v1/test_iam.py b/packages/google-cloud-iam/tests/unit/gapic/iam_admin_v1/test_iam.py index a09b6473ff9d..2d41d3a58b64 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_admin_v1/test_iam.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_admin_v1/test_iam.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IAMClient._get_default_mtls_endpoint(None) is None assert IAMClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -134,6 +135,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert IAMClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IAMClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1169,11 +1171,13 @@ def test_iam_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -13018,11 +13022,14 @@ def test_iam_base_transport(): def test_iam_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_admin_v1.services.iam.transports.IAMTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_admin_v1.services.iam.transports.IAMTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IAMTransport( @@ -13039,9 +13046,12 @@ def test_iam_base_transport_with_credentials_file(): def test_iam_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_admin_v1.services.iam.transports.IAMTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_admin_v1.services.iam.transports.IAMTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IAMTransport() @@ -13112,11 +13122,12 @@ def test_iam_transport_auth_gdch_credentials(transport_class): def test_iam_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py b/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py index 3042348b1b97..985ececf0674 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IAMCredentialsClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( IAMCredentialsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + IAMCredentialsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1281,11 +1286,13 @@ def test_iam_credentials_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3869,8 +3876,9 @@ def test_generate_access_token_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3933,18 +3941,20 @@ def test_generate_access_token_rest_interceptors(null_interceptor): ) client = IAMCredentialsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_generate_access_token" - ) as post, mock.patch.object( - transports.IAMCredentialsRestInterceptor, - "post_generate_access_token_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "pre_generate_access_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "post_generate_access_token" + ) as post, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, + "post_generate_access_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "pre_generate_access_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3997,8 +4007,9 @@ def test_generate_id_token_rest_bad_request(request_type=common.GenerateIdTokenR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4061,17 +4072,20 @@ def test_generate_id_token_rest_interceptors(null_interceptor): ) client = IAMCredentialsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_generate_id_token" - ) as post, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_generate_id_token_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "pre_generate_id_token" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "post_generate_id_token" + ) as post, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, + "post_generate_id_token_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "pre_generate_id_token" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4122,8 +4136,9 @@ def test_sign_blob_rest_bad_request(request_type=common.SignBlobRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4188,17 +4203,19 @@ def test_sign_blob_rest_interceptors(null_interceptor): ) client = IAMCredentialsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_sign_blob" - ) as post, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_sign_blob_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "pre_sign_blob" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "post_sign_blob" + ) as post, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "post_sign_blob_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "pre_sign_blob" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4247,8 +4264,9 @@ def test_sign_jwt_rest_bad_request(request_type=common.SignJwtRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4313,17 +4331,19 @@ def test_sign_jwt_rest_interceptors(null_interceptor): ) client = IAMCredentialsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_sign_jwt" - ) as post, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "post_sign_jwt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IAMCredentialsRestInterceptor, "pre_sign_jwt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "post_sign_jwt" + ) as post, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "post_sign_jwt_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.IAMCredentialsRestInterceptor, "pre_sign_jwt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4510,11 +4530,14 @@ def test_iam_credentials_base_transport(): def test_iam_credentials_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_credentials_v1.services.iam_credentials.transports.IAMCredentialsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_credentials_v1.services.iam_credentials.transports.IAMCredentialsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IAMCredentialsTransport( @@ -4531,9 +4554,12 @@ def test_iam_credentials_base_transport_with_credentials_file(): def test_iam_credentials_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_credentials_v1.services.iam_credentials.transports.IAMCredentialsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_credentials_v1.services.iam_credentials.transports.IAMCredentialsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IAMCredentialsTransport() @@ -4605,11 +4631,12 @@ def test_iam_credentials_transport_auth_gdch_credentials(transport_class): def test_iam_credentials_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py index 398fc41f6eb0..62c2e32dce08 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PoliciesClient._get_default_mtls_endpoint(None) is None assert PoliciesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -143,6 +144,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert PoliciesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1232,11 +1234,13 @@ def test_policies_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4310,8 +4314,9 @@ def test_list_policies_rest_bad_request(request_type=policy.ListPoliciesRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4372,17 +4377,19 @@ def test_list_policies_rest_interceptors(null_interceptor): ) client = PoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PoliciesRestInterceptor, "post_list_policies" - ) as post, mock.patch.object( - transports.PoliciesRestInterceptor, "post_list_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PoliciesRestInterceptor, "pre_list_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_list_policies" + ) as post, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_list_policies_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PoliciesRestInterceptor, "pre_list_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4433,8 +4440,9 @@ def test_get_policy_rest_bad_request(request_type=policy.GetPolicyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4505,17 +4513,17 @@ def test_get_policy_rest_interceptors(null_interceptor): ) client = PoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PoliciesRestInterceptor, "post_get_policy" - ) as post, mock.patch.object( - transports.PoliciesRestInterceptor, "post_get_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PoliciesRestInterceptor, "pre_get_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_get_policy" + ) as post, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_get_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.PoliciesRestInterceptor, "pre_get_policy") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4564,8 +4572,9 @@ def test_create_policy_rest_bad_request(request_type=gi_policy.CreatePolicyReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4728,19 +4737,20 @@ def test_create_policy_rest_interceptors(null_interceptor): ) client = PoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PoliciesRestInterceptor, "post_create_policy" - ) as post, mock.patch.object( - transports.PoliciesRestInterceptor, "post_create_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PoliciesRestInterceptor, "pre_create_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PoliciesRestInterceptor, "post_create_policy" + ) as post, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_create_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PoliciesRestInterceptor, "pre_create_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4789,8 +4799,9 @@ def test_update_policy_rest_bad_request(request_type=policy.UpdatePolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4953,19 +4964,20 @@ def test_update_policy_rest_interceptors(null_interceptor): ) client = PoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PoliciesRestInterceptor, "post_update_policy" - ) as post, mock.patch.object( - transports.PoliciesRestInterceptor, "post_update_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PoliciesRestInterceptor, "pre_update_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PoliciesRestInterceptor, "post_update_policy" + ) as post, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_update_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PoliciesRestInterceptor, "pre_update_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5014,8 +5026,9 @@ def test_delete_policy_rest_bad_request(request_type=policy.DeletePolicyRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5070,19 +5083,20 @@ def test_delete_policy_rest_interceptors(null_interceptor): ) client = PoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PoliciesRestInterceptor, "post_delete_policy" - ) as post, mock.patch.object( - transports.PoliciesRestInterceptor, "post_delete_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.PoliciesRestInterceptor, "pre_delete_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PoliciesRestInterceptor, "post_delete_policy" + ) as post, + mock.patch.object( + transports.PoliciesRestInterceptor, "post_delete_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.PoliciesRestInterceptor, "pre_delete_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5135,8 +5149,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -5371,11 +5386,14 @@ def test_policies_base_transport(): def test_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_v2.services.policies.transports.PoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_v2.services.policies.transports.PoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PoliciesTransport( @@ -5392,9 +5410,12 @@ def test_policies_base_transport_with_credentials_file(): def test_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_v2.services.policies.transports.PoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_v2.services.policies.transports.PoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PoliciesTransport() @@ -5466,11 +5487,12 @@ def test_policies_transport_auth_gdch_credentials(transport_class): def test_policies_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6046,6 +6068,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PoliciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PoliciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PoliciesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py index 7c6ea74be941..f948fe8eb33c 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PoliciesClient._get_default_mtls_endpoint(None) is None assert PoliciesClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -140,6 +141,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert PoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert PoliciesClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1212,11 +1214,13 @@ def test_policies_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3429,11 +3433,14 @@ def test_policies_base_transport(): def test_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_v2beta.services.policies.transports.PoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_v2beta.services.policies.transports.PoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PoliciesTransport( @@ -3450,9 +3457,12 @@ def test_policies_base_transport_with_credentials_file(): def test_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_v2beta.services.policies.transports.PoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_v2beta.services.policies.transports.PoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PoliciesTransport() @@ -3523,11 +3533,12 @@ def test_policies_transport_auth_gdch_credentials(transport_class): def test_policies_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4048,6 +4059,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PoliciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PoliciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PoliciesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_policy_bindings.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_policy_bindings.py index 6f8db27fdff0..1f103d0e477f 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_policy_bindings.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_policy_bindings.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PolicyBindingsClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): assert ( PolicyBindingsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PolicyBindingsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1294,11 +1299,13 @@ def test_policy_bindings_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5696,8 +5703,9 @@ def test_create_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5842,20 +5850,21 @@ def test_create_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_create_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_create_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_create_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_create_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_create_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_create_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5908,8 +5917,9 @@ def test_get_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5987,18 +5997,20 @@ def test_get_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_get_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_get_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_get_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_get_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_get_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_get_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6060,8 +6072,9 @@ def test_update_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6210,20 +6223,21 @@ def test_update_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_update_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_update_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_update_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_update_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_update_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_update_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6276,8 +6290,9 @@ def test_delete_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6334,20 +6349,21 @@ def test_delete_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_delete_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_delete_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_delete_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_delete_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_delete_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_delete_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6400,8 +6416,9 @@ def test_list_policy_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6466,18 +6483,20 @@ def test_list_policy_bindings_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_list_policy_bindings" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_list_policy_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_list_policy_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_list_policy_bindings" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_list_policy_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_list_policy_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6535,8 +6554,9 @@ def test_search_target_policy_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6601,18 +6621,22 @@ def test_search_target_policy_bindings_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_search_target_policy_bindings" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_search_target_policy_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_search_target_policy_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_search_target_policy_bindings", + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_search_target_policy_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "pre_search_target_policy_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6674,8 +6698,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6943,11 +6968,14 @@ def test_policy_bindings_base_transport(): def test_policy_bindings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_v3.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_v3.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyBindingsTransport( @@ -6964,9 +6992,12 @@ def test_policy_bindings_base_transport_with_credentials_file(): def test_policy_bindings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_v3.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_v3.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyBindingsTransport() @@ -7038,11 +7069,12 @@ def test_policy_bindings_transport_auth_gdch_credentials(transport_class): def test_policy_bindings_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7660,6 +7692,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PolicyBindingsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PolicyBindingsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PolicyBindingsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_principal_access_boundary_policies.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_principal_access_boundary_policies.py index 246ffa958d6c..d319bf5837ac 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_principal_access_boundary_policies.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v3/test_principal_access_boundary_policies.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( PrincipalAccessBoundaryPoliciesClient._get_default_mtls_endpoint(None) is None @@ -163,6 +164,12 @@ def test__get_default_mtls_endpoint(): PrincipalAccessBoundaryPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PrincipalAccessBoundaryPoliciesClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1426,11 +1433,13 @@ def test_principal_access_boundary_policies_client_create_channel_credentials_fi ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5962,8 +5971,9 @@ def test_create_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6114,22 +6124,23 @@ def test_create_principal_access_boundary_policy_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_create_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_create_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_create_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_create_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_create_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_create_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6184,8 +6195,9 @@ def test_get_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6265,20 +6277,22 @@ def test_get_principal_access_boundary_policy_rest_interceptors(null_interceptor ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_get_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_get_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_get_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_get_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_get_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_get_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6342,8 +6356,9 @@ def test_update_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6498,22 +6513,23 @@ def test_update_principal_access_boundary_policy_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_update_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_update_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_update_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_update_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_update_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_update_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6568,8 +6584,9 @@ def test_delete_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6628,22 +6645,23 @@ def test_delete_principal_access_boundary_policy_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_delete_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_delete_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_delete_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_delete_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_delete_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_delete_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6696,8 +6714,9 @@ def test_list_principal_access_boundary_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6762,20 +6781,22 @@ def test_list_principal_access_boundary_policies_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_list_principal_access_boundary_policies", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_list_principal_access_boundary_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_list_principal_access_boundary_policies", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_list_principal_access_boundary_policies", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_list_principal_access_boundary_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_list_principal_access_boundary_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6835,8 +6856,9 @@ def test_search_principal_access_boundary_policy_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6907,20 +6929,22 @@ def test_search_principal_access_boundary_policy_bindings_rest_interceptors( ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_search_principal_access_boundary_policy_bindings", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_search_principal_access_boundary_policy_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_search_principal_access_boundary_policy_bindings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_search_principal_access_boundary_policy_bindings", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_search_principal_access_boundary_policy_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_search_principal_access_boundary_policy_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6980,8 +7004,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7250,11 +7275,14 @@ def test_principal_access_boundary_policies_base_transport(): def test_principal_access_boundary_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_v3.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_v3.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrincipalAccessBoundaryPoliciesTransport( @@ -7271,9 +7299,12 @@ def test_principal_access_boundary_policies_base_transport_with_credentials_file def test_principal_access_boundary_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_v3.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_v3.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrincipalAccessBoundaryPoliciesTransport() @@ -7352,11 +7383,12 @@ def test_principal_access_boundary_policies_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8026,6 +8058,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PrincipalAccessBoundaryPoliciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PrincipalAccessBoundaryPoliciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PrincipalAccessBoundaryPoliciesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_policy_bindings.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_policy_bindings.py index 6c53a689eff2..cf0ddea97119 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_policy_bindings.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_policy_bindings.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert PolicyBindingsClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): assert ( PolicyBindingsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PolicyBindingsClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1294,11 +1299,13 @@ def test_policy_bindings_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5696,8 +5703,9 @@ def test_create_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5842,20 +5850,21 @@ def test_create_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_create_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_create_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_create_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_create_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_create_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_create_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5908,8 +5917,9 @@ def test_get_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5987,18 +5997,20 @@ def test_get_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_get_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_get_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_get_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_get_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_get_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_get_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6060,8 +6072,9 @@ def test_update_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6210,20 +6223,21 @@ def test_update_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_update_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_update_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_update_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_update_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_update_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_update_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6276,8 +6290,9 @@ def test_delete_policy_binding_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6334,20 +6349,21 @@ def test_delete_policy_binding_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_delete_policy_binding" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_delete_policy_binding_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_delete_policy_binding" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_delete_policy_binding" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_delete_policy_binding_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_delete_policy_binding" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6400,8 +6416,9 @@ def test_list_policy_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6466,18 +6483,20 @@ def test_list_policy_bindings_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_list_policy_bindings" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_list_policy_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_list_policy_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "post_list_policy_bindings" + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_list_policy_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, "pre_list_policy_bindings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6535,8 +6554,9 @@ def test_search_target_policy_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6601,18 +6621,22 @@ def test_search_target_policy_bindings_rest_interceptors(null_interceptor): ) client = PolicyBindingsClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "post_search_target_policy_bindings" - ) as post, mock.patch.object( - transports.PolicyBindingsRestInterceptor, - "post_search_target_policy_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PolicyBindingsRestInterceptor, "pre_search_target_policy_bindings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_search_target_policy_bindings", + ) as post, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "post_search_target_policy_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PolicyBindingsRestInterceptor, + "pre_search_target_policy_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6674,8 +6698,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6943,11 +6968,14 @@ def test_policy_bindings_base_transport(): def test_policy_bindings_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_v3beta.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_v3beta.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyBindingsTransport( @@ -6964,9 +6992,12 @@ def test_policy_bindings_base_transport_with_credentials_file(): def test_policy_bindings_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_v3beta.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_v3beta.services.policy_bindings.transports.PolicyBindingsTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PolicyBindingsTransport() @@ -7038,11 +7069,12 @@ def test_policy_bindings_transport_auth_gdch_credentials(transport_class): def test_policy_bindings_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7660,6 +7692,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PolicyBindingsClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PolicyBindingsAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PolicyBindingsClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_principal_access_boundary_policies.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_principal_access_boundary_policies.py index 3e6c75d8cfc5..5e2743804d56 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_principal_access_boundary_policies.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v3beta/test_principal_access_boundary_policies.py @@ -133,6 +133,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ( PrincipalAccessBoundaryPoliciesClient._get_default_mtls_endpoint(None) is None @@ -163,6 +164,12 @@ def test__get_default_mtls_endpoint(): PrincipalAccessBoundaryPoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + PrincipalAccessBoundaryPoliciesClient._get_default_mtls_endpoint( + custom_endpoint + ) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1426,11 +1433,13 @@ def test_principal_access_boundary_policies_client_create_channel_credentials_fi ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5962,8 +5971,9 @@ def test_create_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6114,22 +6124,23 @@ def test_create_principal_access_boundary_policy_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_create_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_create_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_create_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_create_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_create_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_create_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6184,8 +6195,9 @@ def test_get_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6265,20 +6277,22 @@ def test_get_principal_access_boundary_policy_rest_interceptors(null_interceptor ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_get_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_get_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_get_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_get_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_get_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_get_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6342,8 +6356,9 @@ def test_update_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6498,22 +6513,23 @@ def test_update_principal_access_boundary_policy_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_update_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_update_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_update_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_update_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_update_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_update_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6568,8 +6584,9 @@ def test_delete_principal_access_boundary_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6628,22 +6645,23 @@ def test_delete_principal_access_boundary_policy_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_delete_principal_access_boundary_policy", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_delete_principal_access_boundary_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_delete_principal_access_boundary_policy", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_delete_principal_access_boundary_policy", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_delete_principal_access_boundary_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_delete_principal_access_boundary_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6696,8 +6714,9 @@ def test_list_principal_access_boundary_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6762,20 +6781,22 @@ def test_list_principal_access_boundary_policies_rest_interceptors(null_intercep ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_list_principal_access_boundary_policies", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_list_principal_access_boundary_policies_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_list_principal_access_boundary_policies", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_list_principal_access_boundary_policies", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_list_principal_access_boundary_policies_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_list_principal_access_boundary_policies", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6835,8 +6856,9 @@ def test_search_principal_access_boundary_policy_bindings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6907,20 +6929,22 @@ def test_search_principal_access_boundary_policy_bindings_rest_interceptors( ) client = PrincipalAccessBoundaryPoliciesClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_search_principal_access_boundary_policy_bindings", - ) as post, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "post_search_principal_access_boundary_policy_bindings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.PrincipalAccessBoundaryPoliciesRestInterceptor, - "pre_search_principal_access_boundary_policy_bindings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_search_principal_access_boundary_policy_bindings", + ) as post, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "post_search_principal_access_boundary_policy_bindings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.PrincipalAccessBoundaryPoliciesRestInterceptor, + "pre_search_principal_access_boundary_policy_bindings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6980,8 +7004,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7250,11 +7275,14 @@ def test_principal_access_boundary_policies_base_transport(): def test_principal_access_boundary_policies_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iam_v3beta.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iam_v3beta.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrincipalAccessBoundaryPoliciesTransport( @@ -7271,9 +7299,12 @@ def test_principal_access_boundary_policies_base_transport_with_credentials_file def test_principal_access_boundary_policies_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iam_v3beta.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iam_v3beta.services.principal_access_boundary_policies.transports.PrincipalAccessBoundaryPoliciesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PrincipalAccessBoundaryPoliciesTransport() @@ -7352,11 +7383,12 @@ def test_principal_access_boundary_policies_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8026,6 +8058,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = PrincipalAccessBoundaryPoliciesClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = PrincipalAccessBoundaryPoliciesAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_transport_close_grpc(): client = PrincipalAccessBoundaryPoliciesClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/async_client.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/async_client.py index 368dd97653cf..5e4b28c04297 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/async_client.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> IdentityAwareProxyAdminServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py index ab2e92b8e836..00b38534bc97 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/client.py @@ -120,7 +120,7 @@ class IdentityAwareProxyAdminServiceClient( """APIs for Identity-Aware Proxy Admin configurations.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -128,7 +128,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -138,6 +138,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -468,7 +472,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -567,7 +571,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -671,7 +675,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/README.rst b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/README.rst index a25e3225af0b..f33c523e3192 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/README.rst +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IdentityAwareProxyAdminServiceTransport` is the ABC for all transports. -- public child `IdentityAwareProxyAdminServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IdentityAwareProxyAdminServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIdentityAwareProxyAdminServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IdentityAwareProxyAdminServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IdentityAwareProxyAdminServiceTransport`` is the ABC for all transports. + +- public child ``IdentityAwareProxyAdminServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IdentityAwareProxyAdminServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIdentityAwareProxyAdminServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IdentityAwareProxyAdminServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/base.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/base.py index 8e00a0db708b..1408af5a8e7c 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/base.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc.py index b3c9d4c0e2ec..6b3761d8c2bb 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc_asyncio.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc_asyncio.py index 844c72bd568a..c1f853a33495 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/rest.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/rest.py index 2b911fe856d0..e7e6dec34673 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/rest.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_admin_service/transports/rest.py @@ -732,6 +732,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IdentityAwareProxyAdminServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/async_client.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/async_client.py index 9af5b94cdfc3..cb275605a565 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/async_client.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> IdentityAwareProxyOAuthServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py index 72f267d7da1d..0038dfb66381 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/client.py @@ -119,7 +119,7 @@ class IdentityAwareProxyOAuthServiceClient( """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -426,7 +430,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -525,7 +529,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -629,7 +633,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/README.rst b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/README.rst index 007f3e6d771a..a8268ff62761 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/README.rst +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IdentityAwareProxyOAuthServiceTransport` is the ABC for all transports. -- public child `IdentityAwareProxyOAuthServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IdentityAwareProxyOAuthServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIdentityAwareProxyOAuthServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IdentityAwareProxyOAuthServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IdentityAwareProxyOAuthServiceTransport`` is the ABC for all transports. + +- public child ``IdentityAwareProxyOAuthServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IdentityAwareProxyOAuthServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIdentityAwareProxyOAuthServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IdentityAwareProxyOAuthServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/base.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/base.py index eee9a40f6d8b..f1443d7933d4 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/base.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc.py index 59388695ac51..f43a02ee884a 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc_asyncio.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc_asyncio.py index e39dfe41ca15..937895165616 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/rest.py b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/rest.py index ee92c9e8a726..71f028f9cb62 100644 --- a/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/rest.py +++ b/packages/google-cloud-iap/google/cloud/iap_v1/services/identity_aware_proxy_o_auth_service/transports/rest.py @@ -560,6 +560,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IdentityAwareProxyOAuthServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-iap/noxfile.py b/packages/google-cloud-iap/noxfile.py index c31df1416759..b05a0a277285 100644 --- a/packages/google-cloud-iap/noxfile.py +++ b/packages/google-cloud-iap/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-iap/setup.py b/packages/google-cloud-iap/setup.py index 0ebb89491c26..4b1402488e4b 100644 --- a/packages/google-cloud-iap/setup.py +++ b/packages/google-cloud-iap/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-iap/testing/constraints-3.7.txt b/packages/google-cloud-iap/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-iap/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-iap/testing/constraints-3.8.txt b/packages/google-cloud-iap/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-iap/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-iap/testing/constraints-3.9.txt b/packages/google-cloud-iap/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-iap/testing/constraints-3.9.txt +++ b/packages/google-cloud-iap/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py b/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py index 17f4dfa39c92..8e3e291a3ab8 100644 --- a/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py +++ b/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_admin_service.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IdentityAwareProxyAdminServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -154,6 +155,10 @@ def test__get_default_mtls_endpoint(): IdentityAwareProxyAdminServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + IdentityAwareProxyAdminServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1412,11 +1417,13 @@ def test_identity_aware_proxy_admin_service_client_create_channel_credentials_fi ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7435,8 +7442,9 @@ def test_set_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7498,18 +7506,22 @@ def test_set_iam_policy_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, "post_set_iam_policy" - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_set_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, "pre_set_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_set_iam_policy", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_set_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_set_iam_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7560,8 +7572,9 @@ def test_get_iam_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7623,18 +7636,22 @@ def test_get_iam_policy_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, "post_get_iam_policy" - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_get_iam_policy_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, "pre_get_iam_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_get_iam_policy", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_get_iam_policy_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_get_iam_policy", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7685,8 +7702,9 @@ def test_test_iam_permissions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7746,20 +7764,22 @@ def test_test_iam_permissions_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_test_iam_permissions", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_test_iam_permissions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_test_iam_permissions", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_test_iam_permissions", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_test_iam_permissions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_test_iam_permissions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7813,8 +7833,9 @@ def test_get_iap_settings_rest_bad_request(request_type=service.GetIapSettingsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7877,19 +7898,22 @@ def test_get_iap_settings_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_get_iap_settings", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_get_iap_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, "pre_get_iap_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_get_iap_settings", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_get_iap_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_get_iap_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7940,8 +7964,9 @@ def test_update_iap_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8120,20 +8145,22 @@ def test_update_iap_settings_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_update_iap_settings", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_update_iap_settings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_update_iap_settings", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_update_iap_settings", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_update_iap_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_update_iap_settings", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8186,8 +8213,9 @@ def test_validate_iap_attribute_expression_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8247,20 +8275,22 @@ def test_validate_iap_attribute_expression_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_validate_iap_attribute_expression", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_validate_iap_attribute_expression_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_validate_iap_attribute_expression", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_validate_iap_attribute_expression", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_validate_iap_attribute_expression_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_validate_iap_attribute_expression", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8318,8 +8348,9 @@ def test_list_tunnel_dest_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8382,20 +8413,22 @@ def test_list_tunnel_dest_groups_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_list_tunnel_dest_groups", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_list_tunnel_dest_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_list_tunnel_dest_groups", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_list_tunnel_dest_groups", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_list_tunnel_dest_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_list_tunnel_dest_groups", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8453,8 +8486,9 @@ def test_create_tunnel_dest_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8593,20 +8627,22 @@ def test_create_tunnel_dest_group_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_create_tunnel_dest_group", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_create_tunnel_dest_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_create_tunnel_dest_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_create_tunnel_dest_group", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_create_tunnel_dest_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_create_tunnel_dest_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8661,8 +8697,9 @@ def test_get_tunnel_dest_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8731,20 +8768,22 @@ def test_get_tunnel_dest_group_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_get_tunnel_dest_group", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_get_tunnel_dest_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_get_tunnel_dest_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_get_tunnel_dest_group", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_get_tunnel_dest_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_get_tunnel_dest_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8799,8 +8838,9 @@ def test_delete_tunnel_dest_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8859,14 +8899,14 @@ def test_delete_tunnel_dest_group_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_delete_tunnel_dest_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_delete_tunnel_dest_group", + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteTunnelDestGroupRequest.pb( service.DeleteTunnelDestGroupRequest() @@ -8915,8 +8955,9 @@ def test_update_tunnel_dest_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -9059,20 +9100,22 @@ def test_update_tunnel_dest_group_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyAdminServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_update_tunnel_dest_group", - ) as post, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "post_update_tunnel_dest_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyAdminServiceRestInterceptor, - "pre_update_tunnel_dest_group", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_update_tunnel_dest_group", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "post_update_tunnel_dest_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyAdminServiceRestInterceptor, + "pre_update_tunnel_dest_group", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -9420,11 +9463,14 @@ def test_identity_aware_proxy_admin_service_base_transport(): def test_identity_aware_proxy_admin_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iap_v1.services.identity_aware_proxy_admin_service.transports.IdentityAwareProxyAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iap_v1.services.identity_aware_proxy_admin_service.transports.IdentityAwareProxyAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IdentityAwareProxyAdminServiceTransport( @@ -9441,9 +9487,12 @@ def test_identity_aware_proxy_admin_service_base_transport_with_credentials_file def test_identity_aware_proxy_admin_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iap_v1.services.identity_aware_proxy_admin_service.transports.IdentityAwareProxyAdminServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iap_v1.services.identity_aware_proxy_admin_service.transports.IdentityAwareProxyAdminServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IdentityAwareProxyAdminServiceTransport() @@ -9522,11 +9571,12 @@ def test_identity_aware_proxy_admin_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py b/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py index b4c5d79575dd..47252b3e058a 100644 --- a/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py +++ b/packages/google-cloud-iap/tests/unit/gapic/iap_v1/test_identity_aware_proxy_o_auth_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IdentityAwareProxyOAuthServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): IdentityAwareProxyOAuthServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + IdentityAwareProxyOAuthServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1405,11 +1410,13 @@ def test_identity_aware_proxy_o_auth_service_client_create_channel_credentials_f ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5312,8 +5319,9 @@ def test_list_brands_rest_bad_request(request_type=service.ListBrandsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5373,18 +5381,20 @@ def test_list_brands_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, "post_list_brands" - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_list_brands_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, "pre_list_brands" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, "post_list_brands" + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_list_brands_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, "pre_list_brands" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5433,8 +5443,9 @@ def test_create_brand_rest_bad_request(request_type=service.CreateBrandRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5576,18 +5587,21 @@ def test_create_brand_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, "post_create_brand" - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_create_brand_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, "pre_create_brand" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_create_brand", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_create_brand_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, "pre_create_brand" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5636,8 +5650,9 @@ def test_get_brand_rest_bad_request(request_type=service.GetBrandRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5706,18 +5721,20 @@ def test_get_brand_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, "post_get_brand" - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_get_brand_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, "pre_get_brand" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, "post_get_brand" + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_get_brand_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, "pre_get_brand" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5768,8 +5785,9 @@ def test_create_identity_aware_proxy_client_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5914,20 +5932,22 @@ def test_create_identity_aware_proxy_client_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_create_identity_aware_proxy_client", - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_create_identity_aware_proxy_client_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "pre_create_identity_aware_proxy_client", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_create_identity_aware_proxy_client", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_create_identity_aware_proxy_client_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "pre_create_identity_aware_proxy_client", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5982,8 +6002,9 @@ def test_list_identity_aware_proxy_clients_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6046,20 +6067,22 @@ def test_list_identity_aware_proxy_clients_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_list_identity_aware_proxy_clients", - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_list_identity_aware_proxy_clients_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "pre_list_identity_aware_proxy_clients", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_list_identity_aware_proxy_clients", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_list_identity_aware_proxy_clients_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "pre_list_identity_aware_proxy_clients", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6119,8 +6142,9 @@ def test_get_identity_aware_proxy_client_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6189,20 +6213,22 @@ def test_get_identity_aware_proxy_client_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_get_identity_aware_proxy_client", - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_get_identity_aware_proxy_client_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "pre_get_identity_aware_proxy_client", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_get_identity_aware_proxy_client", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_get_identity_aware_proxy_client_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "pre_get_identity_aware_proxy_client", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6259,8 +6285,9 @@ def test_reset_identity_aware_proxy_client_secret_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6329,20 +6356,22 @@ def test_reset_identity_aware_proxy_client_secret_rest_interceptors(null_interce ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_reset_identity_aware_proxy_client_secret", - ) as post, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "post_reset_identity_aware_proxy_client_secret_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "pre_reset_identity_aware_proxy_client_secret", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_reset_identity_aware_proxy_client_secret", + ) as post, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "post_reset_identity_aware_proxy_client_secret_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "pre_reset_identity_aware_proxy_client_secret", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6399,8 +6428,9 @@ def test_delete_identity_aware_proxy_client_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6459,14 +6489,14 @@ def test_delete_identity_aware_proxy_client_rest_interceptors(null_interceptor): ) client = IdentityAwareProxyOAuthServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IdentityAwareProxyOAuthServiceRestInterceptor, - "pre_delete_identity_aware_proxy_client", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.IdentityAwareProxyOAuthServiceRestInterceptor, + "pre_delete_identity_aware_proxy_client", + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteIdentityAwareProxyClientRequest.pb( service.DeleteIdentityAwareProxyClientRequest() @@ -6737,11 +6767,14 @@ def test_identity_aware_proxy_o_auth_service_base_transport(): def test_identity_aware_proxy_o_auth_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.iap_v1.services.identity_aware_proxy_o_auth_service.transports.IdentityAwareProxyOAuthServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.iap_v1.services.identity_aware_proxy_o_auth_service.transports.IdentityAwareProxyOAuthServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IdentityAwareProxyOAuthServiceTransport( @@ -6758,9 +6791,12 @@ def test_identity_aware_proxy_o_auth_service_base_transport_with_credentials_fil def test_identity_aware_proxy_o_auth_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.iap_v1.services.identity_aware_proxy_o_auth_service.transports.IdentityAwareProxyOAuthServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.iap_v1.services.identity_aware_proxy_o_auth_service.transports.IdentityAwareProxyOAuthServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IdentityAwareProxyOAuthServiceTransport() @@ -6839,11 +6875,12 @@ def test_identity_aware_proxy_o_auth_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/async_client.py b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/async_client.py index eb6a45ce0b59..5b90ed509e98 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/async_client.py +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/async_client.py @@ -181,7 +181,7 @@ def transport(self) -> IDSTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/client.py b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/client.py index 5e049f0af09c..184eb6fe374b 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/client.py +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/client.py @@ -115,7 +115,7 @@ class IDSClient(metaclass=IDSClientMeta): """The IDS Service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -440,7 +444,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -537,7 +541,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -633,7 +637,7 @@ def __init__( self._universe_domain = IDSClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/README.rst b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/README.rst index a5c0b2e0b7f4..2d55074a80a0 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/README.rst +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`IDSTransport` is the ABC for all transports. -- public child `IDSGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `IDSGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseIDSRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `IDSRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``IDSTransport`` is the ABC for all transports. + +- public child ``IDSGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``IDSGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseIDSRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``IDSRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/base.py b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/base.py index 098d712a5b77..6da8a2de061e 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/base.py +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc.py b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc.py index 4ab8c06401dc..d4b57021eee8 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc.py +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc_asyncio.py b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc_asyncio.py index d245f05b5894..c19aac340f79 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc_asyncio.py +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/rest.py b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/rest.py index 6beb4c6f2585..623647da0b03 100644 --- a/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/rest.py +++ b/packages/google-cloud-ids/google/cloud/ids_v1/services/ids/transports/rest.py @@ -358,6 +358,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[IDSRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-ids/noxfile.py b/packages/google-cloud-ids/noxfile.py index 95e285b5a61a..777c7a164585 100644 --- a/packages/google-cloud-ids/noxfile.py +++ b/packages/google-cloud-ids/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-ids/setup.py b/packages/google-cloud-ids/setup.py index 26b28709d982..44d0a6c2049b 100644 --- a/packages/google-cloud-ids/setup.py +++ b/packages/google-cloud-ids/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-ids" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-ids/testing/constraints-3.7.txt b/packages/google-cloud-ids/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-ids/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-ids/testing/constraints-3.8.txt b/packages/google-cloud-ids/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-ids/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-ids/testing/constraints-3.9.txt b/packages/google-cloud-ids/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-ids/testing/constraints-3.9.txt +++ b/packages/google-cloud-ids/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-ids/tests/unit/gapic/ids_v1/test_ids.py b/packages/google-cloud-ids/tests/unit/gapic/ids_v1/test_ids.py index edf8f84f1c8c..e93e1120ac6e 100644 --- a/packages/google-cloud-ids/tests/unit/gapic/ids_v1/test_ids.py +++ b/packages/google-cloud-ids/tests/unit/gapic/ids_v1/test_ids.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IDSClient._get_default_mtls_endpoint(None) is None assert IDSClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -139,6 +140,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert IDSClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IDSClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1191,11 +1193,13 @@ def test_ids_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3926,8 +3930,9 @@ def test_list_endpoints_rest_bad_request(request_type=ids.ListEndpointsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3990,17 +3995,15 @@ def test_list_endpoints_rest_interceptors(null_interceptor): ) client = IDSClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IDSRestInterceptor, "post_list_endpoints" - ) as post, mock.patch.object( - transports.IDSRestInterceptor, "post_list_endpoints_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IDSRestInterceptor, "pre_list_endpoints" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.IDSRestInterceptor, "post_list_endpoints") as post, + mock.patch.object( + transports.IDSRestInterceptor, "post_list_endpoints_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IDSRestInterceptor, "pre_list_endpoints") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4049,8 +4052,9 @@ def test_get_endpoint_rest_bad_request(request_type=ids.GetEndpointRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4125,17 +4129,15 @@ def test_get_endpoint_rest_interceptors(null_interceptor): ) client = IDSClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.IDSRestInterceptor, "post_get_endpoint" - ) as post, mock.patch.object( - transports.IDSRestInterceptor, "post_get_endpoint_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IDSRestInterceptor, "pre_get_endpoint" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.IDSRestInterceptor, "post_get_endpoint") as post, + mock.patch.object( + transports.IDSRestInterceptor, "post_get_endpoint_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IDSRestInterceptor, "pre_get_endpoint") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4184,8 +4186,9 @@ def test_create_endpoint_rest_bad_request(request_type=ids.CreateEndpointRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4320,19 +4323,18 @@ def test_create_endpoint_rest_interceptors(null_interceptor): ) client = IDSClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IDSRestInterceptor, "post_create_endpoint" - ) as post, mock.patch.object( - transports.IDSRestInterceptor, "post_create_endpoint_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IDSRestInterceptor, "pre_create_endpoint" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IDSRestInterceptor, "post_create_endpoint" + ) as post, + mock.patch.object( + transports.IDSRestInterceptor, "post_create_endpoint_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IDSRestInterceptor, "pre_create_endpoint") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4381,8 +4383,9 @@ def test_delete_endpoint_rest_bad_request(request_type=ids.DeleteEndpointRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4437,19 +4440,18 @@ def test_delete_endpoint_rest_interceptors(null_interceptor): ) client = IDSClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.IDSRestInterceptor, "post_delete_endpoint" - ) as post, mock.patch.object( - transports.IDSRestInterceptor, "post_delete_endpoint_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.IDSRestInterceptor, "pre_delete_endpoint" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.IDSRestInterceptor, "post_delete_endpoint" + ) as post, + mock.patch.object( + transports.IDSRestInterceptor, "post_delete_endpoint_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.IDSRestInterceptor, "pre_delete_endpoint") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4654,11 +4656,14 @@ def test_ids_base_transport(): def test_ids_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.ids_v1.services.ids.transports.IDSTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.ids_v1.services.ids.transports.IDSTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IDSTransport( @@ -4675,9 +4680,12 @@ def test_ids_base_transport_with_credentials_file(): def test_ids_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.ids_v1.services.ids.transports.IDSTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.ids_v1.services.ids.transports.IDSTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IDSTransport() @@ -4749,11 +4757,12 @@ def test_ids_transport_auth_gdch_credentials(transport_class): def test_ids_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/async_client.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/async_client.py index df377724485c..6693a9ca9333 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/async_client.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/async_client.py @@ -199,7 +199,7 @@ def transport(self) -> KeyDashboardServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/client.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/client.py index 5806a8e39835..9d7b907daf0d 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/client.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/client.py @@ -113,7 +113,7 @@ class KeyDashboardServiceClient(metaclass=KeyDashboardServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -466,7 +470,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -563,7 +567,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -663,7 +667,7 @@ def __init__( self._universe_domain = KeyDashboardServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/README.rst b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/README.rst index aa1085b4e222..42332dfbd7db 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/README.rst +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`KeyDashboardServiceTransport` is the ABC for all transports. -- public child `KeyDashboardServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `KeyDashboardServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseKeyDashboardServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `KeyDashboardServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``KeyDashboardServiceTransport`` is the ABC for all transports. + +- public child ``KeyDashboardServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``KeyDashboardServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseKeyDashboardServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``KeyDashboardServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/base.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/base.py index f5479548f6f4..8e08cd51485a 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/base.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc.py index ef33b871ce3d..f132f00c754e 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc_asyncio.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc_asyncio.py index 3d9078c264b1..c236a0d43a79 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/rest.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/rest.py index 82639373a614..c40468fc6776 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/rest.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_dashboard_service/transports/rest.py @@ -206,6 +206,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[KeyDashboardServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/async_client.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/async_client.py index 7204288bd6a2..5f69f06317f5 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/async_client.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> KeyTrackingServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/client.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/client.py index 11a35fd6d2d8..a7d7500c4389 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/client.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/client.py @@ -111,7 +111,7 @@ class KeyTrackingServiceClient(metaclass=KeyTrackingServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -492,7 +496,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -589,7 +593,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -689,7 +693,7 @@ def __init__( self._universe_domain = KeyTrackingServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/README.rst b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/README.rst index 2829b8eb7067..402727d93e0a 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/README.rst +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`KeyTrackingServiceTransport` is the ABC for all transports. -- public child `KeyTrackingServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `KeyTrackingServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseKeyTrackingServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `KeyTrackingServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``KeyTrackingServiceTransport`` is the ABC for all transports. + +- public child ``KeyTrackingServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``KeyTrackingServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseKeyTrackingServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``KeyTrackingServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/base.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/base.py index b523f397c504..c806c688bde6 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/base.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc.py index 100aa54ef9c1..921fb59d0f0b 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc_asyncio.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc_asyncio.py index 9f55f5fcb76d..ea0f2d773e99 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/rest.py b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/rest.py index a1c73191e82f..7dd81c883d13 100644 --- a/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/rest.py +++ b/packages/google-cloud-kms-inventory/google/cloud/kms_inventory_v1/services/key_tracking_service/transports/rest.py @@ -266,6 +266,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[KeyTrackingServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms-inventory/noxfile.py b/packages/google-cloud-kms-inventory/noxfile.py index 9dcccb8f949a..4431b7499617 100644 --- a/packages/google-cloud-kms-inventory/noxfile.py +++ b/packages/google-cloud-kms-inventory/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-kms-inventory/setup.py b/packages/google-cloud-kms-inventory/setup.py index c2a79e5c07f7..c85ba2f1c725 100644 --- a/packages/google-cloud-kms-inventory/setup.py +++ b/packages/google-cloud-kms-inventory/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "google-cloud-kms >= 2.3.0, <4.0.0", ] extras = {} @@ -82,8 +82,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,7 +93,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-kms-inventory/testing/constraints-3.7.txt b/packages/google-cloud-kms-inventory/testing/constraints-3.7.txt deleted file mode 100644 index 5aa0637d9be7..000000000000 --- a/packages/google-cloud-kms-inventory/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -google-cloud-kms==2.3.0 diff --git a/packages/google-cloud-kms-inventory/testing/constraints-3.8.txt b/packages/google-cloud-kms-inventory/testing/constraints-3.8.txt deleted file mode 100644 index b6454e2a81ee..000000000000 --- a/packages/google-cloud-kms-inventory/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-cloud-kms diff --git a/packages/google-cloud-kms-inventory/testing/constraints-3.9.txt b/packages/google-cloud-kms-inventory/testing/constraints-3.9.txt index b6454e2a81ee..814764581d81 100644 --- a/packages/google-cloud-kms-inventory/testing/constraints-3.9.txt +++ b/packages/google-cloud-kms-inventory/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -google-cloud-kms +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +google-cloud-kms==2.3.0 diff --git a/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_dashboard_service.py b/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_dashboard_service.py index 181bff2be9a2..708871b2f360 100644 --- a/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_dashboard_service.py +++ b/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_dashboard_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert KeyDashboardServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): KeyDashboardServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + KeyDashboardServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1341,11 +1346,13 @@ def test_key_dashboard_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2331,8 +2338,9 @@ def test_list_crypto_keys_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2395,18 +2403,20 @@ def test_list_crypto_keys_rest_interceptors(null_interceptor): ) client = KeyDashboardServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyDashboardServiceRestInterceptor, "post_list_crypto_keys" - ) as post, mock.patch.object( - transports.KeyDashboardServiceRestInterceptor, - "post_list_crypto_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyDashboardServiceRestInterceptor, "pre_list_crypto_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyDashboardServiceRestInterceptor, "post_list_crypto_keys" + ) as post, + mock.patch.object( + transports.KeyDashboardServiceRestInterceptor, + "post_list_crypto_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyDashboardServiceRestInterceptor, "pre_list_crypto_keys" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2531,11 +2541,14 @@ def test_key_dashboard_service_base_transport(): def test_key_dashboard_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_inventory_v1.services.key_dashboard_service.transports.KeyDashboardServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_inventory_v1.services.key_dashboard_service.transports.KeyDashboardServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KeyDashboardServiceTransport( @@ -2552,9 +2565,12 @@ def test_key_dashboard_service_base_transport_with_credentials_file(): def test_key_dashboard_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_inventory_v1.services.key_dashboard_service.transports.KeyDashboardServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_inventory_v1.services.key_dashboard_service.transports.KeyDashboardServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KeyDashboardServiceTransport() @@ -2626,11 +2642,12 @@ def test_key_dashboard_service_transport_auth_gdch_credentials(transport_class): def test_key_dashboard_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_tracking_service.py b/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_tracking_service.py index d049b53a4c2b..cfde07fe7c54 100644 --- a/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_tracking_service.py +++ b/packages/google-cloud-kms-inventory/tests/unit/gapic/kms_inventory_v1/test_key_tracking_service.py @@ -119,6 +119,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert KeyTrackingServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): KeyTrackingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + KeyTrackingServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1322,11 +1327,13 @@ def test_key_tracking_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2993,8 +3000,9 @@ def test_get_protected_resources_summary_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3063,20 +3071,22 @@ def test_get_protected_resources_summary_rest_interceptors(null_interceptor): ) client = KeyTrackingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyTrackingServiceRestInterceptor, - "post_get_protected_resources_summary", - ) as post, mock.patch.object( - transports.KeyTrackingServiceRestInterceptor, - "post_get_protected_resources_summary_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyTrackingServiceRestInterceptor, - "pre_get_protected_resources_summary", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyTrackingServiceRestInterceptor, + "post_get_protected_resources_summary", + ) as post, + mock.patch.object( + transports.KeyTrackingServiceRestInterceptor, + "post_get_protected_resources_summary_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyTrackingServiceRestInterceptor, + "pre_get_protected_resources_summary", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3134,8 +3144,9 @@ def test_search_protected_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3200,18 +3211,22 @@ def test_search_protected_resources_rest_interceptors(null_interceptor): ) client = KeyTrackingServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyTrackingServiceRestInterceptor, "post_search_protected_resources" - ) as post, mock.patch.object( - transports.KeyTrackingServiceRestInterceptor, - "post_search_protected_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyTrackingServiceRestInterceptor, "pre_search_protected_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyTrackingServiceRestInterceptor, + "post_search_protected_resources", + ) as post, + mock.patch.object( + transports.KeyTrackingServiceRestInterceptor, + "post_search_protected_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyTrackingServiceRestInterceptor, + "pre_search_protected_resources", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3363,11 +3378,14 @@ def test_key_tracking_service_base_transport(): def test_key_tracking_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_inventory_v1.services.key_tracking_service.transports.KeyTrackingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_inventory_v1.services.key_tracking_service.transports.KeyTrackingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KeyTrackingServiceTransport( @@ -3384,9 +3402,12 @@ def test_key_tracking_service_base_transport_with_credentials_file(): def test_key_tracking_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_inventory_v1.services.key_tracking_service.transports.KeyTrackingServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_inventory_v1.services.key_tracking_service.transports.KeyTrackingServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KeyTrackingServiceTransport() @@ -3458,11 +3479,12 @@ def test_key_tracking_service_transport_auth_gdch_credentials(transport_class): def test_key_tracking_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/async_client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/async_client.py index 59e0011c56ce..cd477e7a19b6 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/async_client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/async_client.py @@ -207,7 +207,7 @@ def transport(self) -> AutokeyTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -720,7 +720,7 @@ async def sample_list_key_handles(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -746,8 +746,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -756,7 +760,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -764,7 +768,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -775,7 +779,7 @@ async def get_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -867,8 +871,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -877,7 +885,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -885,7 +895,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -896,7 +906,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -989,8 +999,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -999,7 +1013,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1007,7 +1023,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1018,7 +1034,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1049,8 +1065,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1061,7 +1081,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1069,7 +1091,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1080,7 +1102,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1106,8 +1128,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1116,7 +1142,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1124,7 +1150,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1135,7 +1161,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1161,8 +1187,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1171,7 +1201,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1179,7 +1209,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py index e25ab1860929..c3dc0f7a6968 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/client.py @@ -137,7 +137,7 @@ class AutokeyClient(metaclass=AutokeyClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -145,7 +145,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -155,6 +155,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -486,7 +490,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -583,7 +587,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -679,7 +683,7 @@ def __init__( self._universe_domain = AutokeyClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1181,7 +1185,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1207,8 +1211,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1217,7 +1225,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1226,7 +1234,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1240,7 +1248,7 @@ def get_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1332,8 +1340,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1342,7 +1354,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1351,7 +1365,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1365,7 +1379,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1458,8 +1472,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1468,7 +1486,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1477,7 +1497,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1491,7 +1511,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1522,8 +1542,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1532,7 +1556,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1541,7 +1567,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1555,7 +1581,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1581,8 +1607,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1591,7 +1621,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1600,7 +1630,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1614,7 +1644,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1640,8 +1670,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1650,7 +1684,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1659,7 +1693,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/README.rst b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/README.rst index e6b77aacde54..eba5526590b2 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/README.rst +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutokeyTransport` is the ABC for all transports. -- public child `AutokeyGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutokeyGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutokeyRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutokeyRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutokeyTransport`` is the ABC for all transports. + +- public child ``AutokeyGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutokeyGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutokeyRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutokeyRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/base.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/base.py index eca91a4262b7..e0a7b2ea25d1 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/base.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc.py index de1d7dcc4825..10a8d66e521f 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -208,6 +208,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc_asyncio.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc_asyncio.py index d3685df1bcd3..bfedcd5a1713 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -259,6 +259,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/rest.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/rest.py index facbd9cbdf4b..169e7ef67e1c 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/rest.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey/transports/rest.py @@ -476,6 +476,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutokeyRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/async_client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/async_client.py index 3034ba9f3155..7ea052e28757 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/async_client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/async_client.py @@ -201,7 +201,7 @@ def transport(self) -> AutokeyAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -675,7 +675,7 @@ async def sample_show_effective_autokey_config(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -701,8 +701,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -711,7 +715,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -719,7 +723,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -730,7 +734,7 @@ async def get_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -822,8 +826,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -832,7 +840,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -840,7 +850,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -851,7 +861,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -944,8 +954,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -954,7 +968,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -962,7 +978,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -973,7 +989,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1004,8 +1020,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1016,7 +1036,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1024,7 +1046,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1035,7 +1057,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1061,8 +1083,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1071,7 +1097,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1079,7 +1105,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1090,7 +1116,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1116,8 +1142,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1126,7 +1156,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1134,7 +1164,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py index 602bfb677a41..4539e31e75e7 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/client.py @@ -127,7 +127,7 @@ class AutokeyAdminClient(metaclass=AutokeyAdminClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -135,7 +135,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -145,6 +145,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -445,7 +449,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -542,7 +546,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -638,7 +642,7 @@ def __init__( self._universe_domain = AutokeyAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1103,7 +1107,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1129,8 +1133,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1139,7 +1147,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1148,7 +1156,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1162,7 +1170,7 @@ def get_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1254,8 +1262,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1264,7 +1276,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1273,7 +1287,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1287,7 +1301,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1380,8 +1394,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1390,7 +1408,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1399,7 +1419,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1413,7 +1433,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1444,8 +1464,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1454,7 +1478,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1463,7 +1489,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1477,7 +1503,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1503,8 +1529,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1513,7 +1543,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1522,7 +1552,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1536,7 +1566,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1562,8 +1592,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1572,7 +1606,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1581,7 +1615,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/README.rst b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/README.rst index e031a9fac606..5bb323de7164 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/README.rst +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AutokeyAdminTransport` is the ABC for all transports. -- public child `AutokeyAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AutokeyAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAutokeyAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AutokeyAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AutokeyAdminTransport`` is the ABC for all transports. + +- public child ``AutokeyAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AutokeyAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAutokeyAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AutokeyAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/base.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/base.py index 3bd926bfb804..1ef701b9c1b8 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/base.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc.py index 25cfeadf037b..7c431490e383 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -200,6 +200,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc_asyncio.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc_asyncio.py index 198d773ef362..4171f91cc747 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -251,6 +251,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/rest.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/rest.py index 7db8b262425d..72db6303cf10 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/rest.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/autokey_admin/transports/rest.py @@ -481,6 +481,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[AutokeyAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/async_client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/async_client.py index 8124a6381d23..d5496add218c 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/async_client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> EkmServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1209,7 +1209,7 @@ async def sample_verify_connectivity(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1235,8 +1235,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1245,7 +1249,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1253,7 +1257,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1264,7 +1268,7 @@ async def get_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1356,8 +1360,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1366,7 +1374,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1374,7 +1384,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1385,7 +1395,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1478,8 +1488,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1488,7 +1502,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1496,7 +1512,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1507,7 +1523,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1538,8 +1554,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1550,7 +1570,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1558,7 +1580,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1569,7 +1591,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1595,8 +1617,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1605,7 +1631,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1613,7 +1639,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1624,7 +1650,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1650,8 +1676,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1660,7 +1690,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1668,7 +1698,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py index b9d3563133d5..c112ea784e15 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/client.py @@ -124,7 +124,7 @@ class EkmServiceClient(metaclass=EkmServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -492,7 +496,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -589,7 +593,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -685,7 +689,7 @@ def __init__( self._universe_domain = EkmServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1673,7 +1677,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1699,8 +1703,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1709,7 +1717,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1718,7 +1726,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1732,7 +1740,7 @@ def get_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1824,8 +1832,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1834,7 +1846,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1843,7 +1857,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1857,7 +1871,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1950,8 +1964,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1960,7 +1978,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1969,7 +1989,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1983,7 +2003,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2014,8 +2034,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2024,7 +2048,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2033,7 +2059,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2047,7 +2073,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2073,8 +2099,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2083,7 +2113,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2092,7 +2122,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2106,7 +2136,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2132,8 +2162,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2142,7 +2176,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2151,7 +2185,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/README.rst b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/README.rst index c0fa99e1eca8..6d82b147ca95 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/README.rst +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`EkmServiceTransport` is the ABC for all transports. -- public child `EkmServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `EkmServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseEkmServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `EkmServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``EkmServiceTransport`` is the ABC for all transports. + +- public child ``EkmServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``EkmServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseEkmServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``EkmServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/base.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/base.py index b5cfc6f258a9..40b442b8e62e 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/base.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc.py index 9b6d010d000f..068687116e70 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +195,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc_asyncio.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc_asyncio.py index 5f57fcdb1443..5cd576c9dc75 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +246,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/rest.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/rest.py index 44fc0a4cfc22..a503e93fd24a 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/rest.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/ekm_service/transports/rest.py @@ -699,6 +699,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[EkmServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/async_client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/async_client.py index 32bae7238a69..91c9251c311f 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/async_client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/async_client.py @@ -214,7 +214,7 @@ def transport(self) -> HsmManagementTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1578,7 +1578,7 @@ async def sample_delete_single_tenant_hsm_instance_proposal(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1604,8 +1604,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1614,7 +1618,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1622,7 +1626,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1633,7 +1637,7 @@ async def get_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1725,8 +1729,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1735,7 +1743,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1743,7 +1753,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1754,7 +1764,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1847,8 +1857,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1857,7 +1871,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1865,7 +1881,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1876,7 +1892,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1907,8 +1923,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1919,7 +1939,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1927,7 +1949,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1938,7 +1960,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1964,8 +1986,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1974,7 +2000,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1982,7 +2008,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1993,7 +2019,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2019,8 +2045,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2029,7 +2059,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2037,7 +2067,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py index 4f4df1b2694d..c7961eced002 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/client.py @@ -128,7 +128,7 @@ class HsmManagementClient(metaclass=HsmManagementClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +136,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +146,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -477,7 +481,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -574,7 +578,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -670,7 +674,7 @@ def __init__( self._universe_domain = HsmManagementClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2026,7 +2030,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2052,8 +2056,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2062,7 +2070,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2071,7 +2079,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2085,7 +2093,7 @@ def get_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2177,8 +2185,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2187,7 +2199,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2196,7 +2210,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2210,7 +2224,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2303,8 +2317,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2313,7 +2331,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2322,7 +2342,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2336,7 +2356,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2367,8 +2387,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2377,7 +2401,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2386,7 +2412,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2400,7 +2426,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2426,8 +2452,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2436,7 +2466,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2445,7 +2475,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2459,7 +2489,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2485,8 +2515,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2495,7 +2529,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2504,7 +2538,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/README.rst b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/README.rst index e999469435d7..0d34900bde30 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/README.rst +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HsmManagementTransport` is the ABC for all transports. -- public child `HsmManagementGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HsmManagementGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHsmManagementRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HsmManagementRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HsmManagementTransport`` is the ABC for all transports. + +- public child ``HsmManagementGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HsmManagementGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHsmManagementRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HsmManagementRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/base.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/base.py index 18e5ee97abb5..19b5e9c3ca22 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/base.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc.py index a5f3a3d90f10..aeeb77a9829e 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -198,6 +198,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc_asyncio.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc_asyncio.py index 4ce8d3b2f0da..2435383eae66 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -249,6 +249,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/rest.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/rest.py index ec800cab6d96..e114bbcf956d 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/rest.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/hsm_management/transports/rest.py @@ -795,6 +795,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[HsmManagementRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/async_client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/async_client.py index df1e553abd51..189615f3a51e 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/async_client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/async_client.py @@ -237,7 +237,7 @@ def transport(self) -> KeyManagementServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4654,7 +4654,7 @@ async def sample_generate_random_bytes(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4680,8 +4680,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4690,7 +4694,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4698,7 +4702,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4709,7 +4713,7 @@ async def get_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4801,8 +4805,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4811,7 +4819,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4819,7 +4829,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4830,7 +4840,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4923,8 +4933,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4933,7 +4947,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4941,7 +4957,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4952,7 +4968,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4983,8 +4999,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4995,7 +5015,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5003,7 +5025,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5014,7 +5036,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5040,8 +5062,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5050,7 +5076,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5058,7 +5084,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5069,7 +5095,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5095,8 +5121,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5105,7 +5135,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5113,7 +5143,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py index 5243d71414f7..e9f14f2d433a 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/client.py @@ -135,7 +135,7 @@ class KeyManagementServiceClient(metaclass=KeyManagementServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -143,7 +143,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -153,6 +153,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -582,7 +586,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -679,7 +683,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -779,7 +783,7 @@ def __init__( self._universe_domain = KeyManagementServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -5119,7 +5123,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5145,8 +5149,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5155,7 +5163,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5164,7 +5172,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5178,7 +5186,7 @@ def get_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5270,8 +5278,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5280,7 +5292,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5289,7 +5303,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5303,7 +5317,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5396,8 +5410,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5406,7 +5424,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5415,7 +5435,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5429,7 +5449,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5460,8 +5480,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5470,7 +5494,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -5479,7 +5505,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5493,7 +5519,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5519,8 +5545,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5529,7 +5559,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5538,7 +5568,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -5552,7 +5582,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -5578,8 +5608,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -5588,7 +5622,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -5597,7 +5631,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/README.rst b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/README.rst index ebe015054ce3..1bce98caa959 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/README.rst +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`KeyManagementServiceTransport` is the ABC for all transports. -- public child `KeyManagementServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `KeyManagementServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseKeyManagementServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `KeyManagementServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``KeyManagementServiceTransport`` is the ABC for all transports. + +- public child ``KeyManagementServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``KeyManagementServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseKeyManagementServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``KeyManagementServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/base.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/base.py index 4a5bed010e91..fab78fed8c1e 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/base.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc.py index 4c9f8e5b8ede..823fdeda62cf 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -201,6 +201,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc_asyncio.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc_asyncio.py index a190302125fd..8f21405a2a5d 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -252,6 +252,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/rest.py b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/rest.py index 09fd7cc4ac61..48273bc886e0 100644 --- a/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/rest.py +++ b/packages/google-cloud-kms/google/cloud/kms_v1/services/key_management_service/transports/rest.py @@ -2116,6 +2116,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[KeyManagementServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-kms/noxfile.py b/packages/google-cloud-kms/noxfile.py index 1c03585ef992..f1c69b7111e6 100644 --- a/packages/google-cloud-kms/noxfile.py +++ b/packages/google-cloud-kms/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-kms/setup.py b/packages/google-cloud-kms/setup.py index 2cad13231dc3..c09dc3ce8c19 100644 --- a/packages/google-cloud-kms/setup.py +++ b/packages/google-cloud-kms/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", "grpc-google-iam-v1 >= 0.14.0, <1.0.0", ] extras = {} @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-kms/testing/constraints-3.7.txt b/packages/google-cloud-kms/testing/constraints-3.7.txt deleted file mode 100644 index 9907cdc23bdb..000000000000 --- a/packages/google-cloud-kms/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 -grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-kms/testing/constraints-3.8.txt b/packages/google-cloud-kms/testing/constraints-3.8.txt deleted file mode 100644 index 1cd0c5a2c3d4..000000000000 --- a/packages/google-cloud-kms/testing/constraints-3.8.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 diff --git a/packages/google-cloud-kms/testing/constraints-3.9.txt b/packages/google-cloud-kms/testing/constraints-3.9.txt index 1cd0c5a2c3d4..dcb9a9b3d8ed 100644 --- a/packages/google-cloud-kms/testing/constraints-3.9.txt +++ b/packages/google-cloud-kms/testing/constraints-3.9.txt @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography -grpc-google-iam-v1 +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 +grpc-google-iam-v1==0.14.0 diff --git a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey.py b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey.py index 317d493930d4..3acd21718792 100644 --- a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey.py +++ b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutokeyClient._get_default_mtls_endpoint(None) is None assert AutokeyClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -145,6 +146,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AutokeyClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AutokeyClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1224,11 +1226,13 @@ def test_autokey_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3381,8 +3385,9 @@ def test_create_key_handle_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3509,19 +3514,20 @@ def test_create_key_handle_rest_interceptors(null_interceptor): ) client = AutokeyClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.AutokeyRestInterceptor, "post_create_key_handle" - ) as post, mock.patch.object( - transports.AutokeyRestInterceptor, "post_create_key_handle_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutokeyRestInterceptor, "pre_create_key_handle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.AutokeyRestInterceptor, "post_create_key_handle" + ) as post, + mock.patch.object( + transports.AutokeyRestInterceptor, "post_create_key_handle_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutokeyRestInterceptor, "pre_create_key_handle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3570,8 +3576,9 @@ def test_get_key_handle_rest_bad_request(request_type=autokey.GetKeyHandleReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3636,17 +3643,19 @@ def test_get_key_handle_rest_interceptors(null_interceptor): ) client = AutokeyClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutokeyRestInterceptor, "post_get_key_handle" - ) as post, mock.patch.object( - transports.AutokeyRestInterceptor, "post_get_key_handle_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutokeyRestInterceptor, "pre_get_key_handle" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutokeyRestInterceptor, "post_get_key_handle" + ) as post, + mock.patch.object( + transports.AutokeyRestInterceptor, "post_get_key_handle_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutokeyRestInterceptor, "pre_get_key_handle" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3695,8 +3704,9 @@ def test_list_key_handles_rest_bad_request(request_type=autokey.ListKeyHandlesRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3757,17 +3767,19 @@ def test_list_key_handles_rest_interceptors(null_interceptor): ) client = AutokeyClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutokeyRestInterceptor, "post_list_key_handles" - ) as post, mock.patch.object( - transports.AutokeyRestInterceptor, "post_list_key_handles_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutokeyRestInterceptor, "pre_list_key_handles" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutokeyRestInterceptor, "post_list_key_handles" + ) as post, + mock.patch.object( + transports.AutokeyRestInterceptor, "post_list_key_handles_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.AutokeyRestInterceptor, "pre_list_key_handles" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3820,8 +3832,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3880,8 +3893,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3942,8 +3956,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4004,8 +4019,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4066,8 +4082,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4128,8 +4145,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4329,11 +4347,14 @@ def test_autokey_base_transport(): def test_autokey_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_v1.services.autokey.transports.AutokeyTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_v1.services.autokey.transports.AutokeyTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutokeyTransport( @@ -4353,9 +4374,12 @@ def test_autokey_base_transport_with_credentials_file(): def test_autokey_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_v1.services.autokey.transports.AutokeyTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_v1.services.autokey.transports.AutokeyTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutokeyTransport() @@ -4433,11 +4457,12 @@ def test_autokey_transport_auth_gdch_credentials(transport_class): def test_autokey_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5067,6 +5092,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AutokeyClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AutokeyAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_locations(transport: str = "grpc"): client = AutokeyClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5212,6 +5271,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AutokeyClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AutokeyAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AutokeyClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5353,6 +5446,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AutokeyClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AutokeyAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AutokeyClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5517,6 +5644,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AutokeyClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AutokeyAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AutokeyClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5684,6 +5846,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AutokeyClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AutokeyAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AutokeyClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5861,6 +6058,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AutokeyClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AutokeyAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AutokeyClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey_admin.py b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey_admin.py index e39370e2370c..3b1de275b728 100644 --- a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey_admin.py +++ b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_autokey_admin.py @@ -126,6 +126,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AutokeyAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert AutokeyAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + AutokeyAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1264,11 +1269,13 @@ def test_autokey_admin_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3230,8 +3237,9 @@ def test_update_autokey_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3379,18 +3387,20 @@ def test_update_autokey_config_rest_interceptors(null_interceptor): ) client = AutokeyAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "post_update_autokey_config" - ) as post, mock.patch.object( - transports.AutokeyAdminRestInterceptor, - "post_update_autokey_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "pre_update_autokey_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, "post_update_autokey_config" + ) as post, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, + "post_update_autokey_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, "pre_update_autokey_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3445,8 +3455,9 @@ def test_get_autokey_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3520,17 +3531,20 @@ def test_get_autokey_config_rest_interceptors(null_interceptor): ) client = AutokeyAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "post_get_autokey_config" - ) as post, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "post_get_autokey_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "pre_get_autokey_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, "post_get_autokey_config" + ) as post, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, + "post_get_autokey_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, "pre_get_autokey_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3585,8 +3599,9 @@ def test_show_effective_autokey_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3649,18 +3664,20 @@ def test_show_effective_autokey_config_rest_interceptors(null_interceptor): ) client = AutokeyAdminClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "post_show_effective_autokey_config" - ) as post, mock.patch.object( - transports.AutokeyAdminRestInterceptor, - "post_show_effective_autokey_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.AutokeyAdminRestInterceptor, "pre_show_effective_autokey_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, "post_show_effective_autokey_config" + ) as post, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, + "post_show_effective_autokey_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.AutokeyAdminRestInterceptor, "pre_show_effective_autokey_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3718,8 +3735,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3778,8 +3796,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3840,8 +3859,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3902,8 +3922,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3964,8 +3985,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4026,8 +4048,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4209,11 +4232,14 @@ def test_autokey_admin_base_transport(): def test_autokey_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_v1.services.autokey_admin.transports.AutokeyAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_v1.services.autokey_admin.transports.AutokeyAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutokeyAdminTransport( @@ -4233,9 +4259,12 @@ def test_autokey_admin_base_transport_with_credentials_file(): def test_autokey_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_v1.services.autokey_admin.transports.AutokeyAdminTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_v1.services.autokey_admin.transports.AutokeyAdminTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AutokeyAdminTransport() @@ -4313,11 +4342,12 @@ def test_autokey_admin_transport_auth_gdch_credentials(transport_class): def test_autokey_admin_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4878,6 +4908,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = AutokeyAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AutokeyAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_locations(transport: str = "grpc"): client = AutokeyAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5023,6 +5087,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = AutokeyAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = AutokeyAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = AutokeyAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5164,6 +5262,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = AutokeyAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = AutokeyAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = AutokeyAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5328,6 +5460,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = AutokeyAdminClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = AutokeyAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = AutokeyAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5495,6 +5662,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = AutokeyAdminClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = AutokeyAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = AutokeyAdminClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5672,6 +5874,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = AutokeyAdminClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = AutokeyAdminAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = AutokeyAdminClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_ekm_service.py b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_ekm_service.py index 6f69b5b7d8af..52d99b32b9c3 100644 --- a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_ekm_service.py +++ b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_ekm_service.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EkmServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert EkmServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + EkmServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1248,11 +1252,13 @@ def test_ekm_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5862,8 +5868,9 @@ def test_list_ekm_connections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5928,17 +5935,20 @@ def test_list_ekm_connections_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_list_ekm_connections" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_list_ekm_connections_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_list_ekm_connections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_list_ekm_connections" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, + "post_list_ekm_connections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_list_ekm_connections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5996,8 +6006,9 @@ def test_get_ekm_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6069,17 +6080,20 @@ def test_get_ekm_connection_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_get_ekm_connection" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_get_ekm_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_get_ekm_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_get_ekm_connection" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, + "post_get_ekm_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_get_ekm_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6132,8 +6146,9 @@ def test_create_ekm_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6302,17 +6317,20 @@ def test_create_ekm_connection_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_create_ekm_connection" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_create_ekm_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_create_ekm_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_create_ekm_connection" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, + "post_create_ekm_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_create_ekm_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6369,8 +6387,9 @@ def test_update_ekm_connection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6543,17 +6562,20 @@ def test_update_ekm_connection_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_update_ekm_connection" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_update_ekm_connection_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_update_ekm_connection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_update_ekm_connection" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, + "post_update_ekm_connection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_update_ekm_connection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6604,8 +6626,9 @@ def test_get_ekm_config_rest_bad_request(request_type=ekm_service.GetEkmConfigRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6670,17 +6693,19 @@ def test_get_ekm_config_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_get_ekm_config" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_get_ekm_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_get_ekm_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_get_ekm_config" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_get_ekm_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_get_ekm_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6735,8 +6760,9 @@ def test_update_ekm_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6874,17 +6900,19 @@ def test_update_ekm_config_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_update_ekm_config" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_update_ekm_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_update_ekm_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_update_ekm_config" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_update_ekm_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_update_ekm_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6937,8 +6965,9 @@ def test_verify_connectivity_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6998,17 +7027,20 @@ def test_verify_connectivity_rest_interceptors(null_interceptor): ) client = EkmServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_verify_connectivity" - ) as post, mock.patch.object( - transports.EkmServiceRestInterceptor, "post_verify_connectivity_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.EkmServiceRestInterceptor, "pre_verify_connectivity" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.EkmServiceRestInterceptor, "post_verify_connectivity" + ) as post, + mock.patch.object( + transports.EkmServiceRestInterceptor, + "post_verify_connectivity_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.EkmServiceRestInterceptor, "pre_verify_connectivity" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7066,8 +7098,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7126,8 +7159,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7188,8 +7222,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7250,8 +7285,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7312,8 +7348,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7374,8 +7411,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7647,11 +7685,14 @@ def test_ekm_service_base_transport(): def test_ekm_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_v1.services.ekm_service.transports.EkmServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_v1.services.ekm_service.transports.EkmServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EkmServiceTransport( @@ -7671,9 +7712,12 @@ def test_ekm_service_base_transport_with_credentials_file(): def test_ekm_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_v1.services.ekm_service.transports.EkmServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_v1.services.ekm_service.transports.EkmServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EkmServiceTransport() @@ -7751,11 +7795,12 @@ def test_ekm_service_transport_auth_gdch_credentials(transport_class): def test_ekm_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8386,6 +8431,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = EkmServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EkmServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_locations(transport: str = "grpc"): client = EkmServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8531,6 +8610,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = EkmServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EkmServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = EkmServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8672,6 +8785,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = EkmServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EkmServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = EkmServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8836,6 +8983,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = EkmServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = EkmServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = EkmServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9003,6 +9185,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = EkmServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = EkmServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = EkmServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9180,6 +9397,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = EkmServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = EkmServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = EkmServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_hsm_management.py b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_hsm_management.py index f8d2489e6ac9..ef3575c4eb1c 100644 --- a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_hsm_management.py +++ b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_hsm_management.py @@ -132,6 +132,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert HsmManagementClient._get_default_mtls_endpoint(None) is None assert ( @@ -153,6 +154,10 @@ def test__get_default_mtls_endpoint(): assert ( HsmManagementClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + HsmManagementClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_hsm_management_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7564,8 +7571,9 @@ def test_list_single_tenant_hsm_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7632,18 +7640,22 @@ def test_list_single_tenant_hsm_instances_rest_interceptors(null_interceptor): ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HsmManagementRestInterceptor, "post_list_single_tenant_hsm_instances" - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_list_single_tenant_hsm_instances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, "pre_list_single_tenant_hsm_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_list_single_tenant_hsm_instances", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_list_single_tenant_hsm_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_list_single_tenant_hsm_instances", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7703,8 +7715,9 @@ def test_get_single_tenant_hsm_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7771,18 +7784,22 @@ def test_get_single_tenant_hsm_instance_rest_interceptors(null_interceptor): ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HsmManagementRestInterceptor, "post_get_single_tenant_hsm_instance" - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_get_single_tenant_hsm_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, "pre_get_single_tenant_hsm_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_get_single_tenant_hsm_instance", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_get_single_tenant_hsm_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_get_single_tenant_hsm_instance", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7840,8 +7857,9 @@ def test_create_single_tenant_hsm_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7987,21 +8005,23 @@ def test_create_single_tenant_hsm_instance_rest_interceptors(null_interceptor): ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_create_single_tenant_hsm_instance", - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_create_single_tenant_hsm_instance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, "pre_create_single_tenant_hsm_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_create_single_tenant_hsm_instance", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_create_single_tenant_hsm_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_create_single_tenant_hsm_instance", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8056,8 +8076,9 @@ def test_create_single_tenant_hsm_instance_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8242,22 +8263,23 @@ def test_create_single_tenant_hsm_instance_proposal_rest_interceptors(null_inter ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_create_single_tenant_hsm_instance_proposal", - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_create_single_tenant_hsm_instance_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, - "pre_create_single_tenant_hsm_instance_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_create_single_tenant_hsm_instance_proposal", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_create_single_tenant_hsm_instance_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_create_single_tenant_hsm_instance_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8312,8 +8334,9 @@ def test_approve_single_tenant_hsm_instance_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8381,20 +8404,22 @@ def test_approve_single_tenant_hsm_instance_proposal_rest_interceptors( ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_approve_single_tenant_hsm_instance_proposal", - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_approve_single_tenant_hsm_instance_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, - "pre_approve_single_tenant_hsm_instance_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_approve_single_tenant_hsm_instance_proposal", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_approve_single_tenant_hsm_instance_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_approve_single_tenant_hsm_instance_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8458,8 +8483,9 @@ def test_execute_single_tenant_hsm_instance_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8520,22 +8546,23 @@ def test_execute_single_tenant_hsm_instance_proposal_rest_interceptors( ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_execute_single_tenant_hsm_instance_proposal", - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_execute_single_tenant_hsm_instance_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, - "pre_execute_single_tenant_hsm_instance_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_execute_single_tenant_hsm_instance_proposal", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_execute_single_tenant_hsm_instance_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_execute_single_tenant_hsm_instance_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8590,8 +8617,9 @@ def test_get_single_tenant_hsm_instance_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8662,20 +8690,22 @@ def test_get_single_tenant_hsm_instance_proposal_rest_interceptors(null_intercep ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_get_single_tenant_hsm_instance_proposal", - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_get_single_tenant_hsm_instance_proposal_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, - "pre_get_single_tenant_hsm_instance_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_get_single_tenant_hsm_instance_proposal", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_get_single_tenant_hsm_instance_proposal_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_get_single_tenant_hsm_instance_proposal", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8735,8 +8765,9 @@ def test_list_single_tenant_hsm_instance_proposals_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8805,20 +8836,22 @@ def test_list_single_tenant_hsm_instance_proposals_rest_interceptors(null_interc ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_list_single_tenant_hsm_instance_proposals", - ) as post, mock.patch.object( - transports.HsmManagementRestInterceptor, - "post_list_single_tenant_hsm_instance_proposals_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.HsmManagementRestInterceptor, - "pre_list_single_tenant_hsm_instance_proposals", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_list_single_tenant_hsm_instance_proposals", + ) as post, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "post_list_single_tenant_hsm_instance_proposals_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_list_single_tenant_hsm_instance_proposals", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8882,8 +8915,9 @@ def test_delete_single_tenant_hsm_instance_proposal_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8942,14 +8976,14 @@ def test_delete_single_tenant_hsm_instance_proposal_rest_interceptors(null_inter ) client = HsmManagementClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.HsmManagementRestInterceptor, - "pre_delete_single_tenant_hsm_instance_proposal", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.HsmManagementRestInterceptor, + "pre_delete_single_tenant_hsm_instance_proposal", + ) as pre, + ): pre.assert_not_called() pb_message = hsm_management.DeleteSingleTenantHsmInstanceProposalRequest.pb( hsm_management.DeleteSingleTenantHsmInstanceProposalRequest() @@ -8994,8 +9028,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9054,8 +9089,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9116,8 +9152,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9178,8 +9215,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9240,8 +9278,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9302,8 +9341,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9645,11 +9685,14 @@ def test_hsm_management_base_transport(): def test_hsm_management_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_v1.services.hsm_management.transports.HsmManagementTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_v1.services.hsm_management.transports.HsmManagementTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HsmManagementTransport( @@ -9669,9 +9712,12 @@ def test_hsm_management_base_transport_with_credentials_file(): def test_hsm_management_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_v1.services.hsm_management.transports.HsmManagementTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_v1.services.hsm_management.transports.HsmManagementTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HsmManagementTransport() @@ -9749,11 +9795,12 @@ def test_hsm_management_transport_auth_gdch_credentials(transport_class): def test_hsm_management_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10414,6 +10461,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = HsmManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = HsmManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_locations(transport: str = "grpc"): client = HsmManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10559,6 +10640,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = HsmManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = HsmManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = HsmManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10700,6 +10815,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = HsmManagementClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = HsmManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = HsmManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10864,6 +11013,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = HsmManagementClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = HsmManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = HsmManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11031,6 +11215,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = HsmManagementClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = HsmManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = HsmManagementClient( credentials=ga_credentials.AnonymousCredentials(), @@ -11208,6 +11427,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = HsmManagementClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = HsmManagementAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = HsmManagementClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_key_management_service.py b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_key_management_service.py index ac98523090bb..f2ef4d93fb46 100644 --- a/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_key_management_service.py +++ b/packages/google-cloud-kms/tests/unit/gapic/kms_v1/test_key_management_service.py @@ -135,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert KeyManagementServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -157,6 +158,10 @@ def test__get_default_mtls_endpoint(): KeyManagementServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + KeyManagementServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1356,11 +1361,13 @@ def test_key_management_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -22038,8 +22045,9 @@ def test_list_key_rings_rest_bad_request(request_type=service.ListKeyRingsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22104,18 +22112,20 @@ def test_list_key_rings_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_list_key_rings" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_list_key_rings_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_list_key_rings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_list_key_rings" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_key_rings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_list_key_rings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22166,8 +22176,9 @@ def test_list_crypto_keys_rest_bad_request(request_type=service.ListCryptoKeysRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22232,18 +22243,20 @@ def test_list_crypto_keys_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_list_crypto_keys" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_list_crypto_keys_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_list_crypto_keys" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_list_crypto_keys" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_crypto_keys_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_list_crypto_keys" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22298,8 +22311,9 @@ def test_list_crypto_key_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22366,18 +22380,22 @@ def test_list_crypto_key_versions_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_list_crypto_key_versions" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_list_crypto_key_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_list_crypto_key_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_crypto_key_versions", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_crypto_key_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_list_crypto_key_versions", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22433,8 +22451,9 @@ def test_list_import_jobs_rest_bad_request(request_type=service.ListImportJobsRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22499,18 +22518,20 @@ def test_list_import_jobs_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_list_import_jobs" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_list_import_jobs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_list_import_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_list_import_jobs" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_import_jobs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_list_import_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22563,8 +22584,9 @@ def test_list_retired_resources_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22629,18 +22651,21 @@ def test_list_retired_resources_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_list_retired_resources" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_list_retired_resources_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_list_retired_resources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_retired_resources", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_list_retired_resources_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_list_retired_resources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22696,8 +22721,9 @@ def test_get_key_ring_rest_bad_request(request_type=service.GetKeyRingRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22760,18 +22786,20 @@ def test_get_key_ring_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_get_key_ring" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_get_key_ring_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_get_key_ring" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_get_key_ring" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_key_ring_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_get_key_ring" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22822,8 +22850,9 @@ def test_get_crypto_key_rest_bad_request(request_type=service.GetCryptoKeyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -22894,18 +22923,20 @@ def test_get_crypto_key_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_get_crypto_key" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_get_crypto_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_get_crypto_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_get_crypto_key" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_crypto_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_get_crypto_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -22958,8 +22989,9 @@ def test_get_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23049,18 +23081,21 @@ def test_get_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_get_crypto_key_version" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_get_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_get_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_get_crypto_key_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23113,8 +23148,9 @@ def test_get_public_key_rest_bad_request(request_type=service.GetPublicKeyReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23190,18 +23226,20 @@ def test_get_public_key_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_get_public_key" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_get_public_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_get_public_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_get_public_key" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_public_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_get_public_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23252,8 +23290,9 @@ def test_get_import_job_rest_bad_request(request_type=service.GetImportJobReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23329,18 +23368,20 @@ def test_get_import_job_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_get_import_job" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_get_import_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_get_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_get_import_job" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_get_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23393,8 +23434,9 @@ def test_get_retired_resource_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23463,18 +23505,20 @@ def test_get_retired_resource_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_get_retired_resource" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_get_retired_resource_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_get_retired_resource" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_get_retired_resource" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_get_retired_resource_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_get_retired_resource" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23525,8 +23569,9 @@ def test_create_key_ring_rest_bad_request(request_type=service.CreateKeyRingRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23660,18 +23705,20 @@ def test_create_key_ring_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_create_key_ring" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_create_key_ring_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_create_key_ring" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_create_key_ring" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_create_key_ring_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_create_key_ring" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23722,8 +23769,9 @@ def test_create_crypto_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -23907,18 +23955,20 @@ def test_create_crypto_key_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_create_crypto_key" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_create_crypto_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_create_crypto_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_create_crypto_key" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_create_crypto_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_create_crypto_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -23971,8 +24021,9 @@ def test_create_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24164,18 +24215,22 @@ def test_create_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_create_crypto_key_version" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_create_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_create_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_create_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_create_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_create_crypto_key_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24230,8 +24285,9 @@ def test_delete_crypto_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24290,20 +24346,21 @@ def test_delete_crypto_key_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_delete_crypto_key" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_delete_crypto_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_delete_crypto_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_delete_crypto_key" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_delete_crypto_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_delete_crypto_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24356,8 +24413,9 @@ def test_delete_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24416,20 +24474,23 @@ def test_delete_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_delete_crypto_key_version" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_delete_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_delete_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_delete_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_delete_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_delete_crypto_key_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24484,8 +24545,9 @@ def test_import_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24575,18 +24637,22 @@ def test_import_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_import_crypto_key_version" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_import_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_import_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_import_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_import_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_import_crypto_key_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24639,8 +24705,9 @@ def test_create_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -24808,18 +24875,20 @@ def test_create_import_job_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_create_import_job" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_create_import_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_create_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_create_import_job" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_create_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_create_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -24874,8 +24943,9 @@ def test_update_crypto_key_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25063,18 +25133,20 @@ def test_update_crypto_key_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_update_crypto_key" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_update_crypto_key_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_update_crypto_key" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_update_crypto_key" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_update_crypto_key_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_update_crypto_key" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25129,8 +25201,9 @@ def test_update_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25324,18 +25397,22 @@ def test_update_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_update_crypto_key_version" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_update_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_update_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_update_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_update_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_update_crypto_key_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25390,8 +25467,9 @@ def test_update_crypto_key_primary_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25462,20 +25540,22 @@ def test_update_crypto_key_primary_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_update_crypto_key_primary_version", - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_update_crypto_key_primary_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "pre_update_crypto_key_primary_version", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_update_crypto_key_primary_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_update_crypto_key_primary_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_update_crypto_key_primary_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25530,8 +25610,9 @@ def test_destroy_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25621,19 +25702,22 @@ def test_destroy_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_destroy_crypto_key_version", - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_destroy_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_destroy_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_destroy_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_destroy_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_destroy_crypto_key_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25688,8 +25772,9 @@ def test_restore_crypto_key_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25779,19 +25864,22 @@ def test_restore_crypto_key_version_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_restore_crypto_key_version", - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_restore_crypto_key_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_restore_crypto_key_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_restore_crypto_key_version", + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_restore_crypto_key_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "pre_restore_crypto_key_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25844,8 +25932,9 @@ def test_encrypt_rest_bad_request(request_type=service.EncryptRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -25918,17 +26007,19 @@ def test_encrypt_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_encrypt" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_encrypt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_encrypt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_encrypt" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_encrypt_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_encrypt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -25979,8 +26070,9 @@ def test_decrypt_rest_bad_request(request_type=service.DecryptRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26049,17 +26141,19 @@ def test_decrypt_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_decrypt" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_decrypt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_decrypt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_decrypt" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_decrypt_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_decrypt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26110,8 +26204,9 @@ def test_raw_encrypt_rest_bad_request(request_type=service.RawEncryptRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26190,17 +26285,20 @@ def test_raw_encrypt_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_raw_encrypt" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_raw_encrypt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_raw_encrypt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_raw_encrypt" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_raw_encrypt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_raw_encrypt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26251,8 +26349,9 @@ def test_raw_decrypt_rest_bad_request(request_type=service.RawDecryptRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26325,17 +26424,20 @@ def test_raw_decrypt_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_raw_decrypt" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_raw_decrypt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_raw_decrypt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_raw_decrypt" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_raw_decrypt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_raw_decrypt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26386,8 +26488,9 @@ def test_asymmetric_sign_rest_bad_request(request_type=service.AsymmetricSignReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26460,18 +26563,20 @@ def test_asymmetric_sign_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_asymmetric_sign" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_asymmetric_sign_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_asymmetric_sign" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_asymmetric_sign" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_asymmetric_sign_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_asymmetric_sign" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26526,8 +26631,9 @@ def test_asymmetric_decrypt_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26596,18 +26702,20 @@ def test_asymmetric_decrypt_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_asymmetric_decrypt" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_asymmetric_decrypt_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_asymmetric_decrypt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_asymmetric_decrypt" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_asymmetric_decrypt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_asymmetric_decrypt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26662,8 +26770,9 @@ def test_mac_sign_rest_bad_request(request_type=service.MacSignRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26734,17 +26843,20 @@ def test_mac_sign_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_mac_sign" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_mac_sign_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_mac_sign" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_mac_sign" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_mac_sign_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_mac_sign" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26795,8 +26907,9 @@ def test_mac_verify_rest_bad_request(request_type=service.MacVerifyRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -26871,17 +26984,20 @@ def test_mac_verify_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_mac_verify" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_mac_verify_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_mac_verify" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_mac_verify" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_mac_verify_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_mac_verify" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -26932,8 +27048,9 @@ def test_decapsulate_rest_bad_request(request_type=service.DecapsulateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27006,17 +27123,20 @@ def test_decapsulate_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_decapsulate" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_decapsulate_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_decapsulate" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_decapsulate" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_decapsulate_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_decapsulate" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27069,8 +27189,9 @@ def test_generate_random_bytes_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -27133,18 +27254,20 @@ def test_generate_random_bytes_rest_interceptors(null_interceptor): ) client = KeyManagementServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "post_generate_random_bytes" - ) as post, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, - "post_generate_random_bytes_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.KeyManagementServiceRestInterceptor, "pre_generate_random_bytes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "post_generate_random_bytes" + ) as post, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, + "post_generate_random_bytes_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.KeyManagementServiceRestInterceptor, "pre_generate_random_bytes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -27202,8 +27325,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27262,8 +27386,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27324,8 +27449,9 @@ def test_get_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27386,8 +27512,9 @@ def test_set_iam_policy_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27448,8 +27575,9 @@ def test_test_iam_permissions_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -27510,8 +27638,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -28373,11 +28502,14 @@ def test_key_management_service_base_transport(): def test_key_management_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.kms_v1.services.key_management_service.transports.KeyManagementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.kms_v1.services.key_management_service.transports.KeyManagementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KeyManagementServiceTransport( @@ -28397,9 +28529,12 @@ def test_key_management_service_base_transport_with_credentials_file(): def test_key_management_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.kms_v1.services.key_management_service.transports.KeyManagementServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.kms_v1.services.key_management_service.transports.KeyManagementServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.KeyManagementServiceTransport() @@ -28477,11 +28612,12 @@ def test_key_management_service_transport_auth_gdch_credentials(transport_class) def test_key_management_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -29343,6 +29479,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = KeyManagementServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = KeyManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_locations(transport: str = "grpc"): client = KeyManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29488,6 +29658,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = KeyManagementServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = KeyManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = KeyManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29631,6 +29835,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = KeyManagementServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = KeyManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_set_iam_policy(transport: str = "grpc"): client = KeyManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29795,6 +30033,41 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = KeyManagementServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = KeyManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = KeyManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -29962,6 +30235,41 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = KeyManagementServiceClient( + 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. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = KeyManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # 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 = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = KeyManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -30139,6 +30447,47 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = KeyManagementServiceClient( + 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__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = KeyManagementServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = KeyManagementServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py index 23b8919c01df..da145bbd36c5 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> LanguageServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py index 77bae4803ec7..4549b22a926f 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py @@ -110,7 +110,7 @@ class LanguageServiceClient(metaclass=LanguageServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = LanguageServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/README.rst b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/README.rst index 42a52d4e3091..6e4cc90b7d94 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/README.rst +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LanguageServiceTransport` is the ABC for all transports. -- public child `LanguageServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LanguageServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLanguageServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LanguageServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LanguageServiceTransport`` is the ABC for all transports. + +- public child ``LanguageServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LanguageServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLanguageServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LanguageServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/base.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/base.py index d630e3631cf7..418899fac86e 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/base.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py index 119597f4af99..1eacd84bfea3 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py index e4590b1f6334..fe0533ceadee 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/rest.py b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/rest.py index 1a965757f7a8..4cf8ebc58aaf 100644 --- a/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/rest.py +++ b/packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/rest.py @@ -557,6 +557,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LanguageServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py index 6a56901f0961..c171bbc5e64f 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> LanguageServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py index 6429a5c16ef9..86f309258fcd 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py @@ -110,7 +110,7 @@ class LanguageServiceClient(metaclass=LanguageServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = LanguageServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/README.rst b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/README.rst index 42a52d4e3091..6e4cc90b7d94 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/README.rst +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LanguageServiceTransport` is the ABC for all transports. -- public child `LanguageServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LanguageServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLanguageServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LanguageServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LanguageServiceTransport`` is the ABC for all transports. + +- public child ``LanguageServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LanguageServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLanguageServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LanguageServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/base.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/base.py index 4fa4d5e49a27..d584fca7d5ee 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/base.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py index e8e9e0c5456d..a7a1c46fed97 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py index a27cd776a646..5346b59e2368 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/rest.py b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/rest.py index 75ab8665949c..618a5ccbdd50 100644 --- a/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/rest.py +++ b/packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/rest.py @@ -557,6 +557,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LanguageServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/async_client.py b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/async_client.py index 1d78626ee20a..3780fcd54c77 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/async_client.py +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/async_client.py @@ -184,7 +184,7 @@ def transport(self) -> LanguageServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/client.py b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/client.py index 2fd04191a594..de235fc0c1c7 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/client.py +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/client.py @@ -110,7 +110,7 @@ class LanguageServiceClient(metaclass=LanguageServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -510,7 +514,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = LanguageServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/README.rst b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/README.rst index 42a52d4e3091..6e4cc90b7d94 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/README.rst +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LanguageServiceTransport` is the ABC for all transports. -- public child `LanguageServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LanguageServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLanguageServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LanguageServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LanguageServiceTransport`` is the ABC for all transports. + +- public child ``LanguageServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LanguageServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLanguageServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LanguageServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/base.py b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/base.py index cc05f0c42c09..bd1d6b415bb5 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/base.py +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc.py b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc.py index 839d35bd45de..3a4c4e08e4c0 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc.py +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc_asyncio.py b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc_asyncio.py index 6e1ff3d978b3..c3dad252eb13 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/rest.py b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/rest.py index 9b3ca98e498d..4fa3015a001a 100644 --- a/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/rest.py +++ b/packages/google-cloud-language/google/cloud/language_v2/services/language_service/transports/rest.py @@ -439,6 +439,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LanguageServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-language/noxfile.py b/packages/google-cloud-language/noxfile.py index fa5a67e305b9..5c07a86bc2d0 100644 --- a/packages/google-cloud-language/noxfile.py +++ b/packages/google-cloud-language/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-language/setup.py b/packages/google-cloud-language/setup.py index d9a8cee41914..386ca78f03cd 100644 --- a/packages/google-cloud-language/setup.py +++ b/packages/google-cloud-language/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-language" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-language/testing/constraints-3.7.txt b/packages/google-cloud-language/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-language/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-language/testing/constraints-3.8.txt b/packages/google-cloud-language/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-language/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-language/testing/constraints-3.9.txt b/packages/google-cloud-language/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-language/testing/constraints-3.9.txt +++ b/packages/google-cloud-language/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py b/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py index f9878735ce1f..fbb881bcaf3c 100644 --- a/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py +++ b/packages/google-cloud-language/tests/unit/gapic/language_v1/test_language_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LanguageServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( LanguageServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LanguageServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1303,11 +1308,13 @@ def test_language_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5043,8 +5050,9 @@ def test_analyze_sentiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5107,18 +5115,20 @@ def test_analyze_sentiment_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_sentiment" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, - "post_analyze_sentiment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_sentiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_sentiment" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_sentiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_sentiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5176,8 +5186,9 @@ def test_analyze_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5240,17 +5251,20 @@ def test_analyze_entities_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entities" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entities_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_entities" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5308,8 +5322,9 @@ def test_analyze_entity_sentiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5372,18 +5387,20 @@ def test_analyze_entity_sentiment_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entity_sentiment" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, - "post_analyze_entity_sentiment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_entity_sentiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_entity_sentiment" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_entity_sentiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_entity_sentiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5441,8 +5458,9 @@ def test_analyze_syntax_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5505,17 +5523,20 @@ def test_analyze_syntax_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_syntax" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_syntax_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_syntax" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_syntax" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_syntax_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_syntax" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5573,8 +5594,9 @@ def test_classify_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5634,17 +5656,20 @@ def test_classify_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_classify_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_classify_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_classify_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_classify_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_classify_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_classify_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5702,8 +5727,9 @@ def test_moderate_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5763,17 +5789,20 @@ def test_moderate_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_moderate_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_moderate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_moderate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_moderate_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_moderate_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_moderate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5831,8 +5860,9 @@ def test_annotate_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5895,17 +5925,20 @@ def test_annotate_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_annotate_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_annotate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_annotate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_annotate_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_annotate_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_annotate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6162,11 +6195,14 @@ def test_language_service_base_transport(): def test_language_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.language_v1.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.language_v1.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LanguageServiceTransport( @@ -6186,9 +6222,12 @@ def test_language_service_base_transport_with_credentials_file(): def test_language_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.language_v1.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.language_v1.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LanguageServiceTransport() @@ -6266,11 +6305,12 @@ def test_language_service_transport_auth_gdch_credentials(transport_class): def test_language_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py b/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py index 9b33bc96cc40..a3f1c3d1efac 100644 --- a/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py +++ b/packages/google-cloud-language/tests/unit/gapic/language_v1beta2/test_language_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LanguageServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( LanguageServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LanguageServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1303,11 +1308,13 @@ def test_language_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5044,8 +5051,9 @@ def test_analyze_sentiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5108,18 +5116,20 @@ def test_analyze_sentiment_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_sentiment" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, - "post_analyze_sentiment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_sentiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_sentiment" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_sentiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_sentiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5177,8 +5187,9 @@ def test_analyze_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5241,17 +5252,20 @@ def test_analyze_entities_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entities" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entities_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_entities" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5309,8 +5323,9 @@ def test_analyze_entity_sentiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5373,18 +5388,20 @@ def test_analyze_entity_sentiment_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entity_sentiment" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, - "post_analyze_entity_sentiment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_entity_sentiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_entity_sentiment" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_entity_sentiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_entity_sentiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5442,8 +5459,9 @@ def test_analyze_syntax_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5506,17 +5524,20 @@ def test_analyze_syntax_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_syntax" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_syntax_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_syntax" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_syntax" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_syntax_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_syntax" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5574,8 +5595,9 @@ def test_classify_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5635,17 +5657,20 @@ def test_classify_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_classify_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_classify_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_classify_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_classify_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_classify_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_classify_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5703,8 +5728,9 @@ def test_moderate_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5764,17 +5790,20 @@ def test_moderate_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_moderate_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_moderate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_moderate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_moderate_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_moderate_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_moderate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5832,8 +5861,9 @@ def test_annotate_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5896,17 +5926,20 @@ def test_annotate_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_annotate_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_annotate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_annotate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_annotate_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_annotate_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_annotate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6163,11 +6196,14 @@ def test_language_service_base_transport(): def test_language_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.language_v1beta2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.language_v1beta2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LanguageServiceTransport( @@ -6187,9 +6223,12 @@ def test_language_service_base_transport_with_credentials_file(): def test_language_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.language_v1beta2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.language_v1beta2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LanguageServiceTransport() @@ -6267,11 +6306,12 @@ def test_language_service_transport_auth_gdch_credentials(transport_class): def test_language_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-language/tests/unit/gapic/language_v2/test_language_service.py b/packages/google-cloud-language/tests/unit/gapic/language_v2/test_language_service.py index 8143bbb1549b..57fb44ac764b 100644 --- a/packages/google-cloud-language/tests/unit/gapic/language_v2/test_language_service.py +++ b/packages/google-cloud-language/tests/unit/gapic/language_v2/test_language_service.py @@ -118,6 +118,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LanguageServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,10 @@ def test__get_default_mtls_endpoint(): assert ( LanguageServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LanguageServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1303,11 +1308,13 @@ def test_language_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4057,8 +4064,9 @@ def test_analyze_sentiment_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4123,18 +4131,20 @@ def test_analyze_sentiment_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_sentiment" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, - "post_analyze_sentiment_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_sentiment" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_sentiment" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_sentiment_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_sentiment" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4192,8 +4202,9 @@ def test_analyze_entities_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4258,17 +4269,20 @@ def test_analyze_entities_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entities" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_analyze_entities_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_analyze_entities" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_analyze_entities" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_analyze_entities_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_analyze_entities" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4326,8 +4340,9 @@ def test_classify_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4392,17 +4407,20 @@ def test_classify_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_classify_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_classify_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_classify_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_classify_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_classify_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_classify_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4460,8 +4478,9 @@ def test_moderate_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4526,17 +4545,20 @@ def test_moderate_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_moderate_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_moderate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_moderate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_moderate_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_moderate_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_moderate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4594,8 +4616,9 @@ def test_annotate_text_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4660,17 +4683,20 @@ def test_annotate_text_rest_interceptors(null_interceptor): ) client = LanguageServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_annotate_text" - ) as post, mock.patch.object( - transports.LanguageServiceRestInterceptor, "post_annotate_text_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LanguageServiceRestInterceptor, "pre_annotate_text" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "post_annotate_text" + ) as post, + mock.patch.object( + transports.LanguageServiceRestInterceptor, + "post_annotate_text_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LanguageServiceRestInterceptor, "pre_annotate_text" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4883,11 +4909,14 @@ def test_language_service_base_transport(): def test_language_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.language_v2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.language_v2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LanguageServiceTransport( @@ -4907,9 +4936,12 @@ def test_language_service_base_transport_with_credentials_file(): def test_language_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.language_v2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.language_v2.services.language_service.transports.LanguageServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LanguageServiceTransport() @@ -4987,11 +5019,12 @@ def test_language_service_transport_auth_gdch_credentials(transport_class): def test_language_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/async_client.py b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/async_client.py index 1825f0fb601e..172f5f951917 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/async_client.py +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> LicenseManagerTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1980,7 +1980,7 @@ async def sample_get_product(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2006,8 +2006,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2016,7 +2020,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2024,7 +2028,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2035,7 +2039,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2061,8 +2065,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2071,7 +2079,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2079,7 +2087,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2090,7 +2098,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2120,8 +2128,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2130,7 +2142,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2138,7 +2150,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2146,7 +2158,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2175,8 +2187,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2185,7 +2201,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2193,7 +2209,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2201,7 +2217,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2227,8 +2243,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2237,7 +2257,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2245,7 +2265,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2256,7 +2276,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2282,8 +2302,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2292,7 +2316,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2300,7 +2324,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/client.py b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/client.py index a55568045bf9..98c13264010d 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/client.py +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/client.py @@ -117,7 +117,7 @@ class LicenseManagerClient(metaclass=LicenseManagerClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -508,7 +512,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -605,7 +609,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -701,7 +705,7 @@ def __init__( self._universe_domain = LicenseManagerClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2442,7 +2446,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2468,8 +2472,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2478,7 +2486,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2487,7 +2495,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2501,7 +2509,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2527,8 +2535,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2537,7 +2549,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2546,7 +2558,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2560,7 +2572,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2590,8 +2602,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2600,7 +2616,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2608,7 +2624,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2616,7 +2632,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2645,8 +2661,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2655,7 +2675,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2663,7 +2683,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2671,7 +2691,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2697,8 +2717,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2707,7 +2731,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2716,7 +2740,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2730,7 +2754,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2756,8 +2780,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2766,7 +2794,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2775,7 +2803,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/README.rst b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/README.rst index c6e6e486e045..d1e3a4809268 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/README.rst +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LicenseManagerTransport` is the ABC for all transports. -- public child `LicenseManagerGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LicenseManagerGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLicenseManagerRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LicenseManagerRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LicenseManagerTransport`` is the ABC for all transports. + +- public child ``LicenseManagerGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LicenseManagerGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLicenseManagerRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LicenseManagerRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/base.py b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/base.py index 7b93ebc4ba0b..63628b0aab57 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/base.py +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc.py b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc.py index 7d6c1117fd34..06698c801287 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc.py +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc_asyncio.py b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc_asyncio.py index 1d1b1eba32e9..068cad45050d 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/rest.py b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/rest.py index 67f60406b987..bf8f6a470567 100644 --- a/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/rest.py +++ b/packages/google-cloud-licensemanager/google/cloud/licensemanager_v1/services/license_manager/transports/rest.py @@ -1038,6 +1038,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LicenseManagerRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-licensemanager/noxfile.py b/packages/google-cloud-licensemanager/noxfile.py index e9f860201c64..01b97cceaf11 100644 --- a/packages/google-cloud-licensemanager/noxfile.py +++ b/packages/google-cloud-licensemanager/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-licensemanager/setup.py b/packages/google-cloud-licensemanager/setup.py index a63a25b163bd..60f55b62665f 100644 --- a/packages/google-cloud-licensemanager/setup.py +++ b/packages/google-cloud-licensemanager/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-licensemanager" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-licensemanager/testing/constraints-3.7.txt b/packages/google-cloud-licensemanager/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-licensemanager/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-licensemanager/testing/constraints-3.8.txt b/packages/google-cloud-licensemanager/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-licensemanager/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-licensemanager/testing/constraints-3.9.txt b/packages/google-cloud-licensemanager/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-licensemanager/testing/constraints-3.9.txt +++ b/packages/google-cloud-licensemanager/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-licensemanager/tests/unit/gapic/licensemanager_v1/test_license_manager.py b/packages/google-cloud-licensemanager/tests/unit/gapic/licensemanager_v1/test_license_manager.py index aeff23e5679f..13965beb6bf6 100644 --- a/packages/google-cloud-licensemanager/tests/unit/gapic/licensemanager_v1/test_license_manager.py +++ b/packages/google-cloud-licensemanager/tests/unit/gapic/licensemanager_v1/test_license_manager.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LicenseManagerClient._get_default_mtls_endpoint(None) is None assert ( @@ -149,6 +150,10 @@ def test__get_default_mtls_endpoint(): assert ( LicenseManagerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LicenseManagerClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1289,11 +1294,13 @@ def test_license_manager_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10223,8 +10230,9 @@ def test_list_configurations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10289,18 +10297,20 @@ def test_list_configurations_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_list_configurations" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_list_configurations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_list_configurations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_list_configurations" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_list_configurations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_list_configurations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10358,8 +10368,9 @@ def test_get_configuration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10433,17 +10444,20 @@ def test_get_configuration_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_get_configuration" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_get_configuration_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_get_configuration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_get_configuration" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_get_configuration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_get_configuration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10496,8 +10510,9 @@ def test_create_configuration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10637,20 +10652,21 @@ def test_create_configuration_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_create_configuration" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_create_configuration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_create_configuration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_create_configuration" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_create_configuration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_create_configuration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10707,8 +10723,9 @@ def test_update_configuration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10852,20 +10869,21 @@ def test_update_configuration_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_update_configuration" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_update_configuration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_update_configuration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_update_configuration" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_update_configuration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_update_configuration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10918,8 +10936,9 @@ def test_delete_configuration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10976,20 +10995,21 @@ def test_delete_configuration_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_delete_configuration" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_delete_configuration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_delete_configuration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_delete_configuration" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_delete_configuration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_delete_configuration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11042,8 +11062,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11108,17 +11129,20 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_list_instances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11174,8 +11198,9 @@ def test_get_instance_rest_bad_request(request_type=licensemanager.GetInstanceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11246,17 +11271,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11309,8 +11336,9 @@ def test_deactivate_configuration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11367,20 +11395,21 @@ def test_deactivate_configuration_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_deactivate_configuration" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_deactivate_configuration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_deactivate_configuration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_deactivate_configuration" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_deactivate_configuration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_deactivate_configuration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11433,8 +11462,9 @@ def test_reactivate_configuration_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11491,20 +11521,21 @@ def test_reactivate_configuration_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_reactivate_configuration" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_reactivate_configuration_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_reactivate_configuration" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_reactivate_configuration" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_reactivate_configuration_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_reactivate_configuration" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11557,8 +11588,9 @@ def test_query_configuration_license_usage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11620,20 +11652,22 @@ def test_query_configuration_license_usage_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_query_configuration_license_usage", - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "post_query_configuration_license_usage_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, - "pre_query_configuration_license_usage", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_query_configuration_license_usage", + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_query_configuration_license_usage_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "pre_query_configuration_license_usage", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11691,8 +11725,9 @@ def test_aggregate_usage_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11757,17 +11792,20 @@ def test_aggregate_usage_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_aggregate_usage" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_aggregate_usage_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_aggregate_usage" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_aggregate_usage" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, + "post_aggregate_usage_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_aggregate_usage" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11825,8 +11863,9 @@ def test_list_products_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11891,17 +11930,19 @@ def test_list_products_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_list_products" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_list_products_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_list_products" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_list_products" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_list_products_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_list_products" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11957,8 +11998,9 @@ def test_get_product_rest_bad_request(request_type=licensemanager.GetProductRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12033,17 +12075,19 @@ def test_get_product_rest_interceptors(null_interceptor): ) client = LicenseManagerClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_get_product" - ) as post, mock.patch.object( - transports.LicenseManagerRestInterceptor, "post_get_product_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LicenseManagerRestInterceptor, "pre_get_product" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_get_product" + ) as post, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "post_get_product_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LicenseManagerRestInterceptor, "pre_get_product" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12096,8 +12140,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12156,8 +12201,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12218,8 +12264,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12280,8 +12327,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12342,8 +12390,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12404,8 +12453,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12829,11 +12879,14 @@ def test_license_manager_base_transport(): def test_license_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.licensemanager_v1.services.license_manager.transports.LicenseManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.licensemanager_v1.services.license_manager.transports.LicenseManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseManagerTransport( @@ -12850,9 +12903,12 @@ def test_license_manager_base_transport_with_credentials_file(): def test_license_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.licensemanager_v1.services.license_manager.transports.LicenseManagerTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.licensemanager_v1.services.license_manager.transports.LicenseManagerTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LicenseManagerTransport() @@ -12924,11 +12980,12 @@ def test_license_manager_transport_auth_gdch_credentials(transport_class): def test_license_manager_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13641,6 +13698,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = LicenseManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = LicenseManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = LicenseManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13780,6 +13869,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = LicenseManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LicenseManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = LicenseManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -13925,6 +14046,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = LicenseManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LicenseManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = LicenseManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14070,6 +14225,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = LicenseManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LicenseManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = LicenseManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14215,6 +14404,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = LicenseManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = LicenseManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = LicenseManagerClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14356,6 +14579,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = LicenseManagerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = LicenseManagerAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = LicenseManagerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/async_client.py b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/async_client.py index 60426df03b26..27f292043541 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/async_client.py +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> WorkflowsServiceV2BetaTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -427,7 +427,7 @@ async def sample_run_pipeline(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -453,8 +453,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -463,7 +467,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -471,7 +475,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -482,7 +486,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -508,8 +512,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -518,7 +526,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -526,7 +534,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -537,7 +545,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -566,8 +574,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -576,7 +588,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -584,7 +596,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -592,7 +604,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -618,8 +630,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -628,7 +644,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -636,7 +652,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -647,7 +663,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -673,8 +689,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -683,7 +703,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -691,7 +711,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/client.py b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/client.py index cc581ff0440e..feb4362017b9 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/client.py +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/client.py @@ -115,7 +115,7 @@ class WorkflowsServiceV2BetaClient(metaclass=WorkflowsServiceV2BetaClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -418,7 +422,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -517,7 +521,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -617,7 +621,7 @@ def __init__( self._universe_domain = WorkflowsServiceV2BetaClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -845,7 +849,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -871,8 +875,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -881,7 +889,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -890,7 +898,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -904,7 +912,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -930,8 +938,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -940,7 +952,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -949,7 +961,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -963,7 +975,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -992,8 +1004,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1002,7 +1018,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1010,7 +1026,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1018,7 +1034,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1044,8 +1060,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1054,7 +1074,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1063,7 +1083,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1077,7 +1097,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1103,8 +1123,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1113,7 +1137,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1122,7 +1146,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/README.rst b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/README.rst index d67456623e95..413597678b89 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/README.rst +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`WorkflowsServiceV2BetaTransport` is the ABC for all transports. -- public child `WorkflowsServiceV2BetaGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `WorkflowsServiceV2BetaGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseWorkflowsServiceV2BetaRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `WorkflowsServiceV2BetaRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``WorkflowsServiceV2BetaTransport`` is the ABC for all transports. + +- public child ``WorkflowsServiceV2BetaGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``WorkflowsServiceV2BetaGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseWorkflowsServiceV2BetaRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``WorkflowsServiceV2BetaRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/base.py b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/base.py index a2cca157d306..9ce7f953d55d 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/base.py +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc.py b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc.py index 1e76c8602e45..9cef00251842 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc.py +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc_asyncio.py b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc_asyncio.py index f26151f55832..969c246204d6 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc_asyncio.py +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/rest.py b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/rest.py index 6db499bcca4e..056a8475c39a 100644 --- a/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/rest.py +++ b/packages/google-cloud-life-sciences/google/cloud/lifesciences_v2beta/services/workflows_service_v2_beta/transports/rest.py @@ -325,6 +325,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[WorkflowsServiceV2BetaRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-life-sciences/noxfile.py b/packages/google-cloud-life-sciences/noxfile.py index 60f3fa4cab6e..4c945571f224 100644 --- a/packages/google-cloud-life-sciences/noxfile.py +++ b/packages/google-cloud-life-sciences/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-life-sciences/setup.py b/packages/google-cloud-life-sciences/setup.py index b895d27f4f4d..e2f699d8bc22 100644 --- a/packages/google-cloud-life-sciences/setup.py +++ b/packages/google-cloud-life-sciences/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-life-sciences" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-life-sciences/testing/constraints-3.7.txt b/packages/google-cloud-life-sciences/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-life-sciences/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-life-sciences/testing/constraints-3.8.txt b/packages/google-cloud-life-sciences/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-life-sciences/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-life-sciences/testing/constraints-3.9.txt b/packages/google-cloud-life-sciences/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-life-sciences/testing/constraints-3.9.txt +++ b/packages/google-cloud-life-sciences/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-life-sciences/tests/unit/gapic/lifesciences_v2beta/test_workflows_service_v2_beta.py b/packages/google-cloud-life-sciences/tests/unit/gapic/lifesciences_v2beta/test_workflows_service_v2_beta.py index 1ce7b66c3b58..9dac9b261c30 100644 --- a/packages/google-cloud-life-sciences/tests/unit/gapic/lifesciences_v2beta/test_workflows_service_v2_beta.py +++ b/packages/google-cloud-life-sciences/tests/unit/gapic/lifesciences_v2beta/test_workflows_service_v2_beta.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert WorkflowsServiceV2BetaClient._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): WorkflowsServiceV2BetaClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + WorkflowsServiceV2BetaClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1352,11 +1357,13 @@ def test_workflows_service_v2_beta_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1922,8 +1929,9 @@ def test_run_pipeline_rest_bad_request(request_type=workflows.RunPipelineRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -1980,20 +1988,21 @@ def test_run_pipeline_rest_interceptors(null_interceptor): ) client = WorkflowsServiceV2BetaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.WorkflowsServiceV2BetaRestInterceptor, "post_run_pipeline" - ) as post, mock.patch.object( - transports.WorkflowsServiceV2BetaRestInterceptor, - "post_run_pipeline_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.WorkflowsServiceV2BetaRestInterceptor, "pre_run_pipeline" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.WorkflowsServiceV2BetaRestInterceptor, "post_run_pipeline" + ) as post, + mock.patch.object( + transports.WorkflowsServiceV2BetaRestInterceptor, + "post_run_pipeline_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.WorkflowsServiceV2BetaRestInterceptor, "pre_run_pipeline" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2044,8 +2053,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2104,8 +2114,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2166,8 +2177,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2228,8 +2240,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2290,8 +2303,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -2446,11 +2460,14 @@ def test_workflows_service_v2_beta_base_transport(): def test_workflows_service_v2_beta_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.lifesciences_v2beta.services.workflows_service_v2_beta.transports.WorkflowsServiceV2BetaTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.lifesciences_v2beta.services.workflows_service_v2_beta.transports.WorkflowsServiceV2BetaTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowsServiceV2BetaTransport( @@ -2467,9 +2484,12 @@ def test_workflows_service_v2_beta_base_transport_with_credentials_file(): def test_workflows_service_v2_beta_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.lifesciences_v2beta.services.workflows_service_v2_beta.transports.WorkflowsServiceV2BetaTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.lifesciences_v2beta.services.workflows_service_v2_beta.transports.WorkflowsServiceV2BetaTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.WorkflowsServiceV2BetaTransport() @@ -2543,11 +2563,12 @@ def test_workflows_service_v2_beta_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3120,6 +3141,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = WorkflowsServiceV2BetaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = WorkflowsServiceV2BetaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = WorkflowsServiceV2BetaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3265,6 +3318,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = WorkflowsServiceV2BetaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = WorkflowsServiceV2BetaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = WorkflowsServiceV2BetaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3410,6 +3497,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = WorkflowsServiceV2BetaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = WorkflowsServiceV2BetaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = WorkflowsServiceV2BetaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3555,6 +3676,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = WorkflowsServiceV2BetaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = WorkflowsServiceV2BetaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = WorkflowsServiceV2BetaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -3700,6 +3855,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = WorkflowsServiceV2BetaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = WorkflowsServiceV2BetaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = WorkflowsServiceV2BetaClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/async_client.py b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/async_client.py index 0a8cba81bff0..c0d5a2370167 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/async_client.py +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> CloudLocationFinderTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -696,7 +696,7 @@ async def sample_search_cloud_locations(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -722,8 +722,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -732,7 +736,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -740,7 +744,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -751,7 +755,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -777,8 +781,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -787,7 +795,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -795,7 +803,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/client.py b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/client.py index 6cefe41e4a19..33d42afb26a4 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/client.py +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/client.py @@ -111,7 +111,7 @@ class CloudLocationFinderClient(metaclass=CloudLocationFinderClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -119,7 +119,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -129,6 +129,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -436,7 +440,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -533,7 +537,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -633,7 +637,7 @@ def __init__( self._universe_domain = CloudLocationFinderClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1127,7 +1131,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1153,8 +1157,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,7 +1171,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1172,7 +1180,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1186,7 +1194,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1212,8 +1220,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1222,7 +1234,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1231,7 +1243,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/README.rst b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/README.rst index 96e3d5f30285..a8bd1cbb0d29 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/README.rst +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudLocationFinderTransport` is the ABC for all transports. -- public child `CloudLocationFinderGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudLocationFinderGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudLocationFinderRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudLocationFinderRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudLocationFinderTransport`` is the ABC for all transports. + +- public child ``CloudLocationFinderGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudLocationFinderGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudLocationFinderRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudLocationFinderRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/base.py b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/base.py index 6c2ddb777674..0da7a48f7f4c 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/base.py +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc.py b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc.py index 1f1f16a36f28..32c1678f2884 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc.py +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc_asyncio.py b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc_asyncio.py index 69408a4e6b2b..c34883a0bf91 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc_asyncio.py +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/rest.py b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/rest.py index b4916025f50a..7c3094361e4a 100644 --- a/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/rest.py +++ b/packages/google-cloud-locationfinder/google/cloud/locationfinder_v1/services/cloud_location_finder/transports/rest.py @@ -372,6 +372,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudLocationFinderRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-locationfinder/noxfile.py b/packages/google-cloud-locationfinder/noxfile.py index 2e8a32bc128e..c65f49f156d6 100644 --- a/packages/google-cloud-locationfinder/noxfile.py +++ b/packages/google-cloud-locationfinder/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-locationfinder/setup.py b/packages/google-cloud-locationfinder/setup.py index 30e872430f19..7718a159db87 100644 --- a/packages/google-cloud-locationfinder/setup.py +++ b/packages/google-cloud-locationfinder/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-locationfinder" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-locationfinder/testing/constraints-3.7.txt b/packages/google-cloud-locationfinder/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-locationfinder/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-locationfinder/testing/constraints-3.8.txt b/packages/google-cloud-locationfinder/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-locationfinder/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-locationfinder/testing/constraints-3.9.txt b/packages/google-cloud-locationfinder/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-locationfinder/testing/constraints-3.9.txt +++ b/packages/google-cloud-locationfinder/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-locationfinder/tests/unit/gapic/locationfinder_v1/test_cloud_location_finder.py b/packages/google-cloud-locationfinder/tests/unit/gapic/locationfinder_v1/test_cloud_location_finder.py index 669102748a0f..9bad6cba7088 100644 --- a/packages/google-cloud-locationfinder/tests/unit/gapic/locationfinder_v1/test_cloud_location_finder.py +++ b/packages/google-cloud-locationfinder/tests/unit/gapic/locationfinder_v1/test_cloud_location_finder.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudLocationFinderClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): CloudLocationFinderClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudLocationFinderClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1341,11 +1346,13 @@ def test_cloud_location_finder_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3903,8 +3910,9 @@ def test_list_cloud_locations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3967,18 +3975,20 @@ def test_list_cloud_locations_rest_interceptors(null_interceptor): ) client = CloudLocationFinderClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, "post_list_cloud_locations" - ) as post, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, - "post_list_cloud_locations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, "pre_list_cloud_locations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, "post_list_cloud_locations" + ) as post, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, + "post_list_cloud_locations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, "pre_list_cloud_locations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4036,8 +4046,9 @@ def test_get_cloud_location_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4120,18 +4131,20 @@ def test_get_cloud_location_rest_interceptors(null_interceptor): ) client = CloudLocationFinderClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, "post_get_cloud_location" - ) as post, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, - "post_get_cloud_location_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, "pre_get_cloud_location" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, "post_get_cloud_location" + ) as post, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, + "post_get_cloud_location_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, "pre_get_cloud_location" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4186,8 +4199,9 @@ def test_search_cloud_locations_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4250,18 +4264,20 @@ def test_search_cloud_locations_rest_interceptors(null_interceptor): ) client = CloudLocationFinderClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, "post_search_cloud_locations" - ) as post, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, - "post_search_cloud_locations_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudLocationFinderRestInterceptor, "pre_search_cloud_locations" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, "post_search_cloud_locations" + ) as post, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, + "post_search_cloud_locations_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudLocationFinderRestInterceptor, "pre_search_cloud_locations" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4319,8 +4335,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4379,8 +4396,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4558,11 +4576,14 @@ def test_cloud_location_finder_base_transport(): def test_cloud_location_finder_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.locationfinder_v1.services.cloud_location_finder.transports.CloudLocationFinderTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.locationfinder_v1.services.cloud_location_finder.transports.CloudLocationFinderTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudLocationFinderTransport( @@ -4579,9 +4600,12 @@ def test_cloud_location_finder_base_transport_with_credentials_file(): def test_cloud_location_finder_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.locationfinder_v1.services.cloud_location_finder.transports.CloudLocationFinderTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.locationfinder_v1.services.cloud_location_finder.transports.CloudLocationFinderTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudLocationFinderTransport() @@ -4653,11 +4677,12 @@ def test_cloud_location_finder_transport_auth_gdch_credentials(transport_class): def test_cloud_location_finder_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5236,6 +5261,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudLocationFinderClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudLocationFinderAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CloudLocationFinderClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5379,6 +5438,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CloudLocationFinderClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudLocationFinderAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CloudLocationFinderClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/async_client.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/async_client.py index c09d1132abba..1b1cf6d24445 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -209,7 +209,7 @@ def transport(self) -> ConfigServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4058,7 +4058,7 @@ async def sample_copy_log_entries(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4084,8 +4084,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4094,7 +4098,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4102,7 +4106,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4113,7 +4117,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4139,8 +4143,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4149,7 +4157,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4157,7 +4165,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4168,7 +4176,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4197,8 +4205,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4207,7 +4219,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4215,7 +4227,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/client.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/client.py index 5dd5557c73a6..242bb3ff5779 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/client.py @@ -115,7 +115,7 @@ class ConfigServiceV2Client(metaclass=ConfigServiceV2ClientMeta): """Service for configuring sinks used to route log entries.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -552,7 +556,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -649,7 +653,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -747,7 +751,7 @@ def __init__( self._universe_domain = ConfigServiceV2Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4519,7 +4523,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4545,8 +4549,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4555,7 +4563,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4564,7 +4572,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4578,7 +4586,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4604,8 +4612,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4614,7 +4626,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4623,7 +4635,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4637,7 +4649,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4666,8 +4678,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4676,7 +4692,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4684,7 +4700,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/README.rst b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/README.rst index 4ea84879601d..ffced6a3c3f5 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/README.rst +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ConfigServiceV2Transport` is the ABC for all transports. -- public child `ConfigServiceV2GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ConfigServiceV2GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseConfigServiceV2RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ConfigServiceV2RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ConfigServiceV2Transport`` is the ABC for all transports. + +- public child ``ConfigServiceV2GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ConfigServiceV2GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseConfigServiceV2RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ConfigServiceV2RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py index 509bce7f5dcc..d0b5bbd47c87 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py index 72f2c68f079a..a484749fcd8a 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py index 835770dcc12c..6e1ca1e1f45c 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 5dcaf0794c7c..4b59013dbf04 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -192,7 +192,7 @@ def transport(self) -> LoggingServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1097,7 +1097,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1123,8 +1123,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1133,7 +1137,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1141,7 +1145,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1152,7 +1156,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1178,8 +1182,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1188,7 +1196,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1196,7 +1204,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1207,7 +1215,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1236,8 +1244,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1246,7 +1258,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1254,7 +1266,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/client.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/client.py index 8b8a5186f224..f247216f3a01 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -113,7 +113,7 @@ class LoggingServiceV2Client(metaclass=LoggingServiceV2ClientMeta): """Service for ingesting and querying logs.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -530,7 +534,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = LoggingServiceV2Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1518,7 +1522,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1544,8 +1548,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1554,7 +1562,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1563,7 +1571,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1577,7 +1585,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1603,8 +1611,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1613,7 +1625,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1622,7 +1634,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1636,7 +1648,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1665,8 +1677,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1675,7 +1691,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1683,7 +1699,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/README.rst b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/README.rst index 897a4c7bfaec..5a86bd1e111f 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/README.rst +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LoggingServiceV2Transport` is the ABC for all transports. -- public child `LoggingServiceV2GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LoggingServiceV2GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLoggingServiceV2RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LoggingServiceV2RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LoggingServiceV2Transport`` is the ABC for all transports. + +- public child ``LoggingServiceV2GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LoggingServiceV2GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLoggingServiceV2RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LoggingServiceV2RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py index f9dc0914a73b..05b73ee53a93 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py index 3597556c6c8a..b9564e9e0417 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py index 2f6aa2e0e3d7..63383e7ae17f 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index 9513b3d0b34c..d06534be76c4 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -191,7 +191,7 @@ def transport(self) -> MetricsServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -945,7 +945,7 @@ async def sample_delete_log_metric(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -971,8 +971,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -981,7 +985,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -989,7 +993,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1000,7 +1004,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1026,8 +1030,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1036,7 +1044,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1044,7 +1052,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1055,7 +1063,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1084,8 +1092,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1094,7 +1106,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1102,7 +1114,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/client.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/client.py index ec266d9cc5e5..70e3c42323a3 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -113,7 +113,7 @@ class MetricsServiceV2Client(metaclass=MetricsServiceV2ClientMeta): """Service for configuring logs-based metrics.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -433,7 +437,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -530,7 +534,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -628,7 +632,7 @@ def __init__( self._universe_domain = MetricsServiceV2Client._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1367,7 +1371,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1393,8 +1397,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,7 +1411,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1412,7 +1420,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1426,7 +1434,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1452,8 +1460,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1462,7 +1474,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1471,7 +1483,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1485,7 +1497,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1514,8 +1526,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1524,7 +1540,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1532,7 +1548,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/README.rst b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/README.rst index 00dffa25f329..19e5d9fc6c0a 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/README.rst +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetricsServiceV2Transport` is the ABC for all transports. -- public child `MetricsServiceV2GrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetricsServiceV2GrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetricsServiceV2RestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetricsServiceV2RestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetricsServiceV2Transport`` is the ABC for all transports. + +- public child ``MetricsServiceV2GrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetricsServiceV2GrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetricsServiceV2RestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetricsServiceV2RestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py index 2efed7ee1f34..866353cfe0e9 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py @@ -88,6 +88,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -137,6 +141,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py index d635bdc29418..ffa66c672c5f 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py index cbaef18b785f..2bbdb0516508 100644 --- a/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py +++ b/packages/google-cloud-logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-logging/noxfile.py b/packages/google-cloud-logging/noxfile.py index 27760f9e69d4..93d54ee3b797 100644 --- a/packages/google-cloud-logging/noxfile.py +++ b/packages/google-cloud-logging/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -299,7 +297,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -529,7 +530,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -624,7 +625,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-logging/setup.py b/packages/google-cloud-logging/setup.py index c8a7047e882d..9be3ab0005fa 100644 --- a/packages/google-cloud-logging/setup.py +++ b/packages/google-cloud-logging/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -52,7 +52,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-logging" @@ -84,8 +84,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -97,7 +95,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-logging/testing/constraints-3.7.txt b/packages/google-cloud-logging/testing/constraints-3.7.txt deleted file mode 100644 index fec3bf897850..000000000000 --- a/packages/google-cloud-logging/testing/constraints-3.7.txt +++ /dev/null @@ -1,29 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -google-cloud-core==2.0.0 -google-cloud-appengine-logging==0.1.3 -google-cloud-audit-log==0.3.1 -grpc-google-iam-v1==0.12.4 -opentelemetry-api==1.16.0 - -# Lower bound testing for optional dependencies -django==3.2 - -# Need specific versions of Flask dependencies for Flask 1.0 to work -flask==1.0.0 -jinja2==2.10.1 -markupsafe==2.0.1 -itsdangerous==2.0.1 -werkzeug==1.0.1 -protobuf==3.20.2 diff --git a/packages/google-cloud-logging/testing/constraints-3.8.txt b/packages/google-cloud-logging/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-logging/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-logging/testing/constraints-3.9.txt b/packages/google-cloud-logging/testing/constraints-3.9.txt index 7599dea499ed..b12ab458012e 100644 --- a/packages/google-cloud-logging/testing/constraints-3.9.txt +++ b/packages/google-cloud-logging/testing/constraints-3.9.txt @@ -1,10 +1,28 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +google-cloud-core==2.0.0 +google-cloud-appengine-logging==0.1.3 +google-cloud-audit-log==0.3.1 +grpc-google-iam-v1==0.12.4 +opentelemetry-api==1.16.0 + +# Lower bound testing for optional dependencies +django==3.2 + +# Need specific versions of Flask dependencies for Flask 1.0 to work +flask==1.0.0 +jinja2==2.10.1 +markupsafe==2.0.1 +itsdangerous==2.0.1 +werkzeug==1.0.1 +protobuf==4.25.8 diff --git a/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index 5ebaa82f6d2c..663d73392541 100644 --- a/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigServiceV2Client._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): assert ( ConfigServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ConfigServiceV2Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1283,11 +1288,13 @@ def test_config_service_v2_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -13617,11 +13624,14 @@ def test_config_service_v2_base_transport(): def test_config_service_v2_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigServiceV2Transport( @@ -13643,9 +13653,12 @@ def test_config_service_v2_base_transport_with_credentials_file(): def test_config_service_v2_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ConfigServiceV2Transport() @@ -13726,11 +13739,12 @@ def test_config_service_v2_transport_auth_gdch_credentials(transport_class): def test_config_service_v2_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -14437,6 +14451,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -14582,6 +14628,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -14727,6 +14807,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 36aaa660899e..5268a9c4ee4b 100644 --- a/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -125,6 +125,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LoggingServiceV2Client._get_default_mtls_endpoint(None) is None assert ( @@ -147,6 +148,10 @@ def test__get_default_mtls_endpoint(): LoggingServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + LoggingServiceV2Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1284,11 +1289,13 @@ def test_logging_service_v2_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3896,11 +3903,14 @@ def test_logging_service_v2_base_transport(): def test_logging_service_v2_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.logging_v2.services.logging_service_v2.transports.LoggingServiceV2Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.logging_v2.services.logging_service_v2.transports.LoggingServiceV2Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LoggingServiceV2Transport( @@ -3923,9 +3933,12 @@ def test_logging_service_v2_base_transport_with_credentials_file(): def test_logging_service_v2_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.logging_v2.services.logging_service_v2.transports.LoggingServiceV2Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.logging_v2.services.logging_service_v2.transports.LoggingServiceV2Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LoggingServiceV2Transport() @@ -4008,11 +4021,12 @@ def test_logging_service_v2_transport_auth_gdch_credentials(transport_class): def test_logging_service_v2_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4535,6 +4549,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4680,6 +4726,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4825,6 +4905,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 3fa6f896197e..5ccfd70a89c2 100644 --- a/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/packages/google-cloud-logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetricsServiceV2Client._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): MetricsServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetricsServiceV2Client._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1283,11 +1288,13 @@ def test_metrics_service_v2_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3701,11 +3708,14 @@ def test_metrics_service_v2_base_transport(): def test_metrics_service_v2_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.logging_v2.services.metrics_service_v2.transports.MetricsServiceV2Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.logging_v2.services.metrics_service_v2.transports.MetricsServiceV2Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsServiceV2Transport( @@ -3728,9 +3738,12 @@ def test_metrics_service_v2_base_transport_with_credentials_file(): def test_metrics_service_v2_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.logging_v2.services.metrics_service_v2.transports.MetricsServiceV2Transport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.logging_v2.services.metrics_service_v2.transports.MetricsServiceV2Transport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsServiceV2Transport() @@ -3813,11 +3826,12 @@ def test_metrics_service_v2_transport_auth_gdch_credentials(transport_class): def test_metrics_service_v2_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4340,6 +4354,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = MetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4485,6 +4531,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = MetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), @@ -4630,6 +4710,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = MetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_transport_close_grpc(): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-logging/tests/unit/handlers/test_app_engine.py b/packages/google-cloud-logging/tests/unit/handlers/test_app_engine.py index b576339368f8..572567948ea0 100644 --- a/packages/google-cloud-logging/tests/unit/handlers/test_app_engine.py +++ b/packages/google-cloud-logging/tests/unit/handlers/test_app_engine.py @@ -39,18 +39,22 @@ def test_constructor_w_gae_standard_env(self): # Verify that project/service/version are picked up from the # environment. - with mock.patch( - "os.environ", - new={ - app_engine._GAE_SERVICE_ENV: "test_service", - app_engine._GAE_VERSION_ENV: "test_version", - }, - ), mock.patch( - "google.cloud.logging_v2.handlers._monitored_resources.retrieve_metadata_server", - return_value=self.PROJECT, - ), pytest.warns( - DeprecationWarning, - match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + with ( + mock.patch( + "os.environ", + new={ + app_engine._GAE_SERVICE_ENV: "test_service", + app_engine._GAE_VERSION_ENV: "test_version", + }, + ), + mock.patch( + "google.cloud.logging_v2.handlers._monitored_resources.retrieve_metadata_server", + return_value=self.PROJECT, + ), + pytest.warns( + DeprecationWarning, + match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + ), ): handler = self._make_one(client, transport=_Transport) @@ -73,20 +77,24 @@ def test_constructor_w_gae_flex_env(self): # Verify that _GAE_PROJECT_ENV_FLEX environment variable takes # precedence over _GAE_PROJECT_ENV_STANDARD. - with mock.patch( - "os.environ", - new={ - app_engine._GAE_PROJECT_ENV_FLEX: "test_project_2", - app_engine._GAE_PROJECT_ENV_STANDARD: "test_project_should_be_overridden", - app_engine._GAE_SERVICE_ENV: "test_service_2", - app_engine._GAE_VERSION_ENV: "test_version_2", - }, - ), mock.patch( - "google.cloud.logging_v2.handlers._monitored_resources.retrieve_metadata_server", - return_value=self.PROJECT, - ), pytest.warns( - DeprecationWarning, - match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + with ( + mock.patch( + "os.environ", + new={ + app_engine._GAE_PROJECT_ENV_FLEX: "test_project_2", + app_engine._GAE_PROJECT_ENV_STANDARD: "test_project_should_be_overridden", + app_engine._GAE_SERVICE_ENV: "test_service_2", + app_engine._GAE_VERSION_ENV: "test_version_2", + }, + ), + mock.patch( + "google.cloud.logging_v2.handlers._monitored_resources.retrieve_metadata_server", + return_value=self.PROJECT, + ), + pytest.warns( + DeprecationWarning, + match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + ), ): handler = self._make_one( client, name=name, transport=_Transport, stream=stream @@ -108,9 +116,12 @@ def test_emit(self): "google.cloud.logging_v2.handlers.app_engine.get_request_data", return_value=(expected_http_request, trace_id, None, None), ) - with get_request_patch, pytest.warns( - DeprecationWarning, - match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + with ( + get_request_patch, + pytest.warns( + DeprecationWarning, + match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + ), ): # library integrations mocked to return test data client = mock.Mock(project=self.PROJECT, spec=["project"]) @@ -149,9 +160,12 @@ def test_emit_manual_field_override(self): "google.cloud.logging_v2.handlers.app_engine.get_request_data", return_value=(inferred_http_request, inferred_trace_id, None, None), ) - with get_request_patch, pytest.warns( - DeprecationWarning, - match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + with ( + get_request_patch, + pytest.warns( + DeprecationWarning, + match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead", + ), ): # library integrations mocked to return test data client = mock.Mock(project=self.PROJECT, spec=["project"]) diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/async_client.py b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/async_client.py index 17ea4b05e826..d519cb3c58a3 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/async_client.py +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> LustreTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1214,7 +1214,7 @@ async def sample_export_data(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1240,8 +1240,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1250,7 +1254,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1258,7 +1262,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1269,7 +1273,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1295,8 +1299,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1305,7 +1313,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1313,7 +1321,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1324,7 +1332,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1354,8 +1362,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1364,7 +1376,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1372,7 +1384,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1380,7 +1392,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1409,8 +1421,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1419,7 +1435,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1427,7 +1443,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1435,7 +1451,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1461,8 +1477,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1471,7 +1491,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1479,7 +1499,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1490,7 +1510,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1516,8 +1536,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1526,7 +1550,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1534,7 +1558,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/client.py b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/client.py index 94cb2903b97a..c2a7e728c9d7 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/client.py +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/client.py @@ -118,7 +118,7 @@ class LustreClient(metaclass=LustreClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -126,7 +126,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -136,6 +136,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -482,7 +486,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -579,7 +583,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -675,7 +679,7 @@ def __init__( self._universe_domain = LustreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1679,7 +1683,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1705,8 +1709,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1715,7 +1723,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1724,7 +1732,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1738,7 +1746,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1764,8 +1772,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1774,7 +1786,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1783,7 +1795,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1797,7 +1809,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1827,8 +1839,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1837,7 +1853,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1845,7 +1861,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1853,7 +1869,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1882,8 +1898,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1892,7 +1912,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1900,7 +1920,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1908,7 +1928,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1934,8 +1954,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1944,7 +1968,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1953,7 +1977,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1967,7 +1991,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1993,8 +2017,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2003,7 +2031,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2012,7 +2040,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/README.rst b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/README.rst index f475193be956..ef48e6827649 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/README.rst +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`LustreTransport` is the ABC for all transports. -- public child `LustreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `LustreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseLustreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `LustreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``LustreTransport`` is the ABC for all transports. + +- public child ``LustreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``LustreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseLustreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``LustreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/base.py b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/base.py index 14a5099d28c0..c00ddeedc393 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/base.py +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc.py b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc.py index 2148a78195af..8e8015a65f40 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc.py +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc_asyncio.py b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc_asyncio.py index 57b7ab652927..9ffe989894d0 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc_asyncio.py +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/rest.py b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/rest.py index 8dc9bcac654f..6f4f36ff4ece 100644 --- a/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/rest.py +++ b/packages/google-cloud-lustre/google/cloud/lustre_v1/services/lustre/transports/rest.py @@ -674,6 +674,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[LustreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-lustre/noxfile.py b/packages/google-cloud-lustre/noxfile.py index e66e0094c5c7..b3e9facb7380 100644 --- a/packages/google-cloud-lustre/noxfile.py +++ b/packages/google-cloud-lustre/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-lustre/setup.py b/packages/google-cloud-lustre/setup.py index c66007fe5f3e..550f066fe783 100644 --- a/packages/google-cloud-lustre/setup.py +++ b/packages/google-cloud-lustre/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-lustre" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-lustre/testing/constraints-3.7.txt b/packages/google-cloud-lustre/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-lustre/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-lustre/testing/constraints-3.8.txt b/packages/google-cloud-lustre/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-lustre/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-lustre/testing/constraints-3.9.txt b/packages/google-cloud-lustre/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-lustre/testing/constraints-3.9.txt +++ b/packages/google-cloud-lustre/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-lustre/tests/unit/gapic/lustre_v1/test_lustre.py b/packages/google-cloud-lustre/tests/unit/gapic/lustre_v1/test_lustre.py index 73453439a229..0f54977b13dd 100644 --- a/packages/google-cloud-lustre/tests/unit/gapic/lustre_v1/test_lustre.py +++ b/packages/google-cloud-lustre/tests/unit/gapic/lustre_v1/test_lustre.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LustreClient._get_default_mtls_endpoint(None) is None assert LustreClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -144,6 +145,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert LustreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert LustreClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1222,11 +1224,13 @@ def test_lustre_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5501,8 +5505,9 @@ def test_list_instances_rest_bad_request(request_type=instance.ListInstancesRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5565,17 +5570,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LustreRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LustreRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LustreRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5626,8 +5633,9 @@ def test_get_instance_rest_bad_request(request_type=instance.GetInstanceRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5704,17 +5712,17 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.LustreRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.LustreRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LustreRestInterceptor, "pre_get_instance") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5765,8 +5773,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5902,19 +5911,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LustreRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LustreRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LustreRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5969,8 +5979,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6108,19 +6119,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LustreRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LustreRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LustreRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6171,8 +6183,9 @@ def test_delete_instance_rest_bad_request(request_type=instance.DeleteInstanceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6227,19 +6240,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LustreRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.LustreRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.LustreRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6288,8 +6302,9 @@ def test_import_data_rest_bad_request(request_type=transfer.ImportDataRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6344,19 +6359,16 @@ def test_import_data_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LustreRestInterceptor, "post_import_data" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_import_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_import_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.LustreRestInterceptor, "post_import_data") as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_import_data_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LustreRestInterceptor, "pre_import_data") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6405,8 +6417,9 @@ def test_export_data_rest_bad_request(request_type=transfer.ExportDataRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6461,19 +6474,16 @@ def test_export_data_rest_interceptors(null_interceptor): ) client = LustreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.LustreRestInterceptor, "post_export_data" - ) as post, mock.patch.object( - transports.LustreRestInterceptor, "post_export_data_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.LustreRestInterceptor, "pre_export_data" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object(transports.LustreRestInterceptor, "post_export_data") as post, + mock.patch.object( + transports.LustreRestInterceptor, "post_export_data_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.LustreRestInterceptor, "pre_export_data") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6524,8 +6534,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6584,8 +6595,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6646,8 +6658,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6708,8 +6721,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6770,8 +6784,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6832,8 +6847,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7115,11 +7131,14 @@ def test_lustre_base_transport(): def test_lustre_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.lustre_v1.services.lustre.transports.LustreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.lustre_v1.services.lustre.transports.LustreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LustreTransport( @@ -7136,9 +7155,12 @@ def test_lustre_base_transport_with_credentials_file(): def test_lustre_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.lustre_v1.services.lustre.transports.LustreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.lustre_v1.services.lustre.transports.LustreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.LustreTransport() @@ -7210,11 +7232,12 @@ def test_lustre_transport_auth_gdch_credentials(transport_class): def test_lustre_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7864,6 +7887,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = LustreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = LustreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = LustreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8003,6 +8058,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = LustreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LustreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = LustreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8148,6 +8235,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = LustreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LustreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = LustreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8293,6 +8414,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = LustreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LustreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = LustreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8438,6 +8593,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = LustreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = LustreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = LustreClient( credentials=ga_credentials.AnonymousCredentials(), @@ -8579,6 +8768,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = LustreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = LustreAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = LustreClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/async_client.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/async_client.py index 9910ba9c11fc..3effa5fb0f81 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/async_client.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> MaintenanceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -668,7 +668,7 @@ async def sample_get_resource_maintenance(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -694,8 +694,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -704,7 +708,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -712,7 +716,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -723,7 +727,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -749,8 +753,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -759,7 +767,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -767,7 +775,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/client.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/client.py index e9c3e0fd87b6..599b4bdbe771 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/client.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/client.py @@ -112,7 +112,7 @@ class MaintenanceClient(metaclass=MaintenanceClientMeta): """Unified Maintenance service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -630,7 +634,7 @@ def __init__( self._universe_domain = MaintenanceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1101,7 +1105,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1127,8 +1131,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1137,7 +1145,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1146,7 +1154,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1160,7 +1168,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1186,8 +1194,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1196,7 +1208,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1205,7 +1217,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/README.rst b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/README.rst index a0f65ecd2232..a76797a9d391 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/README.rst +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MaintenanceTransport` is the ABC for all transports. -- public child `MaintenanceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MaintenanceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMaintenanceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MaintenanceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MaintenanceTransport`` is the ABC for all transports. + +- public child ``MaintenanceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MaintenanceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMaintenanceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MaintenanceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/base.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/base.py index 105749c142b0..7363c693d6d5 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/base.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc.py index a8298e9b1a81..5668b2c80da7 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc_asyncio.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc_asyncio.py index 769a8c5a2546..6648daf300c1 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc_asyncio.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/rest.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/rest.py index 81c3ea6fc342..09c6eecc9659 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/rest.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1/services/maintenance/transports/rest.py @@ -375,6 +375,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MaintenanceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/async_client.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/async_client.py index 6814d78bf33e..9cbc70356ba5 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/async_client.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> MaintenanceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -668,7 +668,7 @@ async def sample_get_resource_maintenance(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -694,8 +694,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -704,7 +708,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -712,7 +716,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -723,7 +727,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -749,8 +753,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -759,7 +767,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -767,7 +775,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/client.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/client.py index 5b2853980ec5..f56f11996369 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/client.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/client.py @@ -112,7 +112,7 @@ class MaintenanceClient(metaclass=MaintenanceClientMeta): """Unified Maintenance service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -437,7 +441,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -534,7 +538,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -630,7 +634,7 @@ def __init__( self._universe_domain = MaintenanceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1101,7 +1105,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1127,8 +1131,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1137,7 +1145,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1146,7 +1154,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1160,7 +1168,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1186,8 +1194,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1196,7 +1208,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1205,7 +1217,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/README.rst b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/README.rst index a0f65ecd2232..a76797a9d391 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/README.rst +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MaintenanceTransport` is the ABC for all transports. -- public child `MaintenanceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MaintenanceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMaintenanceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MaintenanceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MaintenanceTransport`` is the ABC for all transports. + +- public child ``MaintenanceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MaintenanceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMaintenanceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MaintenanceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/base.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/base.py index 8da0afcf87cb..4e2db731b948 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/base.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc.py index 3b3b29417850..92b0dc7fbdc0 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc_asyncio.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc_asyncio.py index 714c71e61581..36110267a483 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc_asyncio.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/rest.py b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/rest.py index 1eb42ef86fd0..a84b065d6758 100644 --- a/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/rest.py +++ b/packages/google-cloud-maintenance-api/google/cloud/maintenance_api_v1beta/services/maintenance/transports/rest.py @@ -375,6 +375,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MaintenanceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-maintenance-api/noxfile.py b/packages/google-cloud-maintenance-api/noxfile.py index b006a9baa359..e4a6cf4d80e0 100644 --- a/packages/google-cloud-maintenance-api/noxfile.py +++ b/packages/google-cloud-maintenance-api/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-maintenance-api/setup.py b/packages/google-cloud-maintenance-api/setup.py index 935bc8e2db99..0dd74b669e69 100644 --- a/packages/google-cloud-maintenance-api/setup.py +++ b/packages/google-cloud-maintenance-api/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-maintenance-api" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-maintenance-api/testing/constraints-3.7.txt b/packages/google-cloud-maintenance-api/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-maintenance-api/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-maintenance-api/testing/constraints-3.8.txt b/packages/google-cloud-maintenance-api/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-maintenance-api/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-maintenance-api/testing/constraints-3.9.txt b/packages/google-cloud-maintenance-api/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-maintenance-api/testing/constraints-3.9.txt +++ b/packages/google-cloud-maintenance-api/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1/test_maintenance.py b/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1/test_maintenance.py index b6a827cc0948..a5905f61da5a 100644 --- a/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1/test_maintenance.py +++ b/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1/test_maintenance.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MaintenanceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MaintenanceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MaintenanceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1245,11 +1249,13 @@ def test_maintenance_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3779,8 +3785,9 @@ def test_summarize_maintenances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3847,18 +3854,20 @@ def test_summarize_maintenances_rest_interceptors(null_interceptor): ) client = MaintenanceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MaintenanceRestInterceptor, "post_summarize_maintenances" - ) as post, mock.patch.object( - transports.MaintenanceRestInterceptor, - "post_summarize_maintenances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MaintenanceRestInterceptor, "pre_summarize_maintenances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MaintenanceRestInterceptor, "post_summarize_maintenances" + ) as post, + mock.patch.object( + transports.MaintenanceRestInterceptor, + "post_summarize_maintenances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MaintenanceRestInterceptor, "pre_summarize_maintenances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3916,8 +3925,9 @@ def test_list_resource_maintenances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3984,18 +3994,20 @@ def test_list_resource_maintenances_rest_interceptors(null_interceptor): ) client = MaintenanceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MaintenanceRestInterceptor, "post_list_resource_maintenances" - ) as post, mock.patch.object( - transports.MaintenanceRestInterceptor, - "post_list_resource_maintenances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MaintenanceRestInterceptor, "pre_list_resource_maintenances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MaintenanceRestInterceptor, "post_list_resource_maintenances" + ) as post, + mock.patch.object( + transports.MaintenanceRestInterceptor, + "post_list_resource_maintenances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MaintenanceRestInterceptor, "pre_list_resource_maintenances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4055,8 +4067,9 @@ def test_get_resource_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4129,18 +4142,20 @@ def test_get_resource_maintenance_rest_interceptors(null_interceptor): ) client = MaintenanceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MaintenanceRestInterceptor, "post_get_resource_maintenance" - ) as post, mock.patch.object( - transports.MaintenanceRestInterceptor, - "post_get_resource_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MaintenanceRestInterceptor, "pre_get_resource_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MaintenanceRestInterceptor, "post_get_resource_maintenance" + ) as post, + mock.patch.object( + transports.MaintenanceRestInterceptor, + "post_get_resource_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MaintenanceRestInterceptor, "pre_get_resource_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4198,8 +4213,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4258,8 +4274,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4437,11 +4454,14 @@ def test_maintenance_base_transport(): def test_maintenance_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.maintenance_api_v1.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.maintenance_api_v1.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MaintenanceTransport( @@ -4458,9 +4478,12 @@ def test_maintenance_base_transport_with_credentials_file(): def test_maintenance_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.maintenance_api_v1.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.maintenance_api_v1.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MaintenanceTransport() @@ -4532,11 +4555,12 @@ def test_maintenance_transport_auth_gdch_credentials(transport_class): def test_maintenance_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5102,6 +5126,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = MaintenanceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = MaintenanceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = MaintenanceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5243,6 +5301,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = MaintenanceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = MaintenanceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = MaintenanceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1beta/test_maintenance.py b/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1beta/test_maintenance.py index 28c361f37075..6702e00a6c00 100644 --- a/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1beta/test_maintenance.py +++ b/packages/google-cloud-maintenance-api/tests/unit/gapic/maintenance_api_v1beta/test_maintenance.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MaintenanceClient._get_default_mtls_endpoint(None) is None assert ( @@ -139,6 +140,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MaintenanceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MaintenanceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1245,11 +1249,13 @@ def test_maintenance_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3779,8 +3785,9 @@ def test_summarize_maintenances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3847,18 +3854,20 @@ def test_summarize_maintenances_rest_interceptors(null_interceptor): ) client = MaintenanceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MaintenanceRestInterceptor, "post_summarize_maintenances" - ) as post, mock.patch.object( - transports.MaintenanceRestInterceptor, - "post_summarize_maintenances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MaintenanceRestInterceptor, "pre_summarize_maintenances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MaintenanceRestInterceptor, "post_summarize_maintenances" + ) as post, + mock.patch.object( + transports.MaintenanceRestInterceptor, + "post_summarize_maintenances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MaintenanceRestInterceptor, "pre_summarize_maintenances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3916,8 +3925,9 @@ def test_list_resource_maintenances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3984,18 +3994,20 @@ def test_list_resource_maintenances_rest_interceptors(null_interceptor): ) client = MaintenanceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MaintenanceRestInterceptor, "post_list_resource_maintenances" - ) as post, mock.patch.object( - transports.MaintenanceRestInterceptor, - "post_list_resource_maintenances_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MaintenanceRestInterceptor, "pre_list_resource_maintenances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MaintenanceRestInterceptor, "post_list_resource_maintenances" + ) as post, + mock.patch.object( + transports.MaintenanceRestInterceptor, + "post_list_resource_maintenances_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MaintenanceRestInterceptor, "pre_list_resource_maintenances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4055,8 +4067,9 @@ def test_get_resource_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4129,18 +4142,20 @@ def test_get_resource_maintenance_rest_interceptors(null_interceptor): ) client = MaintenanceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MaintenanceRestInterceptor, "post_get_resource_maintenance" - ) as post, mock.patch.object( - transports.MaintenanceRestInterceptor, - "post_get_resource_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MaintenanceRestInterceptor, "pre_get_resource_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MaintenanceRestInterceptor, "post_get_resource_maintenance" + ) as post, + mock.patch.object( + transports.MaintenanceRestInterceptor, + "post_get_resource_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MaintenanceRestInterceptor, "pre_get_resource_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4198,8 +4213,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4258,8 +4274,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4437,11 +4454,14 @@ def test_maintenance_base_transport(): def test_maintenance_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.maintenance_api_v1beta.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.maintenance_api_v1beta.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MaintenanceTransport( @@ -4458,9 +4478,12 @@ def test_maintenance_base_transport_with_credentials_file(): def test_maintenance_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.maintenance_api_v1beta.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.maintenance_api_v1beta.services.maintenance.transports.MaintenanceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MaintenanceTransport() @@ -4532,11 +4555,12 @@ def test_maintenance_transport_auth_gdch_credentials(transport_class): def test_maintenance_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5102,6 +5126,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = MaintenanceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = MaintenanceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = MaintenanceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -5243,6 +5301,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = MaintenanceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = MaintenanceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = MaintenanceClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py index d99e18ef7992..88d47d826afb 100644 --- a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py +++ b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/async_client.py @@ -235,7 +235,7 @@ def transport(self) -> ManagedIdentitiesServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/client.py b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/client.py index e5644bc66330..1c6bd10e63fe 100644 --- a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/client.py +++ b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/client.py @@ -147,7 +147,7 @@ class ManagedIdentitiesServiceClient(metaclass=ManagedIdentitiesServiceClientMet """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -155,7 +155,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -165,6 +165,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -472,7 +476,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -571,7 +575,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -673,7 +677,7 @@ def __init__( self._universe_domain = ManagedIdentitiesServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/README.rst b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/README.rst index cb892ba1de73..2f8dbcbaf1a1 100644 --- a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/README.rst +++ b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ManagedIdentitiesServiceTransport` is the ABC for all transports. -- public child `ManagedIdentitiesServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ManagedIdentitiesServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseManagedIdentitiesServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ManagedIdentitiesServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ManagedIdentitiesServiceTransport`` is the ABC for all transports. + +- public child ``ManagedIdentitiesServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ManagedIdentitiesServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseManagedIdentitiesServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ManagedIdentitiesServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py index 182acada71b3..18af86f7acf9 100644 --- a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py +++ b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py @@ -81,6 +81,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -130,6 +134,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py index 468c3912d59d..c854b952e861 100644 --- a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py +++ b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -218,6 +218,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py index dd742a583149..b90260402f55 100644 --- a/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-managed-identities/google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -269,6 +269,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managed-identities/noxfile.py b/packages/google-cloud-managed-identities/noxfile.py index 264cf96073de..cc9d72280ecd 100644 --- a/packages/google-cloud-managed-identities/noxfile.py +++ b/packages/google-cloud-managed-identities/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-managed-identities/setup.py b/packages/google-cloud-managed-identities/setup.py index a95aee128665..3e4fbb2f29d7 100644 --- a/packages/google-cloud-managed-identities/setup.py +++ b/packages/google-cloud-managed-identities/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-managed-identities" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-managed-identities/testing/constraints-3.7.txt b/packages/google-cloud-managed-identities/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-managed-identities/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-managed-identities/testing/constraints-3.8.txt b/packages/google-cloud-managed-identities/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-managed-identities/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-managed-identities/testing/constraints-3.9.txt b/packages/google-cloud-managed-identities/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-managed-identities/testing/constraints-3.9.txt +++ b/packages/google-cloud-managed-identities/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-managed-identities/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py b/packages/google-cloud-managed-identities/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py index e63d9c7603f8..b6ac52b3e773 100644 --- a/packages/google-cloud-managed-identities/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py +++ b/packages/google-cloud-managed-identities/tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ManagedIdentitiesServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): ManagedIdentitiesServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ManagedIdentitiesServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1317,11 +1322,13 @@ def test_managed_identities_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5642,11 +5649,14 @@ def test_managed_identities_service_base_transport(): def test_managed_identities_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedIdentitiesServiceTransport( @@ -5663,9 +5673,12 @@ def test_managed_identities_service_base_transport_with_credentials_file(): def test_managed_identities_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.managedidentities_v1.services.managed_identities_service.transports.ManagedIdentitiesServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedIdentitiesServiceTransport() @@ -5738,11 +5751,12 @@ def test_managed_identities_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/async_client.py b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/async_client.py index 39fc4dc2d7a8..5585b1a6f41c 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/async_client.py +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/async_client.py @@ -277,7 +277,7 @@ def transport(self) -> ManagedSchemaRegistryTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4144,7 +4144,7 @@ async def sample_delete_schema_mode(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4170,8 +4170,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4180,7 +4184,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4188,7 +4192,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4199,7 +4203,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4225,8 +4229,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4235,7 +4243,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4243,7 +4251,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4254,7 +4262,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4284,8 +4292,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4294,7 +4306,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4302,7 +4314,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4310,7 +4322,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4339,8 +4351,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4349,7 +4365,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4357,7 +4373,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4365,7 +4381,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4391,8 +4407,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4401,7 +4421,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4409,7 +4429,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4420,7 +4440,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4446,8 +4466,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4456,7 +4480,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4464,7 +4488,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/client.py b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/client.py index bf4a8276b318..8516ca60c884 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/client.py +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/client.py @@ -171,7 +171,7 @@ class ManagedSchemaRegistryClient(metaclass=ManagedSchemaRegistryClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -179,7 +179,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -189,6 +189,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -638,7 +642,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -737,7 +741,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -837,7 +841,7 @@ def __init__( self._universe_domain = ManagedSchemaRegistryClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4623,7 +4627,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4649,8 +4653,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4659,7 +4667,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4668,7 +4676,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4682,7 +4690,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4708,8 +4716,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4718,7 +4730,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4727,7 +4739,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4741,7 +4753,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4771,8 +4783,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4781,7 +4797,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4789,7 +4805,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4797,7 +4813,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4826,8 +4842,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4836,7 +4856,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4844,7 +4864,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4852,7 +4872,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4878,8 +4898,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4888,7 +4912,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4897,7 +4921,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4911,7 +4935,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4937,8 +4961,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4947,7 +4975,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4956,7 +4984,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/README.rst b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/README.rst index b9178588809e..f8a6508b4f9b 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/README.rst +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ManagedSchemaRegistryTransport` is the ABC for all transports. -- public child `ManagedSchemaRegistryGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ManagedSchemaRegistryGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseManagedSchemaRegistryRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ManagedSchemaRegistryRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ManagedSchemaRegistryTransport`` is the ABC for all transports. + +- public child ``ManagedSchemaRegistryGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ManagedSchemaRegistryGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseManagedSchemaRegistryRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ManagedSchemaRegistryRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/base.py b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/base.py index b2259025e69b..ccf849f8f510 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/base.py +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/base.py @@ -90,6 +90,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -139,6 +143,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc.py b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc.py index 8a06ac2d797f..367d1591a1ba 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc.py +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc.py @@ -64,7 +64,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc_asyncio.py b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc_asyncio.py index 74e3cfe552d6..64a85d4e1457 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc_asyncio.py +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/grpc_asyncio.py @@ -70,7 +70,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -105,7 +105,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -296,6 +296,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/rest.py b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/rest.py index e93ea8af321f..d46395439742 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/rest.py +++ b/packages/google-cloud-managedkafka-schemaregistry/google/cloud/managedkafka_schemaregistry_v1/services/managed_schema_registry/transports/rest.py @@ -1870,6 +1870,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ManagedSchemaRegistryRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py index 3ae1cca68ad1..864c26844af1 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/noxfile.py +++ b/packages/google-cloud-managedkafka-schemaregistry/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-managedkafka-schemaregistry/setup.py b/packages/google-cloud-managedkafka-schemaregistry/setup.py index f0f01a057aac..b3a35065d711 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/setup.py +++ b/packages/google-cloud-managedkafka-schemaregistry/setup.py @@ -43,7 +43,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -51,7 +51,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-managedkafka-schemaregistry" @@ -83,8 +83,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -96,7 +94,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.7.txt b/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.8.txt b/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.9.txt b/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.9.txt +++ b/packages/google-cloud-managedkafka-schemaregistry/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-managedkafka-schemaregistry/tests/unit/gapic/managedkafka_schemaregistry_v1/test_managed_schema_registry.py b/packages/google-cloud-managedkafka-schemaregistry/tests/unit/gapic/managedkafka_schemaregistry_v1/test_managed_schema_registry.py index af9b4f9a75cb..223881acfefb 100644 --- a/packages/google-cloud-managedkafka-schemaregistry/tests/unit/gapic/managedkafka_schemaregistry_v1/test_managed_schema_registry.py +++ b/packages/google-cloud-managedkafka-schemaregistry/tests/unit/gapic/managedkafka_schemaregistry_v1/test_managed_schema_registry.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ManagedSchemaRegistryClient._get_default_mtls_endpoint(None) is None assert ( @@ -150,6 +151,10 @@ def test__get_default_mtls_endpoint(): ManagedSchemaRegistryClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ManagedSchemaRegistryClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1351,11 +1356,13 @@ def test_managed_schema_registry_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -17229,8 +17236,9 @@ def test_get_schema_registry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17297,18 +17305,20 @@ def test_get_schema_registry_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_registry" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_schema_registry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema_registry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_registry" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_schema_registry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema_registry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17366,8 +17376,9 @@ def test_list_schema_registries_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17427,18 +17438,22 @@ def test_list_schema_registries_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_schema_registries" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_schema_registries_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_schema_registries" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_schema_registries", + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_schema_registries_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "pre_list_schema_registries", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17496,8 +17511,9 @@ def test_create_schema_registry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17562,18 +17578,22 @@ def test_create_schema_registry_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_create_schema_registry" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_create_schema_registry_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_create_schema_registry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_create_schema_registry", + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_create_schema_registry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "pre_create_schema_registry", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17633,8 +17653,9 @@ def test_delete_schema_registry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17693,13 +17714,14 @@ def test_delete_schema_registry_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_schema_registry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "pre_delete_schema_registry", + ) as pre, + ): pre.assert_not_called() pb_message = schema_registry.DeleteSchemaRegistryRequest.pb( schema_registry.DeleteSchemaRegistryRequest() @@ -17744,8 +17766,9 @@ def test_get_context_rest_bad_request(request_type=schema_registry.GetContextReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17812,18 +17835,20 @@ def test_get_context_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_context" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_context_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_context" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_context" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_context_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_context" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17880,8 +17905,9 @@ def test_list_contexts_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17945,18 +17971,20 @@ def test_list_contexts_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_contexts" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_contexts_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_contexts" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_list_contexts" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_contexts_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_list_contexts" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18009,8 +18037,9 @@ def test_get_schema_rest_bad_request(request_type=schema_registry.GetSchemaReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18077,17 +18106,20 @@ def test_get_schema_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18142,8 +18174,9 @@ def test_get_raw_schema_rest_bad_request(request_type=schema_registry.GetSchemaR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18207,18 +18240,20 @@ def test_get_raw_schema_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_raw_schema" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_raw_schema_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_raw_schema" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_raw_schema" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_raw_schema_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_raw_schema" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18273,8 +18308,9 @@ def test_list_schema_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18338,18 +18374,20 @@ def test_list_schema_versions_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_schema_versions" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_schema_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_schema_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_list_schema_versions" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_schema_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_list_schema_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18404,8 +18442,9 @@ def test_list_schema_types_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18469,18 +18508,20 @@ def test_list_schema_types_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_schema_types" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_schema_types_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_schema_types" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_list_schema_types" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_schema_types_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_list_schema_types" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18535,8 +18576,9 @@ def test_list_subjects_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18600,18 +18642,20 @@ def test_list_subjects_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_subjects" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_subjects_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_subjects" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_list_subjects" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_subjects_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_list_subjects" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18666,8 +18710,9 @@ def test_list_subjects_by_schema_id_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18731,20 +18776,22 @@ def test_list_subjects_by_schema_id_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_subjects_by_schema_id", - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_subjects_by_schema_id_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "pre_list_subjects_by_schema_id", - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_subjects_by_schema_id", + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_subjects_by_schema_id_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "pre_list_subjects_by_schema_id", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18799,8 +18846,9 @@ def test_delete_subject_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -18864,18 +18912,20 @@ def test_delete_subject_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_delete_subject" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_delete_subject_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_subject" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_delete_subject" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_delete_subject_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_subject" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -18930,8 +18980,9 @@ def test_lookup_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19004,18 +19055,20 @@ def test_lookup_version_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_lookup_version" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_lookup_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_lookup_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_lookup_version" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_lookup_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_lookup_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19073,8 +19126,9 @@ def test_get_version_rest_bad_request(request_type=schema_registry.GetVersionReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19147,18 +19201,20 @@ def test_get_version_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_version" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_version" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19218,8 +19274,9 @@ def test_get_raw_schema_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19283,18 +19340,22 @@ def test_get_raw_schema_version_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_raw_schema_version" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_raw_schema_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_raw_schema_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_raw_schema_version", + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_raw_schema_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "pre_get_raw_schema_version", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19349,8 +19410,9 @@ def test_list_versions_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19414,18 +19476,20 @@ def test_list_versions_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_versions" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_versions_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_versions" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_list_versions" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_versions_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_list_versions" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19480,8 +19544,9 @@ def test_create_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19546,18 +19611,20 @@ def test_create_version_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_create_version" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_create_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_create_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_create_version" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_create_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_create_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19617,8 +19684,9 @@ def test_delete_version_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19682,18 +19750,20 @@ def test_delete_version_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_delete_version" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_delete_version_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_version" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_delete_version" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_delete_version_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_version" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19748,8 +19818,9 @@ def test_list_referenced_schemas_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19813,18 +19884,22 @@ def test_list_referenced_schemas_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_list_referenced_schemas" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_list_referenced_schemas_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_list_referenced_schemas" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_referenced_schemas", + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_list_referenced_schemas_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "pre_list_referenced_schemas", + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -19879,8 +19954,9 @@ def test_check_compatibility_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -19947,18 +20023,20 @@ def test_check_compatibility_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_check_compatibility" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_check_compatibility_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_check_compatibility" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_check_compatibility" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_check_compatibility_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_check_compatibility" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20018,8 +20096,9 @@ def test_get_schema_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20091,18 +20170,20 @@ def test_get_schema_config_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_config" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_schema_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_config" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_schema_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20162,8 +20243,9 @@ def test_update_schema_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20235,18 +20317,20 @@ def test_update_schema_config_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_update_schema_config" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_update_schema_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_update_schema_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_update_schema_config" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_update_schema_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_update_schema_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20306,8 +20390,9 @@ def test_delete_schema_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20379,18 +20464,20 @@ def test_delete_schema_config_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_delete_schema_config" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_delete_schema_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_schema_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_delete_schema_config" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_delete_schema_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_schema_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20450,8 +20537,9 @@ def test_get_schema_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20516,18 +20604,20 @@ def test_get_schema_mode_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_mode" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_get_schema_mode_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_get_schema_mode" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_get_schema_mode_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_get_schema_mode" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20587,8 +20677,9 @@ def test_update_schema_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20653,18 +20744,20 @@ def test_update_schema_mode_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_update_schema_mode" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_update_schema_mode_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_update_schema_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_update_schema_mode" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_update_schema_mode_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_update_schema_mode" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20724,8 +20817,9 @@ def test_delete_schema_mode_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -20790,18 +20884,20 @@ def test_delete_schema_mode_rest_interceptors(null_interceptor): ) client = ManagedSchemaRegistryClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "post_delete_schema_mode" - ) as post, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, - "post_delete_schema_mode_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_schema_mode" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "post_delete_schema_mode" + ) as post, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, + "post_delete_schema_mode_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedSchemaRegistryRestInterceptor, "pre_delete_schema_mode" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -20859,8 +20955,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -20919,8 +21016,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -20981,8 +21079,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21043,8 +21142,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21105,8 +21205,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21167,8 +21268,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -21878,11 +21980,14 @@ def test_managed_schema_registry_base_transport(): def test_managed_schema_registry_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.managedkafka_schemaregistry_v1.services.managed_schema_registry.transports.ManagedSchemaRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.managedkafka_schemaregistry_v1.services.managed_schema_registry.transports.ManagedSchemaRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedSchemaRegistryTransport( @@ -21899,9 +22004,12 @@ def test_managed_schema_registry_base_transport_with_credentials_file(): def test_managed_schema_registry_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.managedkafka_schemaregistry_v1.services.managed_schema_registry.transports.ManagedSchemaRegistryTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.managedkafka_schemaregistry_v1.services.managed_schema_registry.transports.ManagedSchemaRegistryTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedSchemaRegistryTransport() @@ -21975,11 +22083,12 @@ def test_managed_schema_registry_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -22807,6 +22916,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ManagedSchemaRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ManagedSchemaRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ManagedSchemaRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -22946,6 +23087,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ManagedSchemaRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ManagedSchemaRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ManagedSchemaRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23091,6 +23264,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ManagedSchemaRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ManagedSchemaRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ManagedSchemaRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23236,6 +23443,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ManagedSchemaRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ManagedSchemaRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ManagedSchemaRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23381,6 +23622,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ManagedSchemaRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ManagedSchemaRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ManagedSchemaRegistryClient( credentials=ga_credentials.AnonymousCredentials(), @@ -23524,6 +23799,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ManagedSchemaRegistryClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ManagedSchemaRegistryAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ManagedSchemaRegistryClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/async_client.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/async_client.py index fd0d0fc1497c..de79bb1afbb1 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/async_client.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/async_client.py @@ -203,7 +203,7 @@ def transport(self) -> ManagedKafkaTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2939,7 +2939,7 @@ async def sample_remove_acl_entry(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2965,8 +2965,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2975,7 +2979,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2983,7 +2987,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2994,7 +2998,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3020,8 +3024,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3030,7 +3038,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3038,7 +3046,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3049,7 +3057,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3079,8 +3087,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3089,7 +3101,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3097,7 +3109,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3105,7 +3117,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3134,8 +3146,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3144,7 +3160,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3152,7 +3168,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3160,7 +3176,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3186,8 +3202,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3196,7 +3216,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3204,7 +3224,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3215,7 +3235,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3241,8 +3261,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3251,7 +3275,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3259,7 +3283,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/client.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/client.py index ec7a37dff834..3b00a8d1b8f3 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/client.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/client.py @@ -119,7 +119,7 @@ class ManagedKafkaClient(metaclass=ManagedKafkaClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -562,7 +566,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -659,7 +663,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -755,7 +759,7 @@ def __init__( self._universe_domain = ManagedKafkaClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3428,7 +3432,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3454,8 +3458,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3464,7 +3472,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3473,7 +3481,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3487,7 +3495,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3513,8 +3521,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3523,7 +3535,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3532,7 +3544,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3546,7 +3558,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3576,8 +3588,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3586,7 +3602,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3594,7 +3610,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3602,7 +3618,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3631,8 +3647,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3641,7 +3661,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3649,7 +3669,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3657,7 +3677,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3683,8 +3703,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3693,7 +3717,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3702,7 +3726,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3716,7 +3740,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3742,8 +3766,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3752,7 +3780,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3761,7 +3789,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/README.rst b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/README.rst index 1935189fc7c4..874fee8c4611 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/README.rst +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ManagedKafkaTransport` is the ABC for all transports. -- public child `ManagedKafkaGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ManagedKafkaGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseManagedKafkaRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ManagedKafkaRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ManagedKafkaTransport`` is the ABC for all transports. + +- public child ``ManagedKafkaGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ManagedKafkaGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseManagedKafkaRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ManagedKafkaRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/base.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/base.py index 9a0a02ca53ad..3aa412a93edd 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/base.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc.py index d0da8f7427db..2fd4f06ffc97 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc_asyncio.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc_asyncio.py index 877971f9e40a..402f167ea85b 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc_asyncio.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/rest.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/rest.py index 002afcfc58b3..0185736ca797 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/rest.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka/transports/rest.py @@ -1338,6 +1338,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ManagedKafkaRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/async_client.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/async_client.py index 3902bed167e2..b7b663ea4670 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/async_client.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> ManagedKafkaConnectTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2066,7 +2066,7 @@ async def sample_stop_connector(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2092,8 +2092,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2102,7 +2106,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2110,7 +2114,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2121,7 +2125,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2147,8 +2151,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2157,7 +2165,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2165,7 +2173,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2176,7 +2184,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2206,8 +2214,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2216,7 +2228,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2224,7 +2236,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2232,7 +2244,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2261,8 +2273,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2271,7 +2287,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2279,7 +2295,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2287,7 +2303,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2313,8 +2329,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2323,7 +2343,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2331,7 +2351,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2342,7 +2362,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2368,8 +2388,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2378,7 +2402,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2386,7 +2410,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/client.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/client.py index ffe4c01a304e..01bac6670091 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/client.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/client.py @@ -119,7 +119,7 @@ class ManagedKafkaConnectClient(metaclass=ManagedKafkaConnectClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -490,7 +494,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -587,7 +591,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -687,7 +691,7 @@ def __init__( self._universe_domain = ManagedKafkaConnectClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2504,7 +2508,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2530,8 +2534,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2540,7 +2548,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2549,7 +2557,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2563,7 +2571,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2589,8 +2597,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2599,7 +2611,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2608,7 +2620,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2622,7 +2634,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2652,8 +2664,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2662,7 +2678,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2670,7 +2686,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2678,7 +2694,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2707,8 +2723,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2717,7 +2737,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2725,7 +2745,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2733,7 +2753,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2759,8 +2779,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2769,7 +2793,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2778,7 +2802,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2792,7 +2816,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2818,8 +2842,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2828,7 +2856,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2837,7 +2865,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/README.rst b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/README.rst index b28dcbf6a4ce..e362511a01fc 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/README.rst +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ManagedKafkaConnectTransport` is the ABC for all transports. -- public child `ManagedKafkaConnectGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ManagedKafkaConnectGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseManagedKafkaConnectRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ManagedKafkaConnectRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ManagedKafkaConnectTransport`` is the ABC for all transports. + +- public child ``ManagedKafkaConnectGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ManagedKafkaConnectGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseManagedKafkaConnectRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ManagedKafkaConnectRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/base.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/base.py index bb6af2a9f1c5..7efc1b49ae16 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/base.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc.py index 64c2d03de6da..6deaf811797c 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -188,6 +188,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc_asyncio.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc_asyncio.py index a71c4b70ad92..c3e8e0111ea6 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc_asyncio.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -239,6 +239,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/rest.py b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/rest.py index ea0781d7be2c..241e5a2ce459 100644 --- a/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/rest.py +++ b/packages/google-cloud-managedkafka/google/cloud/managedkafka_v1/services/managed_kafka_connect/transports/rest.py @@ -1071,6 +1071,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ManagedKafkaConnectRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-managedkafka/noxfile.py b/packages/google-cloud-managedkafka/noxfile.py index ae61584cf7cf..1312f6c38cab 100644 --- a/packages/google-cloud-managedkafka/noxfile.py +++ b/packages/google-cloud-managedkafka/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-managedkafka/setup.py b/packages/google-cloud-managedkafka/setup.py index 05d68dff933b..b8ed52a2643e 100644 --- a/packages/google-cloud-managedkafka/setup.py +++ b/packages/google-cloud-managedkafka/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-managedkafka" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-managedkafka/testing/constraints-3.7.txt b/packages/google-cloud-managedkafka/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-managedkafka/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-managedkafka/testing/constraints-3.8.txt b/packages/google-cloud-managedkafka/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-managedkafka/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-managedkafka/testing/constraints-3.9.txt b/packages/google-cloud-managedkafka/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-managedkafka/testing/constraints-3.9.txt +++ b/packages/google-cloud-managedkafka/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka.py b/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka.py index 040548691d24..f49c19c4241a 100644 --- a/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka.py +++ b/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka.py @@ -128,6 +128,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ManagedKafkaClient._get_default_mtls_endpoint(None) is None assert ( @@ -146,6 +147,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ManagedKafkaClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ManagedKafkaClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1266,11 +1271,13 @@ def test_managed_kafka_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -14571,8 +14578,9 @@ def test_list_clusters_rest_bad_request(request_type=managed_kafka.ListClustersR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14637,17 +14645,19 @@ def test_list_clusters_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_clusters" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_clusters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_list_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_clusters" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_clusters_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_list_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14700,8 +14710,9 @@ def test_get_cluster_rest_bad_request(request_type=managed_kafka.GetClusterReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14770,17 +14781,19 @@ def test_get_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_get_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_get_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -14833,8 +14846,9 @@ def test_create_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -14977,19 +14991,20 @@ def test_create_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_create_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_create_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_create_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_create_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_create_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_create_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15044,8 +15059,9 @@ def test_update_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15190,19 +15206,20 @@ def test_update_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_update_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_update_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15255,8 +15272,9 @@ def test_delete_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15313,19 +15331,20 @@ def test_delete_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_delete_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_delete_cluster_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_delete_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_delete_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_delete_cluster_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_delete_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15376,8 +15395,9 @@ def test_list_topics_rest_bad_request(request_type=managed_kafka.ListTopicsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15440,17 +15460,19 @@ def test_list_topics_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_topics" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_topics_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_list_topics" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_topics" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_topics_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_list_topics" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15505,8 +15527,9 @@ def test_get_topic_rest_bad_request(request_type=managed_kafka.GetTopicRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15575,17 +15598,19 @@ def test_get_topic_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_topic" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_topic_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_get_topic" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_topic" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_topic_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_get_topic" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15634,8 +15659,9 @@ def test_create_topic_rest_bad_request(request_type=managed_kafka.CreateTopicReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15775,17 +15801,19 @@ def test_create_topic_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_create_topic" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_create_topic_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_create_topic" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_create_topic" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_create_topic_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_create_topic" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -15840,8 +15868,9 @@ def test_update_topic_rest_bad_request(request_type=managed_kafka.UpdateTopicReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -15985,17 +16014,19 @@ def test_update_topic_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_topic" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_topic_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_update_topic" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_topic" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_topic_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_update_topic" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16048,8 +16079,9 @@ def test_delete_topic_rest_bad_request(request_type=managed_kafka.DeleteTopicReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16108,13 +16140,13 @@ def test_delete_topic_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_delete_topic" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_delete_topic" + ) as pre, + ): pre.assert_not_called() pb_message = managed_kafka.DeleteTopicRequest.pb( managed_kafka.DeleteTopicRequest() @@ -16159,8 +16191,9 @@ def test_list_consumer_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16223,18 +16256,20 @@ def test_list_consumer_groups_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_consumer_groups" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, - "post_list_consumer_groups_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_list_consumer_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_consumer_groups" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, + "post_list_consumer_groups_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_list_consumer_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16294,8 +16329,9 @@ def test_get_consumer_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16360,17 +16396,20 @@ def test_get_consumer_group_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_consumer_group" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_consumer_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_get_consumer_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_consumer_group" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, + "post_get_consumer_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_get_consumer_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16427,8 +16466,9 @@ def test_update_consumer_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16566,18 +16606,20 @@ def test_update_consumer_group_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_consumer_group" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, - "post_update_consumer_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_update_consumer_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_consumer_group" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, + "post_update_consumer_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_update_consumer_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16632,8 +16674,9 @@ def test_delete_consumer_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16692,13 +16735,13 @@ def test_delete_consumer_group_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_delete_consumer_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_delete_consumer_group" + ) as pre, + ): pre.assert_not_called() pb_message = managed_kafka.DeleteConsumerGroupRequest.pb( managed_kafka.DeleteConsumerGroupRequest() @@ -16741,8 +16784,9 @@ def test_list_acls_rest_bad_request(request_type=managed_kafka.ListAclsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16805,17 +16849,19 @@ def test_list_acls_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_acls" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_list_acls_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_list_acls" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_acls" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_list_acls_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_list_acls" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -16868,8 +16914,9 @@ def test_get_acl_rest_bad_request(request_type=managed_kafka.GetAclRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -16942,17 +16989,17 @@ def test_get_acl_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_acl" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_get_acl_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_get_acl" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_acl" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_get_acl_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.ManagedKafkaRestInterceptor, "pre_get_acl") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17001,8 +17048,9 @@ def test_create_acl_rest_bad_request(request_type=managed_kafka.CreateAclRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17155,17 +17203,19 @@ def test_create_acl_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_create_acl" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_create_acl_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_create_acl" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_create_acl" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_create_acl_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_create_acl" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17218,8 +17268,9 @@ def test_update_acl_rest_bad_request(request_type=managed_kafka.UpdateAclRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17376,17 +17427,19 @@ def test_update_acl_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_acl" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_update_acl_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_update_acl" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_acl" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_update_acl_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_update_acl" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17437,8 +17490,9 @@ def test_delete_acl_rest_bad_request(request_type=managed_kafka.DeleteAclRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17497,13 +17551,13 @@ def test_delete_acl_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_delete_acl" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_delete_acl" + ) as pre, + ): pre.assert_not_called() pb_message = managed_kafka.DeleteAclRequest.pb(managed_kafka.DeleteAclRequest()) transcode.return_value = { @@ -17546,8 +17600,9 @@ def test_add_acl_entry_rest_bad_request(request_type=managed_kafka.AddAclEntryRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17685,17 +17740,19 @@ def test_add_acl_entry_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_add_acl_entry" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_add_acl_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_add_acl_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_add_acl_entry" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_add_acl_entry_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_add_acl_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17752,8 +17809,9 @@ def test_remove_acl_entry_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -17890,17 +17948,20 @@ def test_remove_acl_entry_rest_interceptors(null_interceptor): ) client = ManagedKafkaClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_remove_acl_entry" - ) as post, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "post_remove_acl_entry_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaRestInterceptor, "pre_remove_acl_entry" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "post_remove_acl_entry" + ) as post, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, + "post_remove_acl_entry_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaRestInterceptor, "pre_remove_acl_entry" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -17958,8 +18019,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18018,8 +18080,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18080,8 +18143,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18142,8 +18206,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18204,8 +18269,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18266,8 +18332,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -18851,11 +18918,14 @@ def test_managed_kafka_base_transport(): def test_managed_kafka_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.managedkafka_v1.services.managed_kafka.transports.ManagedKafkaTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.managedkafka_v1.services.managed_kafka.transports.ManagedKafkaTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedKafkaTransport( @@ -18872,9 +18942,12 @@ def test_managed_kafka_base_transport_with_credentials_file(): def test_managed_kafka_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.managedkafka_v1.services.managed_kafka.transports.ManagedKafkaTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.managedkafka_v1.services.managed_kafka.transports.ManagedKafkaTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedKafkaTransport() @@ -18946,11 +19019,12 @@ def test_managed_kafka_transport_auth_gdch_credentials(transport_class): def test_managed_kafka_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -19742,6 +19816,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ManagedKafkaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ManagedKafkaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ManagedKafkaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -19881,6 +19987,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ManagedKafkaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ManagedKafkaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ManagedKafkaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20026,6 +20164,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ManagedKafkaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ManagedKafkaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ManagedKafkaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20171,6 +20343,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ManagedKafkaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ManagedKafkaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ManagedKafkaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20316,6 +20522,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ManagedKafkaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ManagedKafkaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ManagedKafkaClient( credentials=ga_credentials.AnonymousCredentials(), @@ -20457,6 +20697,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ManagedKafkaClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ManagedKafkaAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ManagedKafkaClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka_connect.py b/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka_connect.py index 9848f2ec57fa..de461597f228 100644 --- a/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka_connect.py +++ b/packages/google-cloud-managedkafka/tests/unit/gapic/managedkafka_v1/test_managed_kafka_connect.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ManagedKafkaConnectClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): ManagedKafkaConnectClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ManagedKafkaConnectClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1350,11 +1355,13 @@ def test_managed_kafka_connect_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -10341,8 +10348,9 @@ def test_list_connect_clusters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10409,18 +10417,20 @@ def test_list_connect_clusters_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_list_connect_clusters" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_list_connect_clusters_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_list_connect_clusters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_list_connect_clusters" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_list_connect_clusters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_list_connect_clusters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10480,8 +10490,9 @@ def test_get_connect_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10550,18 +10561,20 @@ def test_get_connect_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_get_connect_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_get_connect_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_get_connect_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_get_connect_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_get_connect_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_get_connect_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10614,8 +10627,9 @@ def test_create_connect_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10769,20 +10783,21 @@ def test_create_connect_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_create_connect_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_create_connect_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_create_connect_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_create_connect_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_create_connect_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_create_connect_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -10839,8 +10854,9 @@ def test_update_connect_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -10998,20 +11014,21 @@ def test_update_connect_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_update_connect_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_update_connect_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_update_connect_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_update_connect_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_update_connect_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_update_connect_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11066,8 +11083,9 @@ def test_delete_connect_cluster_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11126,20 +11144,21 @@ def test_delete_connect_cluster_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_delete_connect_cluster" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_delete_connect_cluster_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_delete_connect_cluster" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_delete_connect_cluster" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_delete_connect_cluster_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_delete_connect_cluster" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11194,8 +11213,9 @@ def test_list_connectors_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11260,18 +11280,20 @@ def test_list_connectors_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_list_connectors" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_list_connectors_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_list_connectors" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_list_connectors" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_list_connectors_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_list_connectors" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11331,8 +11353,9 @@ def test_get_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11399,18 +11422,20 @@ def test_get_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_get_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_get_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_get_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_get_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_get_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_get_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11465,8 +11490,9 @@ def test_create_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11609,18 +11635,20 @@ def test_create_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_create_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_create_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_create_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_create_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_create_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_create_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11677,8 +11705,9 @@ def test_update_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11823,18 +11852,20 @@ def test_update_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_update_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_update_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_update_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_update_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_update_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_update_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -11889,8 +11920,9 @@ def test_delete_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -11949,13 +11981,13 @@ def test_delete_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_delete_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_delete_connector" + ) as pre, + ): pre.assert_not_called() pb_message = managed_kafka_connect.DeleteConnectorRequest.pb( managed_kafka_connect.DeleteConnectorRequest() @@ -12002,8 +12034,9 @@ def test_pause_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12065,18 +12098,20 @@ def test_pause_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_pause_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_pause_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_pause_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_pause_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_pause_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_pause_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12136,8 +12171,9 @@ def test_resume_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12199,18 +12235,20 @@ def test_resume_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_resume_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_resume_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_resume_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_resume_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_resume_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_resume_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12270,8 +12308,9 @@ def test_restart_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12333,18 +12372,20 @@ def test_restart_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_restart_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_restart_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_restart_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_restart_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_restart_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_restart_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12404,8 +12445,9 @@ def test_stop_connector_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -12467,18 +12509,20 @@ def test_stop_connector_rest_interceptors(null_interceptor): ) client = ManagedKafkaConnectClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "post_stop_connector" - ) as post, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, - "post_stop_connector_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ManagedKafkaConnectRestInterceptor, "pre_stop_connector" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "post_stop_connector" + ) as post, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, + "post_stop_connector_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ManagedKafkaConnectRestInterceptor, "pre_stop_connector" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -12536,8 +12580,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12596,8 +12641,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12658,8 +12704,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12720,8 +12767,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12782,8 +12830,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -12844,8 +12893,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -13286,11 +13336,14 @@ def test_managed_kafka_connect_base_transport(): def test_managed_kafka_connect_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.managedkafka_v1.services.managed_kafka_connect.transports.ManagedKafkaConnectTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.managedkafka_v1.services.managed_kafka_connect.transports.ManagedKafkaConnectTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedKafkaConnectTransport( @@ -13307,9 +13360,12 @@ def test_managed_kafka_connect_base_transport_with_credentials_file(): def test_managed_kafka_connect_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.managedkafka_v1.services.managed_kafka_connect.transports.ManagedKafkaConnectTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.managedkafka_v1.services.managed_kafka_connect.transports.ManagedKafkaConnectTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ManagedKafkaConnectTransport() @@ -13381,11 +13437,12 @@ def test_managed_kafka_connect_transport_auth_gdch_credentials(transport_class): def test_managed_kafka_connect_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -14084,6 +14141,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = ManagedKafkaConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = ManagedKafkaConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = ManagedKafkaConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14223,6 +14312,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = ManagedKafkaConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ManagedKafkaConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = ManagedKafkaConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14368,6 +14489,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = ManagedKafkaConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ManagedKafkaConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = ManagedKafkaConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14513,6 +14668,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = ManagedKafkaConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ManagedKafkaConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = ManagedKafkaConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14658,6 +14847,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ManagedKafkaConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ManagedKafkaConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ManagedKafkaConnectClient( credentials=ga_credentials.AnonymousCredentials(), @@ -14801,6 +15024,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ManagedKafkaConnectClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ManagedKafkaConnectAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ManagedKafkaConnectClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py index 7260915c5a43..b83f5bee516e 100644 --- a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py +++ b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> SpeechTranslationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py index 646cb73ce351..280cc5dfba7a 100644 --- a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py +++ b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py @@ -110,7 +110,7 @@ class SpeechTranslationServiceClient(metaclass=SpeechTranslationServiceClientMet """Provides translation from/to media types.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -118,7 +118,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -128,6 +128,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -413,7 +417,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -614,7 +618,7 @@ def __init__( self._universe_domain = SpeechTranslationServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/README.rst b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/README.rst index 81efa12dedd5..feb4209351d5 100644 --- a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/README.rst +++ b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SpeechTranslationServiceTransport` is the ABC for all transports. -- public child `SpeechTranslationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SpeechTranslationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSpeechTranslationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SpeechTranslationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SpeechTranslationServiceTransport`` is the ABC for all transports. + +- public child ``SpeechTranslationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SpeechTranslationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSpeechTranslationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SpeechTranslationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py index 65e0dbacee35..9c9f8cd526fa 100644 --- a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py +++ b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py @@ -80,6 +80,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -129,6 +133,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc.py b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc.py index aacdc1088881..778661b53de6 100644 --- a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc.py +++ b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -184,6 +184,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py index d6431d0e5dec..719204078474 100644 --- a/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-media-translation/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -235,6 +235,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-media-translation/noxfile.py b/packages/google-cloud-media-translation/noxfile.py index c6634da420b2..8b0f19364254 100644 --- a/packages/google-cloud-media-translation/noxfile.py +++ b/packages/google-cloud-media-translation/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-media-translation/setup.py b/packages/google-cloud-media-translation/setup.py index e2a64aa8ff92..028fcc777df4 100644 --- a/packages/google-cloud-media-translation/setup.py +++ b/packages/google-cloud-media-translation/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-media-translation" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-media-translation/testing/constraints-3.7.txt b/packages/google-cloud-media-translation/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-media-translation/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-media-translation/testing/constraints-3.8.txt b/packages/google-cloud-media-translation/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-media-translation/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-media-translation/testing/constraints-3.9.txt b/packages/google-cloud-media-translation/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-media-translation/testing/constraints-3.9.txt +++ b/packages/google-cloud-media-translation/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-media-translation/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py b/packages/google-cloud-media-translation/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py index f5a01055fa51..4ebdec8b825a 100644 --- a/packages/google-cloud-media-translation/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py +++ b/packages/google-cloud-media-translation/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py @@ -116,6 +116,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SpeechTranslationServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): SpeechTranslationServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SpeechTranslationServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1309,11 +1314,13 @@ def test_speech_translation_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1664,11 +1671,14 @@ def test_speech_translation_service_base_transport(): def test_speech_translation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.SpeechTranslationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.SpeechTranslationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpeechTranslationServiceTransport( @@ -1685,9 +1695,12 @@ def test_speech_translation_service_base_transport_with_credentials_file(): def test_speech_translation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.SpeechTranslationServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.SpeechTranslationServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpeechTranslationServiceTransport() @@ -1760,11 +1773,12 @@ def test_speech_translation_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-memcache/README.rst b/packages/google-cloud-memcache/README.rst index 86d08b630b4a..bb2dfc49402f 100644 --- a/packages/google-cloud-memcache/README.rst +++ b/packages/google-cloud-memcache/README.rst @@ -14,9 +14,9 @@ Python Client for Cloud Memorystore for Memcached :target: https://pypi.org/project/google-cloud-memcache/ .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-memcache.svg :target: https://pypi.org/project/google-cloud-memcache/ -.. _Cloud Memorystore for Memcached: cloud.google.com/memorystore/docs/memcached/ +.. _Cloud Memorystore for Memcached: https://cloud.google.com/memorystore/docs/memcached/ .. _Client Library Documentation: https://cloud.google.com/python/docs/reference/memcache/latest/summary_overview -.. _Product Documentation: cloud.google.com/memorystore/docs/memcached/ +.. _Product Documentation: https://cloud.google.com/memorystore/docs/memcached/ Quick Start ----------- @@ -30,7 +30,7 @@ In order to use this library, you first need to go through the following steps: .. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project .. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Enable the Cloud Memorystore for Memcached.: cloud.google.com/memorystore/docs/memcached/ +.. _Enable the Cloud Memorystore for Memcached.: https://cloud.google.com/memorystore/docs/memcached/ .. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html Installation @@ -104,7 +104,7 @@ Next Steps - View this `README`_ to see the full list of Cloud APIs that we cover. -.. _Cloud Memorystore for Memcached Product documentation: cloud.google.com/memorystore/docs/memcached/ +.. _Cloud Memorystore for Memcached Product documentation: https://cloud.google.com/memorystore/docs/memcached/ .. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst Logging diff --git a/packages/google-cloud-memcache/docs/README.rst b/packages/google-cloud-memcache/docs/README.rst index 86d08b630b4a..bb2dfc49402f 100644 --- a/packages/google-cloud-memcache/docs/README.rst +++ b/packages/google-cloud-memcache/docs/README.rst @@ -14,9 +14,9 @@ Python Client for Cloud Memorystore for Memcached :target: https://pypi.org/project/google-cloud-memcache/ .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-memcache.svg :target: https://pypi.org/project/google-cloud-memcache/ -.. _Cloud Memorystore for Memcached: cloud.google.com/memorystore/docs/memcached/ +.. _Cloud Memorystore for Memcached: https://cloud.google.com/memorystore/docs/memcached/ .. _Client Library Documentation: https://cloud.google.com/python/docs/reference/memcache/latest/summary_overview -.. _Product Documentation: cloud.google.com/memorystore/docs/memcached/ +.. _Product Documentation: https://cloud.google.com/memorystore/docs/memcached/ Quick Start ----------- @@ -30,7 +30,7 @@ In order to use this library, you first need to go through the following steps: .. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project .. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Enable the Cloud Memorystore for Memcached.: cloud.google.com/memorystore/docs/memcached/ +.. _Enable the Cloud Memorystore for Memcached.: https://cloud.google.com/memorystore/docs/memcached/ .. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html Installation @@ -104,7 +104,7 @@ Next Steps - View this `README`_ to see the full list of Cloud APIs that we cover. -.. _Cloud Memorystore for Memcached Product documentation: cloud.google.com/memorystore/docs/memcached/ +.. _Cloud Memorystore for Memcached Product documentation: https://cloud.google.com/memorystore/docs/memcached/ .. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst Logging diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/async_client.py b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/async_client.py index 49800206b897..5eb73893edc7 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/async_client.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> CloudMemcacheTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1459,7 +1459,7 @@ async def sample_reschedule_maintenance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1485,8 +1485,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1495,7 +1499,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1503,7 +1507,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1514,7 +1518,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1540,8 +1544,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1550,7 +1558,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1558,7 +1566,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1569,7 +1577,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1599,8 +1607,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1609,7 +1621,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1617,7 +1629,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1625,7 +1637,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1654,8 +1666,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1664,7 +1680,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1672,7 +1688,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1680,7 +1696,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1706,8 +1722,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1716,7 +1736,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1724,7 +1744,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1735,7 +1755,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1761,8 +1781,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1771,7 +1795,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1779,7 +1803,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/client.py b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/client.py index 69230ce5de43..2034411a9ab5 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/client.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/client.py @@ -136,7 +136,7 @@ class CloudMemcacheClient(metaclass=CloudMemcacheClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -144,7 +144,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -154,6 +154,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -654,7 +658,7 @@ def __init__( self._universe_domain = CloudMemcacheClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1878,7 +1882,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1904,8 +1908,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1914,7 +1922,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1923,7 +1931,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1937,7 +1945,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1963,8 +1971,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1973,7 +1985,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1982,7 +1994,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1996,7 +2008,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2026,8 +2038,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2036,7 +2052,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2044,7 +2060,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2052,7 +2068,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2081,8 +2097,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2091,7 +2111,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2099,7 +2119,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2107,7 +2127,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2133,8 +2153,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2143,7 +2167,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2152,7 +2176,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2166,7 +2190,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2192,8 +2216,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2202,7 +2230,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2211,7 +2239,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/README.rst b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/README.rst index a5292a79f793..09abf314a281 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/README.rst +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudMemcacheTransport` is the ABC for all transports. -- public child `CloudMemcacheGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudMemcacheGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudMemcacheRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudMemcacheRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudMemcacheTransport`` is the ABC for all transports. + +- public child ``CloudMemcacheGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudMemcacheGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudMemcacheRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudMemcacheRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/base.py b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/base.py index 1d06e3d2caaa..65d3bd0166cc 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/base.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py index 9ae6307a18dc..dcaad20f56eb 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -204,6 +204,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py index 6aaa3bb7ae04..64721463e5fb 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -255,6 +255,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/rest.py b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/rest.py index c3883dc15e7d..9abd4792a700 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/rest.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1/services/cloud_memcache/transports/rest.py @@ -762,6 +762,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudMemcacheRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py index 6d573110c7fe..b75f0c06a668 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/async_client.py @@ -212,7 +212,7 @@ def transport(self) -> CloudMemcacheTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1615,7 +1615,7 @@ async def sample_reschedule_maintenance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1641,8 +1641,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1651,7 +1655,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1659,7 +1663,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1670,7 +1674,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1696,8 +1700,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1706,7 +1714,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1714,7 +1722,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1725,7 +1733,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1755,8 +1763,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1765,7 +1777,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1773,7 +1785,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1781,7 +1793,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1810,8 +1822,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1820,7 +1836,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1828,7 +1844,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1836,7 +1852,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1862,8 +1878,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1872,7 +1892,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1880,7 +1900,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1891,7 +1911,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1917,8 +1937,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1927,7 +1951,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1935,7 +1959,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py index 8fdf9b7bdfc9..05ac74edf4f6 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/client.py @@ -136,7 +136,7 @@ class CloudMemcacheClient(metaclass=CloudMemcacheClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -144,7 +144,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -154,6 +154,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -461,7 +465,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -654,7 +658,7 @@ def __init__( self._universe_domain = CloudMemcacheClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2031,7 +2035,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2057,8 +2061,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2067,7 +2075,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2076,7 +2084,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2090,7 +2098,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2116,8 +2124,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2126,7 +2138,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2135,7 +2147,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2149,7 +2161,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2179,8 +2191,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2189,7 +2205,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2197,7 +2213,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2205,7 +2221,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2234,8 +2250,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2244,7 +2264,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2252,7 +2272,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2260,7 +2280,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2286,8 +2306,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2296,7 +2320,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2305,7 +2329,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2319,7 +2343,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2345,8 +2369,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2355,7 +2383,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2364,7 +2392,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/README.rst b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/README.rst index a5292a79f793..09abf314a281 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/README.rst +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CloudMemcacheTransport` is the ABC for all transports. -- public child `CloudMemcacheGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CloudMemcacheGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCloudMemcacheRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CloudMemcacheRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CloudMemcacheTransport`` is the ABC for all transports. + +- public child ``CloudMemcacheGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CloudMemcacheGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCloudMemcacheRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CloudMemcacheRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py index 04c1892deced..c37204c5fc2c 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py index 2aca9a2b215b..9286209b8255 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -204,6 +204,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py index 3481da01e6ae..180932ff994a 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -255,6 +255,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/rest.py b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/rest.py index 1e9246944532..30d3136b28ab 100644 --- a/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/rest.py +++ b/packages/google-cloud-memcache/google/cloud/memcache_v1beta2/services/cloud_memcache/transports/rest.py @@ -819,6 +819,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[CloudMemcacheRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-memcache/noxfile.py b/packages/google-cloud-memcache/noxfile.py index e480f1dde933..6acb02c6a66d 100644 --- a/packages/google-cloud-memcache/noxfile.py +++ b/packages/google-cloud-memcache/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-memcache/setup.py b/packages/google-cloud-memcache/setup.py index ae6ea7885d2f..fb28944dcb0d 100644 --- a/packages/google-cloud-memcache/setup.py +++ b/packages/google-cloud-memcache/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-memcache" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-memcache/testing/constraints-3.7.txt b/packages/google-cloud-memcache/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-memcache/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-memcache/testing/constraints-3.8.txt b/packages/google-cloud-memcache/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-memcache/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-memcache/testing/constraints-3.9.txt b/packages/google-cloud-memcache/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-memcache/testing/constraints-3.9.txt +++ b/packages/google-cloud-memcache/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1/test_cloud_memcache.py b/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1/test_cloud_memcache.py index 5b1cb2d2461e..e83e75bf74cc 100644 --- a/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1/test_cloud_memcache.py +++ b/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1/test_cloud_memcache.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudMemcacheClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): assert ( CloudMemcacheClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudMemcacheClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1288,11 +1293,13 @@ def test_cloud_memcache_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6396,8 +6403,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6462,17 +6470,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6528,8 +6538,9 @@ def test_get_instance_rest_bad_request(request_type=cloud_memcache.GetInstanceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6608,17 +6619,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6671,8 +6684,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6845,19 +6859,21 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_create_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6912,8 +6928,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7088,19 +7105,21 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_update_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7153,8 +7172,9 @@ def test_update_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7211,19 +7231,21 @@ def test_update_parameters_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_parameters" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_parameters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_update_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_update_parameters" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_update_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_update_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7276,8 +7298,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7334,19 +7357,21 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_delete_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7399,8 +7424,9 @@ def test_apply_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7457,19 +7483,21 @@ def test_apply_parameters_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_apply_parameters" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_apply_parameters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_apply_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_apply_parameters" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_apply_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_apply_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7522,8 +7550,9 @@ def test_reschedule_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7580,20 +7609,21 @@ def test_reschedule_maintenance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_reschedule_maintenance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, - "post_reschedule_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_reschedule_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_reschedule_maintenance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_reschedule_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_reschedule_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7646,8 +7676,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7706,8 +7737,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7768,8 +7800,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7830,8 +7863,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7892,8 +7926,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -7954,8 +7989,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8262,11 +8298,14 @@ def test_cloud_memcache_base_transport(): def test_cloud_memcache_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport( @@ -8283,9 +8322,12 @@ def test_cloud_memcache_base_transport_with_credentials_file(): def test_cloud_memcache_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.memcache_v1.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport() @@ -8357,11 +8399,12 @@ def test_cloud_memcache_transport_auth_gdch_credentials(transport_class): def test_cloud_memcache_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -8977,6 +9020,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9116,6 +9191,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9261,6 +9368,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9406,6 +9547,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9551,6 +9726,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9692,6 +9901,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py b/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py index 2e694f2c6f15..e78dd7977ad5 100644 --- a/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py +++ b/packages/google-cloud-memcache/tests/unit/gapic/memcache_v1beta2/test_cloud_memcache.py @@ -131,6 +131,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudMemcacheClient._get_default_mtls_endpoint(None) is None assert ( @@ -152,6 +153,10 @@ def test__get_default_mtls_endpoint(): assert ( CloudMemcacheClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + CloudMemcacheClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1288,11 +1293,13 @@ def test_cloud_memcache_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -7011,8 +7018,9 @@ def test_list_instances_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7077,17 +7085,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7143,8 +7153,9 @@ def test_get_instance_rest_bad_request(request_type=cloud_memcache.GetInstanceRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7225,17 +7236,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7288,8 +7301,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7464,19 +7478,21 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_create_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7531,8 +7547,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7709,19 +7726,21 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_update_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7774,8 +7793,9 @@ def test_update_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7832,19 +7852,21 @@ def test_update_parameters_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_parameters" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_update_parameters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_update_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_update_parameters" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_update_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_update_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7897,8 +7919,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7955,19 +7978,21 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_delete_instance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8020,8 +8045,9 @@ def test_apply_parameters_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8078,19 +8104,21 @@ def test_apply_parameters_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_apply_parameters" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_apply_parameters_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_apply_parameters" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_apply_parameters" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_apply_parameters_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_apply_parameters" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8143,8 +8171,9 @@ def test_apply_software_update_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8201,20 +8230,21 @@ def test_apply_software_update_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_apply_software_update" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, - "post_apply_software_update_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_apply_software_update" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_apply_software_update" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_apply_software_update_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_apply_software_update" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8267,8 +8297,9 @@ def test_reschedule_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -8325,20 +8356,21 @@ def test_reschedule_maintenance_rest_interceptors(null_interceptor): ) client = CloudMemcacheClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.CloudMemcacheRestInterceptor, "post_reschedule_maintenance" - ) as post, mock.patch.object( - transports.CloudMemcacheRestInterceptor, - "post_reschedule_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.CloudMemcacheRestInterceptor, "pre_reschedule_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "post_reschedule_maintenance" + ) as post, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, + "post_reschedule_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.CloudMemcacheRestInterceptor, "pre_reschedule_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -8391,8 +8423,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8451,8 +8484,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8513,8 +8547,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8575,8 +8610,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8637,8 +8673,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8699,8 +8736,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -9030,11 +9068,14 @@ def test_cloud_memcache_base_transport(): def test_cloud_memcache_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport( @@ -9051,9 +9092,12 @@ def test_cloud_memcache_base_transport_with_credentials_file(): def test_cloud_memcache_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.memcache_v1beta2.services.cloud_memcache.transports.CloudMemcacheTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.CloudMemcacheTransport() @@ -9125,11 +9169,12 @@ def test_cloud_memcache_transport_auth_gdch_credentials(transport_class): def test_cloud_memcache_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9748,6 +9793,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9887,6 +9964,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10032,6 +10141,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10177,6 +10320,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10322,6 +10499,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), @@ -10463,6 +10674,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = CloudMemcacheClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudMemcacheAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = CloudMemcacheClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/client.py b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/client.py index fc9ee19c65e5..83d818a72907 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/client.py +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/client.py @@ -113,7 +113,7 @@ class MemorystoreClient(metaclass=MemorystoreClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -619,7 +623,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -716,7 +720,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -812,7 +816,7 @@ def __init__( self._universe_domain = MemorystoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2654,7 +2658,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2680,8 +2684,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2690,7 +2698,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2699,7 +2707,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2713,7 +2721,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2739,8 +2747,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2749,7 +2761,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2758,7 +2770,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2772,7 +2784,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2802,8 +2814,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2812,7 +2828,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2820,7 +2836,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2828,7 +2844,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2857,8 +2873,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2867,7 +2887,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2875,7 +2895,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2883,7 +2903,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2909,8 +2929,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2919,7 +2943,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2928,7 +2952,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2942,7 +2966,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2968,8 +2992,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2978,7 +3006,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2987,7 +3015,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/README.rst b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/README.rst index 1ed25b9404df..c23c5b31c8a4 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/README.rst +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MemorystoreTransport` is the ABC for all transports. -- public child `MemorystoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MemorystoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMemorystoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MemorystoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MemorystoreTransport`` is the ABC for all transports. + +- public child ``MemorystoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MemorystoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMemorystoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MemorystoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/base.py b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/base.py index f0502cefbd1e..a98dbe683e1a 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/base.py +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/rest.py b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/rest.py index 87ed546469c5..b7c17c06097b 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/rest.py +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1/services/memorystore/transports/rest.py @@ -1079,6 +1079,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MemorystoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/client.py b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/client.py index 6afa4a8d5f54..c6088b577e7d 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/client.py +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/client.py @@ -113,7 +113,7 @@ class MemorystoreClient(metaclass=MemorystoreClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -523,7 +527,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -620,7 +624,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -716,7 +720,7 @@ def __init__( self._universe_domain = MemorystoreClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1593,7 +1597,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1619,8 +1623,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1629,7 +1637,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1638,7 +1646,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1652,7 +1660,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1678,8 +1686,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1688,7 +1700,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1697,7 +1709,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1711,7 +1723,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1741,8 +1753,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1751,7 +1767,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1759,7 +1775,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1767,7 +1783,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1796,8 +1812,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1806,7 +1826,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1814,7 +1834,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1822,7 +1842,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1848,8 +1868,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1858,7 +1882,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1867,7 +1891,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1881,7 +1905,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1907,8 +1931,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1917,7 +1945,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1926,7 +1954,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/README.rst b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/README.rst index 1ed25b9404df..c23c5b31c8a4 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/README.rst +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MemorystoreTransport` is the ABC for all transports. -- public child `MemorystoreGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MemorystoreGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMemorystoreRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MemorystoreRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MemorystoreTransport`` is the ABC for all transports. + +- public child ``MemorystoreGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MemorystoreGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMemorystoreRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MemorystoreRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/base.py b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/base.py index 72561d80a33f..4f568a208d4e 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/base.py +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/rest.py b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/rest.py index 7f96a4a1c023..2732c4a9eec0 100644 --- a/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/rest.py +++ b/packages/google-cloud-memorystore/google/cloud/memorystore_v1beta/services/memorystore/transports/rest.py @@ -630,6 +630,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MemorystoreRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-memorystore/noxfile.py b/packages/google-cloud-memorystore/noxfile.py index aa710d853ac0..b7a1d3a991fc 100644 --- a/packages/google-cloud-memorystore/noxfile.py +++ b/packages/google-cloud-memorystore/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-memorystore/setup.py b/packages/google-cloud-memorystore/setup.py index f761df77306b..8378801292ba 100644 --- a/packages/google-cloud-memorystore/setup.py +++ b/packages/google-cloud-memorystore/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-memorystore" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-memorystore/testing/constraints-3.7.txt b/packages/google-cloud-memorystore/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-memorystore/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-memorystore/testing/constraints-3.8.txt b/packages/google-cloud-memorystore/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-memorystore/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-memorystore/testing/constraints-3.9.txt b/packages/google-cloud-memorystore/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-memorystore/testing/constraints-3.9.txt +++ b/packages/google-cloud-memorystore/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1/test_memorystore.py b/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1/test_memorystore.py index 3d6b9218aecb..fec251b6db5c 100644 --- a/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1/test_memorystore.py +++ b/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1/test_memorystore.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MemorystoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MemorystoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MemorystoreClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -3999,8 +4003,9 @@ def test_list_instances_rest_bad_request(request_type=memorystore.ListInstancesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4065,17 +4070,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4128,8 +4135,9 @@ def test_get_instance_rest_bad_request(request_type=memorystore.GetInstanceReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4244,17 +4252,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4305,8 +4315,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4551,19 +4562,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4618,8 +4630,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4866,19 +4879,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4931,8 +4945,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4989,19 +5004,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5054,8 +5070,9 @@ def test_get_certificate_authority_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5118,18 +5135,20 @@ def test_get_certificate_authority_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_certificate_authority" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, - "post_get_certificate_authority_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_get_certificate_authority" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_certificate_authority" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, + "post_get_certificate_authority_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_get_certificate_authority" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5184,8 +5203,9 @@ def test_reschedule_maintenance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5242,20 +5262,21 @@ def test_reschedule_maintenance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_reschedule_maintenance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, - "post_reschedule_maintenance_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_reschedule_maintenance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_reschedule_maintenance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, + "post_reschedule_maintenance_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_reschedule_maintenance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5308,8 +5329,9 @@ def test_list_backup_collections_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5374,18 +5396,20 @@ def test_list_backup_collections_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_backup_collections" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, - "post_list_backup_collections_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_list_backup_collections" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_backup_collections" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, + "post_list_backup_collections_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_list_backup_collections" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5445,8 +5469,9 @@ def test_get_backup_collection_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5523,18 +5548,20 @@ def test_get_backup_collection_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_backup_collection" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, - "post_get_backup_collection_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_get_backup_collection" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_backup_collection" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, + "post_get_backup_collection_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_get_backup_collection" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5589,8 +5616,9 @@ def test_list_backups_rest_bad_request(request_type=memorystore.ListBackupsReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5657,17 +5685,19 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_list_backups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5720,8 +5750,9 @@ def test_get_backup_rest_bad_request(request_type=memorystore.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5806,17 +5837,19 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_backup" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_get_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5867,8 +5900,9 @@ def test_delete_backup_rest_bad_request(request_type=memorystore.DeleteBackupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5927,19 +5961,20 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_delete_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5992,8 +6027,9 @@ def test_export_backup_rest_bad_request(request_type=memorystore.ExportBackupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6052,19 +6088,20 @@ def test_export_backup_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_export_backup" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_export_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_export_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_export_backup" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_export_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_export_backup" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6117,8 +6154,9 @@ def test_backup_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6175,19 +6213,20 @@ def test_backup_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_backup_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_backup_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_backup_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_backup_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_backup_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_backup_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6240,8 +6279,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6300,8 +6340,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6362,8 +6403,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6424,8 +6466,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6486,8 +6529,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6548,8 +6592,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -6975,11 +7020,14 @@ def test_memorystore_base_transport(): def test_memorystore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.memorystore_v1.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.memorystore_v1.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MemorystoreTransport( @@ -6996,9 +7044,12 @@ def test_memorystore_base_transport_with_credentials_file(): def test_memorystore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.memorystore_v1.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.memorystore_v1.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MemorystoreTransport() diff --git a/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1beta/test_memorystore.py b/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1beta/test_memorystore.py index 0ac5edbe8118..683ac15482af 100644 --- a/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1beta/test_memorystore.py +++ b/packages/google-cloud-memorystore/tests/unit/gapic/memorystore_v1beta/test_memorystore.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MemorystoreClient._get_default_mtls_endpoint(None) is None assert ( @@ -145,6 +146,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert MemorystoreClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + MemorystoreClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -2432,8 +2436,9 @@ def test_list_instances_rest_bad_request(request_type=memorystore.ListInstancesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2498,17 +2503,19 @@ def test_list_instances_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_instances" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_list_instances_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_list_instances" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_instances" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_list_instances_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_list_instances" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2561,8 +2568,9 @@ def test_get_instance_rest_bad_request(request_type=memorystore.GetInstanceReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2651,17 +2659,19 @@ def test_get_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_get_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_get_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2712,8 +2722,9 @@ def test_create_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -2899,19 +2910,20 @@ def test_create_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_create_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_create_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_create_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_create_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_create_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_create_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2966,8 +2978,9 @@ def test_update_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3155,19 +3168,20 @@ def test_update_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_update_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_update_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_update_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_update_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_update_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_update_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3220,8 +3234,9 @@ def test_delete_instance_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3278,19 +3293,20 @@ def test_delete_instance_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MemorystoreRestInterceptor, "post_delete_instance" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_delete_instance_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_delete_instance" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_delete_instance" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_delete_instance_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_delete_instance" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3343,8 +3359,9 @@ def test_get_certificate_authority_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -3407,18 +3424,20 @@ def test_get_certificate_authority_rest_interceptors(null_interceptor): ) client = MemorystoreClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MemorystoreRestInterceptor, "post_get_certificate_authority" - ) as post, mock.patch.object( - transports.MemorystoreRestInterceptor, - "post_get_certificate_authority_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MemorystoreRestInterceptor, "pre_get_certificate_authority" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MemorystoreRestInterceptor, "post_get_certificate_authority" + ) as post, + mock.patch.object( + transports.MemorystoreRestInterceptor, + "post_get_certificate_authority_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MemorystoreRestInterceptor, "pre_get_certificate_authority" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -3473,8 +3492,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3533,8 +3553,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3595,8 +3616,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3657,8 +3679,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3719,8 +3742,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -3781,8 +3805,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -4034,11 +4059,14 @@ def test_memorystore_base_transport(): def test_memorystore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.memorystore_v1beta.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.memorystore_v1beta.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MemorystoreTransport( @@ -4055,9 +4083,12 @@ def test_memorystore_base_transport_with_credentials_file(): def test_memorystore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.memorystore_v1beta.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.memorystore_v1beta.services.memorystore.transports.MemorystoreTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MemorystoreTransport() diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/async_client.py b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/async_client.py index 0a4a8ec30ed7..06090ae9e5a6 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/async_client.py +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/async_client.py @@ -217,7 +217,7 @@ def transport(self) -> MigrationCenterTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -6366,7 +6366,7 @@ async def sample_delete_report(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6392,8 +6392,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6402,7 +6406,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6410,7 +6414,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6421,7 +6425,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6447,8 +6451,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6457,7 +6465,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6465,7 +6473,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6476,7 +6484,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6506,8 +6514,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6516,7 +6528,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6524,7 +6536,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6532,7 +6544,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6561,8 +6573,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6571,7 +6587,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6579,7 +6595,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6587,7 +6603,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6613,8 +6629,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6623,7 +6643,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6631,7 +6651,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6642,7 +6662,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6668,8 +6688,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6678,7 +6702,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6686,7 +6710,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/client.py b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/client.py index 60b2280f23f3..62b21ae4d991 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/client.py +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/client.py @@ -117,7 +117,7 @@ class MigrationCenterClient(metaclass=MigrationCenterClientMeta): """Service describing handlers for resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -643,7 +647,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -740,7 +744,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -838,7 +842,7 @@ def __init__( self._universe_domain = MigrationCenterClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -6844,7 +6848,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6870,8 +6874,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6880,7 +6888,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6889,7 +6897,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6903,7 +6911,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6929,8 +6937,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -6939,7 +6951,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -6948,7 +6960,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -6962,7 +6974,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -6992,8 +7004,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7002,7 +7018,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7010,7 +7026,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7018,7 +7034,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7047,8 +7063,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7057,7 +7077,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7065,7 +7085,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7073,7 +7093,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7099,8 +7119,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7109,7 +7133,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7118,7 +7142,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -7132,7 +7156,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -7158,8 +7182,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -7168,7 +7196,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -7177,7 +7205,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/README.rst b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/README.rst index a6dbb7810182..b5cda0ca5a83 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/README.rst +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MigrationCenterTransport` is the ABC for all transports. -- public child `MigrationCenterGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MigrationCenterGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMigrationCenterRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MigrationCenterRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MigrationCenterTransport`` is the ABC for all transports. + +- public child ``MigrationCenterGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MigrationCenterGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMigrationCenterRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MigrationCenterRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/base.py b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/base.py index 6b9c194a1af8..a2cfc39dad38 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/base.py +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/base.py @@ -83,6 +83,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -132,6 +136,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc.py b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc.py index 0f31d5ac3c16..3ec6bdffa7d8 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc.py +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc_asyncio.py b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc_asyncio.py index c04ce739deb5..77522fe9f62a 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc_asyncio.py +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/rest.py b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/rest.py index 10c29ff31e67..a23ec466c623 100644 --- a/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/rest.py +++ b/packages/google-cloud-migrationcenter/google/cloud/migrationcenter_v1/services/migration_center/transports/rest.py @@ -2949,6 +2949,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[MigrationCenterRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-migrationcenter/noxfile.py b/packages/google-cloud-migrationcenter/noxfile.py index 89f23abc4dd5..a7f69e9eff3d 100644 --- a/packages/google-cloud-migrationcenter/noxfile.py +++ b/packages/google-cloud-migrationcenter/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-migrationcenter/setup.py b/packages/google-cloud-migrationcenter/setup.py index b033b3c61070..114b3e35ee4c 100644 --- a/packages/google-cloud-migrationcenter/setup.py +++ b/packages/google-cloud-migrationcenter/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-migrationcenter" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-migrationcenter/testing/constraints-3.7.txt b/packages/google-cloud-migrationcenter/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-migrationcenter/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-migrationcenter/testing/constraints-3.8.txt b/packages/google-cloud-migrationcenter/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-migrationcenter/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-migrationcenter/testing/constraints-3.9.txt b/packages/google-cloud-migrationcenter/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-migrationcenter/testing/constraints-3.9.txt +++ b/packages/google-cloud-migrationcenter/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-migrationcenter/tests/unit/gapic/migrationcenter_v1/test_migration_center.py b/packages/google-cloud-migrationcenter/tests/unit/gapic/migrationcenter_v1/test_migration_center.py index fd99e99ef450..ed8ada8e5f56 100644 --- a/packages/google-cloud-migrationcenter/tests/unit/gapic/migrationcenter_v1/test_migration_center.py +++ b/packages/google-cloud-migrationcenter/tests/unit/gapic/migrationcenter_v1/test_migration_center.py @@ -130,6 +130,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MigrationCenterClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): assert ( MigrationCenterClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MigrationCenterClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1315,11 +1320,13 @@ def test_migration_center_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -31747,8 +31754,9 @@ def test_list_assets_rest_bad_request(request_type=migrationcenter.ListAssetsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31813,17 +31821,19 @@ def test_list_assets_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_assets" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_assets_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_assets" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_assets_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -31876,8 +31886,9 @@ def test_get_asset_rest_bad_request(request_type=migrationcenter.GetAssetRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -31944,17 +31955,19 @@ def test_get_asset_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_asset" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_asset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_asset" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_asset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_asset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32007,8 +32020,9 @@ def test_update_asset_rest_bad_request(request_type=migrationcenter.UpdateAssetR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32410,17 +32424,19 @@ def test_update_asset_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_asset" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_asset_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_update_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_asset" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_asset_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_update_asset" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32473,8 +32489,9 @@ def test_batch_update_assets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32534,18 +32551,20 @@ def test_batch_update_assets_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_batch_update_assets" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_batch_update_assets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_batch_update_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_batch_update_assets" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_batch_update_assets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_batch_update_assets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -32601,8 +32620,9 @@ def test_delete_asset_rest_bad_request(request_type=migrationcenter.DeleteAssetR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32659,13 +32679,13 @@ def test_delete_asset_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_asset" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_asset" + ) as pre, + ): pre.assert_not_called() pb_message = migrationcenter.DeleteAssetRequest.pb( migrationcenter.DeleteAssetRequest() @@ -32710,8 +32730,9 @@ def test_batch_delete_assets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -32768,13 +32789,13 @@ def test_batch_delete_assets_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_batch_delete_assets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_batch_delete_assets" + ) as pre, + ): pre.assert_not_called() pb_message = migrationcenter.BatchDeleteAssetsRequest.pb( migrationcenter.BatchDeleteAssetsRequest() @@ -32819,8 +32840,9 @@ def test_report_asset_frames_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33180,18 +33202,20 @@ def test_report_asset_frames_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_report_asset_frames" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_report_asset_frames_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_report_asset_frames" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_report_asset_frames" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_report_asset_frames_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_report_asset_frames" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33249,8 +33273,9 @@ def test_aggregate_assets_values_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33310,18 +33335,20 @@ def test_aggregate_assets_values_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_aggregate_assets_values" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_aggregate_assets_values_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_aggregate_assets_values" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_aggregate_assets_values" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_aggregate_assets_values_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_aggregate_assets_values" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33379,8 +33406,9 @@ def test_create_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33539,20 +33567,21 @@ def test_create_import_job_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_import_job" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_create_import_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_import_job" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_create_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33605,8 +33634,9 @@ def test_list_import_jobs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33671,17 +33701,20 @@ def test_list_import_jobs_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_import_jobs" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_import_jobs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_import_jobs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_import_jobs" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_list_import_jobs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_import_jobs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33739,8 +33772,9 @@ def test_get_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33812,17 +33846,20 @@ def test_get_import_job_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_import_job" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_import_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_import_job" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_get_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -33875,8 +33912,9 @@ def test_delete_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -33933,20 +33971,21 @@ def test_delete_import_job_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_import_job" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_delete_import_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_import_job" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_delete_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34001,8 +34040,9 @@ def test_update_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34163,20 +34203,21 @@ def test_update_import_job_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_import_job" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_update_import_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_update_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_import_job" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_update_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_update_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34229,8 +34270,9 @@ def test_validate_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34287,20 +34329,21 @@ def test_validate_import_job_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_validate_import_job" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_validate_import_job_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_validate_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_validate_import_job" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_validate_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_validate_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34353,8 +34396,9 @@ def test_run_import_job_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34411,19 +34455,21 @@ def test_run_import_job_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_run_import_job" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_run_import_job_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_run_import_job" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_run_import_job" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_run_import_job_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_run_import_job" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34478,8 +34524,9 @@ def test_get_import_data_file_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34553,18 +34600,20 @@ def test_get_import_data_file_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_import_data_file" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_get_import_data_file_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_import_data_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_import_data_file" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_get_import_data_file_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_import_data_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34619,8 +34668,9 @@ def test_list_import_data_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34685,18 +34735,20 @@ def test_list_import_data_files_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_import_data_files" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_list_import_data_files_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_import_data_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_import_data_files" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_list_import_data_files_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_import_data_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34754,8 +34806,9 @@ def test_create_import_data_file_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -34893,20 +34946,21 @@ def test_create_import_data_file_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_import_data_file" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_create_import_data_file_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_import_data_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_import_data_file" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_create_import_data_file_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_import_data_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -34961,8 +35015,9 @@ def test_delete_import_data_file_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35021,20 +35076,21 @@ def test_delete_import_data_file_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_import_data_file" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_delete_import_data_file_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_import_data_file" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_import_data_file" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_delete_import_data_file_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_import_data_file" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35085,8 +35141,9 @@ def test_list_groups_rest_bad_request(request_type=migrationcenter.ListGroupsReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35151,17 +35208,19 @@ def test_list_groups_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_groups" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_groups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_groups" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_groups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35214,8 +35273,9 @@ def test_get_group_rest_bad_request(request_type=migrationcenter.GetGroupRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35282,17 +35342,19 @@ def test_get_group_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_group" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_group" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35343,8 +35405,9 @@ def test_create_group_rest_bad_request(request_type=migrationcenter.CreateGroupR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35476,19 +35539,20 @@ def test_create_group_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_group" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_group" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35541,8 +35605,9 @@ def test_update_group_rest_bad_request(request_type=migrationcenter.UpdateGroupR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35676,19 +35741,20 @@ def test_update_group_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_group" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_update_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_group" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_update_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35739,8 +35805,9 @@ def test_delete_group_rest_bad_request(request_type=migrationcenter.DeleteGroupR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35797,19 +35864,20 @@ def test_delete_group_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_group" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_group" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35862,8 +35930,9 @@ def test_add_assets_to_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -35920,20 +35989,21 @@ def test_add_assets_to_group_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_add_assets_to_group" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_add_assets_to_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_add_assets_to_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_add_assets_to_group" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_add_assets_to_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_add_assets_to_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -35986,8 +36056,9 @@ def test_remove_assets_from_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36044,20 +36115,21 @@ def test_remove_assets_from_group_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_remove_assets_from_group" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_remove_assets_from_group_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_remove_assets_from_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_remove_assets_from_group" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_remove_assets_from_group_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_remove_assets_from_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36110,8 +36182,9 @@ def test_list_error_frames_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36176,18 +36249,20 @@ def test_list_error_frames_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_error_frames" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_list_error_frames_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_error_frames" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_error_frames" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_list_error_frames_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_error_frames" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36247,8 +36322,9 @@ def test_get_error_frame_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36313,17 +36389,20 @@ def test_get_error_frame_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_error_frame" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_error_frame_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_error_frame" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_error_frame" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_get_error_frame_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_error_frame" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36374,8 +36453,9 @@ def test_list_sources_rest_bad_request(request_type=migrationcenter.ListSourcesR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36440,17 +36520,19 @@ def test_list_sources_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_sources" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_sources_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_sources" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_sources" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_sources_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_sources" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36506,8 +36588,9 @@ def test_get_source_rest_bad_request(request_type=migrationcenter.GetSourceReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36586,17 +36669,19 @@ def test_get_source_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_source" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_source" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_source_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36649,8 +36734,9 @@ def test_create_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36787,19 +36873,21 @@ def test_create_source_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_source" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_source" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_create_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -36854,8 +36942,9 @@ def test_update_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -36994,19 +37083,21 @@ def test_update_source_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_source" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_update_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_source" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_update_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_update_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37059,8 +37150,9 @@ def test_delete_source_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37117,19 +37209,21 @@ def test_delete_source_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_source" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_source_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_source" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_source" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_delete_source_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_source" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37182,8 +37276,9 @@ def test_list_preference_sets_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37248,18 +37343,20 @@ def test_list_preference_sets_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_preference_sets" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_list_preference_sets_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_preference_sets" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_preference_sets" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_list_preference_sets_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_preference_sets" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37317,8 +37414,9 @@ def test_get_preference_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37385,18 +37483,20 @@ def test_get_preference_set_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_preference_set" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_get_preference_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_preference_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_preference_set" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_get_preference_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_preference_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37451,8 +37551,9 @@ def test_create_preference_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37614,20 +37715,21 @@ def test_create_preference_set_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_preference_set" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_create_preference_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_preference_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_preference_set" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_create_preference_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_preference_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37684,8 +37786,9 @@ def test_update_preference_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37851,20 +37954,21 @@ def test_update_preference_set_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_preference_set" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_update_preference_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_update_preference_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_preference_set" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_update_preference_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_update_preference_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -37917,8 +38021,9 @@ def test_delete_preference_set_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -37975,20 +38080,21 @@ def test_delete_preference_set_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_preference_set" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_delete_preference_set_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_preference_set" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_preference_set" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_delete_preference_set_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_preference_set" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38039,8 +38145,9 @@ def test_get_settings_rest_bad_request(request_type=migrationcenter.GetSettingsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38105,17 +38212,19 @@ def test_get_settings_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_settings" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_settings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_settings" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_settings_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38168,8 +38277,9 @@ def test_update_settings_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38297,19 +38407,21 @@ def test_update_settings_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_settings" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_update_settings_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_update_settings" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_update_settings" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_update_settings_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_update_settings" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38362,8 +38474,9 @@ def test_create_report_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38497,20 +38610,21 @@ def test_create_report_config_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_report_config" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_create_report_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_report_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_report_config" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_create_report_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_report_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38563,8 +38677,9 @@ def test_get_report_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38631,18 +38746,20 @@ def test_get_report_config_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_report_config" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_get_report_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_report_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_report_config" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_get_report_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_report_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38697,8 +38814,9 @@ def test_list_report_configs_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38763,18 +38881,20 @@ def test_list_report_configs_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_report_configs" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_list_report_configs_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_report_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_report_configs" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_list_report_configs_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_report_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38832,8 +38952,9 @@ def test_delete_report_config_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -38890,20 +39011,21 @@ def test_delete_report_config_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_report_config" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, - "post_delete_report_config_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_report_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_report_config" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_delete_report_config_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_report_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -38958,8 +39080,9 @@ def test_create_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39211,19 +39334,21 @@ def test_create_report_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_report" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_create_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_create_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_create_report" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_create_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_create_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39276,8 +39401,9 @@ def test_get_report_rest_bad_request(request_type=migrationcenter.GetReportReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39350,17 +39476,19 @@ def test_get_report_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_report" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_get_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_get_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_report" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_get_report_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_get_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39413,8 +39541,9 @@ def test_list_reports_rest_bad_request(request_type=migrationcenter.ListReportsR request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39481,17 +39610,19 @@ def test_list_reports_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_reports" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_list_reports_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_list_reports" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_reports" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_list_reports_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_list_reports" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39551,8 +39682,9 @@ def test_delete_report_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -39611,19 +39743,21 @@ def test_delete_report_rest_interceptors(null_interceptor): ) client = MigrationCenterClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_report" - ) as post, mock.patch.object( - transports.MigrationCenterRestInterceptor, "post_delete_report_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.MigrationCenterRestInterceptor, "pre_delete_report" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.MigrationCenterRestInterceptor, "post_delete_report" + ) as post, + mock.patch.object( + transports.MigrationCenterRestInterceptor, + "post_delete_report_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.MigrationCenterRestInterceptor, "pre_delete_report" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -39676,8 +39810,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39736,8 +39871,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39798,8 +39934,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39860,8 +39997,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39922,8 +40060,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -39984,8 +40123,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -41176,11 +41316,14 @@ def test_migration_center_base_transport(): def test_migration_center_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.migrationcenter_v1.services.migration_center.transports.MigrationCenterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.migrationcenter_v1.services.migration_center.transports.MigrationCenterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationCenterTransport( @@ -41197,9 +41340,12 @@ def test_migration_center_base_transport_with_credentials_file(): def test_migration_center_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.migrationcenter_v1.services.migration_center.transports.MigrationCenterTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.migrationcenter_v1.services.migration_center.transports.MigrationCenterTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationCenterTransport() @@ -41271,11 +41417,12 @@ def test_migration_center_transport_auth_gdch_credentials(transport_class): def test_migration_center_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -42261,6 +42408,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = MigrationCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = MigrationCenterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = MigrationCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42400,6 +42579,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = MigrationCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = MigrationCenterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = MigrationCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42545,6 +42756,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = MigrationCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = MigrationCenterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = MigrationCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42690,6 +42935,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = MigrationCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = MigrationCenterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = MigrationCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42835,6 +43114,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = MigrationCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = MigrationCenterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = MigrationCenterClient( credentials=ga_credentials.AnonymousCredentials(), @@ -42976,6 +43289,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = MigrationCenterClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = MigrationCenterAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = MigrationCenterClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/async_client.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/async_client.py index 5e45d1576bda..f894947701d2 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/async_client.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> ModelArmorTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1282,7 +1282,7 @@ async def sample_sanitize_model_response(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1308,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1322,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1326,7 +1330,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1337,7 +1341,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1363,8 +1367,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1381,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1381,7 +1389,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/client.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/client.py index f8bd751af526..8b8a91192de5 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/client.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/client.py @@ -113,7 +113,7 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -458,7 +462,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -555,7 +559,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -651,7 +655,7 @@ def __init__( self._universe_domain = ModelArmorClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1721,7 +1725,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1747,8 +1751,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1757,7 +1765,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1766,7 +1774,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1780,7 +1788,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1806,8 +1814,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1816,7 +1828,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1825,7 +1837,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/README.rst b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/README.rst index cdd5d148ed94..4aa0c82f7210 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/README.rst +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelArmorTransport` is the ABC for all transports. -- public child `ModelArmorGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelArmorGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelArmorRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelArmorRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelArmorTransport`` is the ABC for all transports. + +- public child ``ModelArmorGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelArmorGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelArmorRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelArmorRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/base.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/base.py index 168237284cdc..0953aa1e3884 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/base.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc.py index 627b3c2221db..f57ab71b0ade 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc_asyncio.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc_asyncio.py index d086c6a071d9..8f421935bed2 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc_asyncio.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/rest.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/rest.py index 482f4edc1f11..6e73a8346034 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/rest.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1/services/model_armor/transports/rest.py @@ -649,6 +649,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelArmorRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/async_client.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/async_client.py index 07f2c8695433..576de808f241 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/async_client.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> ModelArmorTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1282,7 +1282,7 @@ async def sample_sanitize_model_response(): async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1308,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1322,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1326,7 +1330,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1337,7 +1341,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1363,8 +1367,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1381,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1381,7 +1389,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/client.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/client.py index 475adf522e65..425fde2d03fd 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/client.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/client.py @@ -113,7 +113,7 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta): """Service describing handlers for resources""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -458,7 +462,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -555,7 +559,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -651,7 +655,7 @@ def __init__( self._universe_domain = ModelArmorClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1721,7 +1725,7 @@ def __exit__(self, type, value, traceback): def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1747,8 +1751,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1757,7 +1765,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1766,7 +1774,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1780,7 +1788,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1806,8 +1814,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1816,7 +1828,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1825,7 +1837,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/README.rst b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/README.rst index cdd5d148ed94..4aa0c82f7210 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/README.rst +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ModelArmorTransport` is the ABC for all transports. -- public child `ModelArmorGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ModelArmorGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseModelArmorRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ModelArmorRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ModelArmorTransport`` is the ABC for all transports. + +- public child ``ModelArmorGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ModelArmorGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseModelArmorRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ModelArmorRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/base.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/base.py index e6601d1986d4..cc54cc6d7a84 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/base.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/base.py @@ -82,6 +82,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -131,6 +135,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc.py index 2e7e220be68f..6e233fc46771 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc_asyncio.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc_asyncio.py index 3be45418ccd2..458735299e46 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc_asyncio.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/rest.py b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/rest.py index c7c6bf2c3948..ccbaf1ffe414 100644 --- a/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/rest.py +++ b/packages/google-cloud-modelarmor/google/cloud/modelarmor_v1beta/services/model_armor/transports/rest.py @@ -649,6 +649,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[ModelArmorRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-modelarmor/noxfile.py b/packages/google-cloud-modelarmor/noxfile.py index 0e81d2510e91..3dff6efe389e 100644 --- a/packages/google-cloud-modelarmor/noxfile.py +++ b/packages/google-cloud-modelarmor/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-modelarmor/setup.py b/packages/google-cloud-modelarmor/setup.py index 1c4d8316bcd6..5c643e7ab3fb 100644 --- a/packages/google-cloud-modelarmor/setup.py +++ b/packages/google-cloud-modelarmor/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-modelarmor" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-modelarmor/testing/constraints-3.7.txt b/packages/google-cloud-modelarmor/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-modelarmor/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-modelarmor/testing/constraints-3.8.txt b/packages/google-cloud-modelarmor/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-modelarmor/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-modelarmor/testing/constraints-3.9.txt b/packages/google-cloud-modelarmor/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-modelarmor/testing/constraints-3.9.txt +++ b/packages/google-cloud-modelarmor/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1/test_model_armor.py b/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1/test_model_armor.py index fe59063a6ea6..5b8c28c15730 100644 --- a/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1/test_model_armor.py +++ b/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1/test_model_armor.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelArmorClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelArmorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelArmorClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_model_armor_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6543,8 +6549,9 @@ def test_list_templates_rest_bad_request(request_type=service.ListTemplatesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6609,17 +6616,19 @@ def test_list_templates_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_list_templates" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_list_templates_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_list_templates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_list_templates" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_list_templates_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_list_templates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6670,8 +6679,9 @@ def test_get_template_rest_bad_request(request_type=service.GetTemplateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6734,17 +6744,19 @@ def test_get_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_template" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_get_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_template" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_get_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6793,8 +6805,9 @@ def test_create_template_rest_bad_request(request_type=service.CreateTemplateReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6958,17 +6971,19 @@ def test_create_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_create_template" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_create_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_create_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_create_template" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_create_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_create_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7019,8 +7034,9 @@ def test_update_template_rest_bad_request(request_type=service.UpdateTemplateReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7186,17 +7202,19 @@ def test_update_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_template" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_update_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_update_template" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_update_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_update_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7245,8 +7263,9 @@ def test_delete_template_rest_bad_request(request_type=service.DeleteTemplateReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7303,13 +7322,13 @@ def test_delete_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_delete_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_delete_template" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteTemplateRequest.pb(service.DeleteTemplateRequest()) transcode.return_value = { @@ -7352,8 +7371,9 @@ def test_get_floor_setting_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7422,17 +7442,19 @@ def test_get_floor_setting_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_floor_setting" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_floor_setting_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_get_floor_setting" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_floor_setting" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_floor_setting_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_get_floor_setting" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7485,8 +7507,9 @@ def test_update_floor_setting_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7656,17 +7679,20 @@ def test_update_floor_setting_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_floor_setting" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_floor_setting_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_update_floor_setting" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_update_floor_setting" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, + "post_update_floor_setting_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_update_floor_setting" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7719,8 +7745,9 @@ def test_sanitize_user_prompt_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7780,17 +7807,20 @@ def test_sanitize_user_prompt_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_sanitize_user_prompt" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_sanitize_user_prompt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_sanitize_user_prompt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_sanitize_user_prompt" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, + "post_sanitize_user_prompt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_sanitize_user_prompt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7845,8 +7875,9 @@ def test_sanitize_model_response_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7906,18 +7937,20 @@ def test_sanitize_model_response_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_sanitize_model_response" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, - "post_sanitize_model_response_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_sanitize_model_response" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_sanitize_model_response" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, + "post_sanitize_model_response_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_sanitize_model_response" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7975,8 +8008,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8035,8 +8069,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8342,11 +8377,14 @@ def test_model_armor_base_transport(): def test_model_armor_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.modelarmor_v1.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.modelarmor_v1.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelArmorTransport( @@ -8363,9 +8401,12 @@ def test_model_armor_base_transport_with_credentials_file(): def test_model_armor_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.modelarmor_v1.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.modelarmor_v1.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelArmorTransport() @@ -8437,11 +8478,12 @@ def test_model_armor_transport_auth_gdch_credentials(transport_class): def test_model_armor_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9046,6 +9088,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ModelArmorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ModelArmorAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ModelArmorClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9187,6 +9263,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ModelArmorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ModelArmorAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ModelArmorClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1beta/test_model_armor.py b/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1beta/test_model_armor.py index cd59d8a4ddc0..6a789f86f832 100644 --- a/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1beta/test_model_armor.py +++ b/packages/google-cloud-modelarmor/tests/unit/gapic/modelarmor_v1beta/test_model_armor.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ModelArmorClient._get_default_mtls_endpoint(None) is None assert ( @@ -140,6 +141,9 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert ModelArmorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ModelArmorClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint + ) def test__read_environment_variables(): @@ -1242,11 +1246,13 @@ def test_model_armor_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6548,8 +6554,9 @@ def test_list_templates_rest_bad_request(request_type=service.ListTemplatesReque request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6614,17 +6621,19 @@ def test_list_templates_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_list_templates" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_list_templates_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_list_templates" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_list_templates" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_list_templates_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_list_templates" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6675,8 +6684,9 @@ def test_get_template_rest_bad_request(request_type=service.GetTemplateRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6739,17 +6749,19 @@ def test_get_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_template" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_get_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_template" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_get_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -6798,8 +6810,9 @@ def test_create_template_rest_bad_request(request_type=service.CreateTemplateReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -6963,17 +6976,19 @@ def test_create_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_create_template" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_create_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_create_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_create_template" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_create_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_create_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7024,8 +7039,9 @@ def test_update_template_rest_bad_request(request_type=service.UpdateTemplateReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7191,17 +7207,19 @@ def test_update_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_template" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_template_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_update_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_update_template" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_update_template_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_update_template" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7250,8 +7268,9 @@ def test_delete_template_rest_bad_request(request_type=service.DeleteTemplateReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7308,13 +7327,13 @@ def test_delete_template_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_delete_template" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_delete_template" + ) as pre, + ): pre.assert_not_called() pb_message = service.DeleteTemplateRequest.pb(service.DeleteTemplateRequest()) transcode.return_value = { @@ -7357,8 +7376,9 @@ def test_get_floor_setting_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7427,17 +7447,19 @@ def test_get_floor_setting_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_floor_setting" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_get_floor_setting_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_get_floor_setting" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_floor_setting" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_get_floor_setting_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_get_floor_setting" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7490,8 +7512,9 @@ def test_update_floor_setting_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7661,17 +7684,20 @@ def test_update_floor_setting_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_floor_setting" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_update_floor_setting_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_update_floor_setting" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_update_floor_setting" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, + "post_update_floor_setting_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_update_floor_setting" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7724,8 +7750,9 @@ def test_sanitize_user_prompt_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7785,17 +7812,20 @@ def test_sanitize_user_prompt_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_sanitize_user_prompt" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_sanitize_user_prompt_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_sanitize_user_prompt" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_sanitize_user_prompt" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, + "post_sanitize_user_prompt_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_sanitize_user_prompt" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7850,8 +7880,9 @@ def test_sanitize_model_response_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -7911,18 +7942,20 @@ def test_sanitize_model_response_rest_interceptors(null_interceptor): ) client = ModelArmorClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.ModelArmorRestInterceptor, "post_sanitize_model_response" - ) as post, mock.patch.object( - transports.ModelArmorRestInterceptor, - "post_sanitize_model_response_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.ModelArmorRestInterceptor, "pre_sanitize_model_response" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.ModelArmorRestInterceptor, "post_sanitize_model_response" + ) as post, + mock.patch.object( + transports.ModelArmorRestInterceptor, + "post_sanitize_model_response_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.ModelArmorRestInterceptor, "pre_sanitize_model_response" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -7980,8 +8013,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8040,8 +8074,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -8347,11 +8382,14 @@ def test_model_armor_base_transport(): def test_model_armor_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.modelarmor_v1beta.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.modelarmor_v1beta.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelArmorTransport( @@ -8368,9 +8406,12 @@ def test_model_armor_base_transport_with_credentials_file(): def test_model_armor_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.modelarmor_v1beta.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.modelarmor_v1beta.services.model_armor.transports.ModelArmorTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ModelArmorTransport() @@ -8442,11 +8483,12 @@ def test_model_armor_transport_auth_gdch_credentials(transport_class): def test_model_armor_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9051,6 +9093,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = ModelArmorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = ModelArmorAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = ModelArmorClient( credentials=ga_credentials.AnonymousCredentials(), @@ -9192,6 +9268,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = ModelArmorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = ModelArmorAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = ModelArmorClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py index 205ff0d694f9..7b4ad19be3de 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> DashboardsServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py index 3e7b05554219..80f3577d1109 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/client.py @@ -117,7 +117,7 @@ class DashboardsServiceClient(metaclass=DashboardsServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -456,7 +460,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -553,7 +557,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -653,7 +657,7 @@ def __init__( self._universe_domain = DashboardsServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/README.rst b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/README.rst index c4dda772c441..cb6647ab8a4e 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/README.rst +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DashboardsServiceTransport` is the ABC for all transports. -- public child `DashboardsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DashboardsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDashboardsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DashboardsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DashboardsServiceTransport`` is the ABC for all transports. + +- public child ``DashboardsServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DashboardsServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDashboardsServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DashboardsServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py index 25b47e6381ed..851b565aa570 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py index f39f50ea249c..b4f6d651d9c8 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py index d1989a6e57bf..820da46fc873 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/rest.py b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/rest.py index efff8c4a9c42..ac29774fde66 100644 --- a/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/rest.py +++ b/packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/rest.py @@ -395,6 +395,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[DashboardsServiceRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-monitoring-dashboards/noxfile.py b/packages/google-cloud-monitoring-dashboards/noxfile.py index 8ee84f6ffa73..0fd46c8ad8a4 100644 --- a/packages/google-cloud-monitoring-dashboards/noxfile.py +++ b/packages/google-cloud-monitoring-dashboards/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,9 @@ def mypy(session): "mypy", "-p", "google", + # TODO(https://github.com/googleapis/google-cloud-python/issues/16083) + # "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +299,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +532,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +627,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-monitoring-dashboards/setup.py b/packages/google-cloud-monitoring-dashboards/setup.py index a170c8930097..7f79ea5a1b54 100644 --- a/packages/google-cloud-monitoring-dashboards/setup.py +++ b/packages/google-cloud-monitoring-dashboards/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-monitoring-dashboards" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-monitoring-dashboards/testing/constraints-3.7.txt b/packages/google-cloud-monitoring-dashboards/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-monitoring-dashboards/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-monitoring-dashboards/testing/constraints-3.8.txt b/packages/google-cloud-monitoring-dashboards/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-monitoring-dashboards/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-monitoring-dashboards/testing/constraints-3.9.txt b/packages/google-cloud-monitoring-dashboards/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-monitoring-dashboards/testing/constraints-3.9.txt +++ b/packages/google-cloud-monitoring-dashboards/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py index 0ad6fcba798d..b9b264e95791 100644 --- a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py +++ b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py @@ -697,11 +697,13 @@ def test_dashboards_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1843,11 +1845,14 @@ def test_dashboards_service_base_transport(): def test_dashboards_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DashboardsServiceTransport( @@ -1869,9 +1874,12 @@ def test_dashboards_service_base_transport_with_credentials_file(): def test_dashboards_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DashboardsServiceTransport() @@ -1952,11 +1960,12 @@ def test_dashboards_service_transport_auth_gdch_credentials(transport_class): def test_dashboards_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/monitoring_dashboard_v1/test_dashboards_service.py b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/monitoring_dashboard_v1/test_dashboards_service.py index e7d68508752b..bec0ba25709b 100644 --- a/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/monitoring_dashboard_v1/test_dashboards_service.py +++ b/packages/google-cloud-monitoring-dashboards/tests/unit/gapic/monitoring_dashboard_v1/test_dashboards_service.py @@ -146,6 +146,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert DashboardsServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -168,6 +169,10 @@ def test__get_default_mtls_endpoint(): DashboardsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + DashboardsServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1345,11 +1350,13 @@ def test_dashboards_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4421,8 +4428,9 @@ def test_create_dashboard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4739,18 +4747,20 @@ def test_create_dashboard_rest_interceptors(null_interceptor): ) client = DashboardsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "post_create_dashboard" - ) as post, mock.patch.object( - transports.DashboardsServiceRestInterceptor, - "post_create_dashboard_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "pre_create_dashboard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "post_create_dashboard" + ) as post, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, + "post_create_dashboard_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "pre_create_dashboard" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4803,8 +4813,9 @@ def test_list_dashboards_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -4867,18 +4878,20 @@ def test_list_dashboards_rest_interceptors(null_interceptor): ) client = DashboardsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "post_list_dashboards" - ) as post, mock.patch.object( - transports.DashboardsServiceRestInterceptor, - "post_list_dashboards_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "pre_list_dashboards" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "post_list_dashboards" + ) as post, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, + "post_list_dashboards_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "pre_list_dashboards" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -4936,8 +4949,9 @@ def test_get_dashboard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5004,17 +5018,20 @@ def test_get_dashboard_rest_interceptors(null_interceptor): ) client = DashboardsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "post_get_dashboard" - ) as post, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "post_get_dashboard_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "pre_get_dashboard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "post_get_dashboard" + ) as post, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, + "post_get_dashboard_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "pre_get_dashboard" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5067,8 +5084,9 @@ def test_delete_dashboard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5125,13 +5143,13 @@ def test_delete_dashboard_rest_interceptors(null_interceptor): ) client = DashboardsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "pre_delete_dashboard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "pre_delete_dashboard" + ) as pre, + ): pre.assert_not_called() pb_message = dashboards_service.DeleteDashboardRequest.pb( dashboards_service.DeleteDashboardRequest() @@ -5176,8 +5194,9 @@ def test_update_dashboard_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -5494,18 +5513,20 @@ def test_update_dashboard_rest_interceptors(null_interceptor): ) client = DashboardsServiceClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "post_update_dashboard" - ) as post, mock.patch.object( - transports.DashboardsServiceRestInterceptor, - "post_update_dashboard_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.DashboardsServiceRestInterceptor, "pre_update_dashboard" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "post_update_dashboard" + ) as post, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, + "post_update_dashboard_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.DashboardsServiceRestInterceptor, "pre_update_dashboard" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -5711,11 +5732,14 @@ def test_dashboards_service_base_transport(): def test_dashboards_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DashboardsServiceTransport( @@ -5737,9 +5761,12 @@ def test_dashboards_service_base_transport_with_credentials_file(): def test_dashboards_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_dashboard_v1.services.dashboards_service.transports.DashboardsServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DashboardsServiceTransport() @@ -5821,11 +5848,12 @@ def test_dashboards_service_transport_auth_gdch_credentials(transport_class): def test_dashboards_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py index 785a360d1ac9..c87182f437ae 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py +++ b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/async_client.py @@ -198,7 +198,7 @@ def transport(self) -> MetricsScopesTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py index 17a6f2962c8c..8f7a94d1cb7b 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py +++ b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/client.py @@ -114,7 +114,7 @@ class MetricsScopesClient(metaclass=MetricsScopesClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -122,7 +122,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -132,6 +132,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -454,7 +458,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -551,7 +555,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = MetricsScopesClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/README.rst b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/README.rst index 6d33f0c511a1..ee8abc22d955 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/README.rst +++ b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetricsScopesTransport` is the ABC for all transports. -- public child `MetricsScopesGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetricsScopesGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetricsScopesRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetricsScopesRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetricsScopesTransport`` is the ABC for all transports. + +- public child ``MetricsScopesGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetricsScopesGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetricsScopesRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetricsScopesRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py index 38deee170026..2df9a5217251 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py +++ b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py index 93eb68985b64..9ac775ff360b 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py +++ b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -186,6 +186,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py index be55121b7f7a..53d3827c8682 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring-metrics-scopes/google/cloud/monitoring_metrics_scope_v1/services/metrics_scopes/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -237,6 +237,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py index c60a2d0376f9..473b9b5d3b6c 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/noxfile.py +++ b/packages/google-cloud-monitoring-metrics-scopes/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-monitoring-metrics-scopes/setup.py b/packages/google-cloud-monitoring-metrics-scopes/setup.py index ebab68272342..9252a1a56754 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/setup.py +++ b/packages/google-cloud-monitoring-metrics-scopes/setup.py @@ -41,7 +41,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -49,7 +49,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-monitoring-metrics-scopes" @@ -81,8 +81,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -94,7 +92,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.7.txt b/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.8.txt b/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.9.txt b/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.9.txt +++ b/packages/google-cloud-monitoring-metrics-scopes/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-monitoring-metrics-scopes/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py b/packages/google-cloud-monitoring-metrics-scopes/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py index 4ab6d0cc6d17..8479dc2238e7 100644 --- a/packages/google-cloud-monitoring-metrics-scopes/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py +++ b/packages/google-cloud-monitoring-metrics-scopes/tests/unit/gapic/monitoring_metrics_scope_v1/test_metrics_scopes.py @@ -123,6 +123,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetricsScopesClient._get_default_mtls_endpoint(None) is None assert ( @@ -144,6 +145,10 @@ def test__get_default_mtls_endpoint(): assert ( MetricsScopesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetricsScopesClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1263,11 +1268,13 @@ def test_metrics_scopes_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -2911,11 +2918,14 @@ def test_metrics_scopes_base_transport(): def test_metrics_scopes_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.transports.MetricsScopesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.transports.MetricsScopesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsScopesTransport( @@ -2937,9 +2947,12 @@ def test_metrics_scopes_base_transport_with_credentials_file(): def test_metrics_scopes_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.transports.MetricsScopesTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_metrics_scope_v1.services.metrics_scopes.transports.MetricsScopesTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricsScopesTransport() @@ -3020,11 +3033,12 @@ def test_metrics_scopes_transport_auth_gdch_credentials(transport_class): def test_metrics_scopes_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py index de8688f269f6..ba3ee689bbdc 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/async_client.py @@ -209,7 +209,7 @@ def transport(self) -> AlertPolicyServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/client.py index 8857695e0a62..8c6f58814ea1 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/client.py @@ -121,7 +121,7 @@ class AlertPolicyServiceClient(metaclass=AlertPolicyServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -465,7 +469,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -562,7 +566,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -662,7 +666,7 @@ def __init__( self._universe_domain = AlertPolicyServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/README.rst index e91349e0d0f2..3389a3164814 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`AlertPolicyServiceTransport` is the ABC for all transports. -- public child `AlertPolicyServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `AlertPolicyServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseAlertPolicyServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `AlertPolicyServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``AlertPolicyServiceTransport`` is the ABC for all transports. + +- public child ``AlertPolicyServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``AlertPolicyServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseAlertPolicyServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``AlertPolicyServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/base.py index 61bb83d7da9c..58328a3e0e9a 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py index ca15f1b479da..f1e42dfd77ef 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py index 61792ca3a117..549081897e15 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/alert_policy_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/async_client.py index b2331178e7f2..da27c973c394 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/async_client.py @@ -197,7 +197,7 @@ def transport(self) -> GroupServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/client.py index 5bed50bc38f0..745a084759ea 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/client.py @@ -123,7 +123,7 @@ class GroupServiceClient(metaclass=GroupServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -131,7 +131,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -141,6 +141,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -443,7 +447,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -540,7 +544,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -636,7 +640,7 @@ def __init__( self._universe_domain = GroupServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/README.rst index cf739d32fb68..cffb6f64c86e 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`GroupServiceTransport` is the ABC for all transports. -- public child `GroupServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `GroupServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseGroupServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `GroupServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``GroupServiceTransport`` is the ABC for all transports. + +- public child ``GroupServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``GroupServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseGroupServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``GroupServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/base.py index 97ada120e5b3..3fa6628c660d 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc.py index f95a29544d8f..ef544bc6a7b5 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -198,6 +198,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py index 4015a2d2d5d8..ee7ae670d807 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/group_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -249,6 +249,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/async_client.py index 6b93a0a76b96..0d256199e7c5 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/async_client.py @@ -204,7 +204,7 @@ def transport(self) -> MetricServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/client.py index 8386901d72bc..2c363eca7ea0 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/client.py @@ -116,7 +116,7 @@ class MetricServiceClient(metaclass=MetricServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -124,7 +124,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -134,6 +134,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -478,7 +482,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -575,7 +579,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -671,7 +675,7 @@ def __init__( self._universe_domain = MetricServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/README.rst index 9d0ceec49170..3e0d17c05742 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`MetricServiceTransport` is the ABC for all transports. -- public child `MetricServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `MetricServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseMetricServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `MetricServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``MetricServiceTransport`` is the ABC for all transports. + +- public child ``MetricServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``MetricServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseMetricServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``MetricServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/base.py index e778c7def097..43cb2970452b 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py index bf1a94e433f4..b5809727e3f7 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc.py @@ -58,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -93,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py index b834ddf195d7..903ce6585ff1 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/metric_service/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -99,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py index a387cd9834c7..d72db666c1f4 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/async_client.py @@ -223,7 +223,7 @@ def transport(self) -> NotificationChannelServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/client.py index dd24c8a2df33..993fccc49967 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/client.py @@ -121,7 +121,7 @@ class NotificationChannelServiceClient(metaclass=NotificationChannelServiceClien """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -129,7 +129,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -139,6 +139,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -563,7 +567,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -665,7 +669,7 @@ def __init__( self._universe_domain = NotificationChannelServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/README.rst index bf00983aefe9..35e9cd44d89f 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NotificationChannelServiceTransport` is the ABC for all transports. -- public child `NotificationChannelServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NotificationChannelServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNotificationChannelServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NotificationChannelServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NotificationChannelServiceTransport`` is the ABC for all transports. + +- public child ``NotificationChannelServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NotificationChannelServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNotificationChannelServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NotificationChannelServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/base.py index a3e45d3a9eab..de043dbeb2bb 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py index 201bb458f192..bee7b8ebb461 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py index 4d39f8698253..a72af2d958b0 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/notification_channel_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/async_client.py index 239d7669df15..019b5bafe348 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/async_client.py @@ -185,7 +185,7 @@ def transport(self) -> QueryServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/client.py index 94fde587cb7b..4c0fdc04b01f 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/client.py @@ -112,7 +112,7 @@ class QueryServiceClient(metaclass=QueryServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -120,7 +120,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -130,6 +130,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -415,7 +419,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -512,7 +516,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -608,7 +612,7 @@ def __init__( self._universe_domain = QueryServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/README.rst index d65930c8cfed..bf43362f77c3 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`QueryServiceTransport` is the ABC for all transports. -- public child `QueryServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `QueryServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseQueryServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `QueryServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``QueryServiceTransport`` is the ABC for all transports. + +- public child ``QueryServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``QueryServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseQueryServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``QueryServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/base.py index 68b0e56f9532..4f8ca8353e88 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/base.py @@ -85,6 +85,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -134,6 +138,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc.py index 8bbefec44f4f..6c1073966018 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -187,6 +187,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc_asyncio.py index d12946900e72..2e8bc2708817 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/query_service/transports/grpc_asyncio.py @@ -61,7 +61,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -238,6 +238,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py index b1d7c7f99776..d6f86e3a9fa1 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/async_client.py @@ -211,7 +211,7 @@ def transport(self) -> ServiceMonitoringServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/client.py index f8b0f5c44b62..c6ef69c562b6 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/client.py @@ -117,7 +117,7 @@ class ServiceMonitoringServiceClient(metaclass=ServiceMonitoringServiceClientMet """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -125,7 +125,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -135,6 +135,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -459,7 +463,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -558,7 +562,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -660,7 +664,7 @@ def __init__( self._universe_domain = ServiceMonitoringServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/README.rst index a2c42706b77e..3b2646b44719 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`ServiceMonitoringServiceTransport` is the ABC for all transports. -- public child `ServiceMonitoringServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ServiceMonitoringServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseServiceMonitoringServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ServiceMonitoringServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``ServiceMonitoringServiceTransport`` is the ABC for all transports. + +- public child ``ServiceMonitoringServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``ServiceMonitoringServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseServiceMonitoringServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``ServiceMonitoringServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/base.py index 685f89634397..e3293b9671bf 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py index 2314a30b27a3..2b66fbe6b864 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc.py @@ -57,7 +57,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -92,7 +92,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -191,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py index d31d36eeefd6..4f3197a04892 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/service_monitoring_service/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -242,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/async_client.py index b45c12c914e3..03ba12c2817e 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/async_client.py @@ -195,7 +195,7 @@ def transport(self) -> SnoozeServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/client.py index 5175cbfe2b79..ccf355b1afd1 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/client.py @@ -115,7 +115,7 @@ class SnoozeServiceClient(metaclass=SnoozeServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -123,7 +123,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -133,6 +133,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -454,7 +458,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -551,7 +555,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -647,7 +651,7 @@ def __init__( self._universe_domain = SnoozeServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/README.rst index 04647cb11fea..4c738b8467dc 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`SnoozeServiceTransport` is the ABC for all transports. -- public child `SnoozeServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `SnoozeServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseSnoozeServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `SnoozeServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``SnoozeServiceTransport`` is the ABC for all transports. + +- public child ``SnoozeServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``SnoozeServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseSnoozeServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``SnoozeServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/base.py index 325b47433dcb..e95e91e3aca7 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc.py index 89118b2056a3..9cc6ac9d09a9 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -189,6 +189,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc_asyncio.py index 869ed22c6e81..9a081f674f06 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/snooze_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -240,6 +240,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py index 3c43b7e1286d..0b5ba82a0fd2 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/async_client.py @@ -205,7 +205,7 @@ def transport(self) -> UptimeCheckServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/client.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/client.py index 9eb718332ddf..aec524e65692 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/client.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/client.py @@ -119,7 +119,7 @@ class UptimeCheckServiceClient(metaclass=UptimeCheckServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -464,7 +468,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -561,7 +565,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -661,7 +665,7 @@ def __init__( self._universe_domain = UptimeCheckServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/README.rst b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/README.rst index c01856fad335..63b3a35c364d 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/README.rst +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`UptimeCheckServiceTransport` is the ABC for all transports. -- public child `UptimeCheckServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `UptimeCheckServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseUptimeCheckServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `UptimeCheckServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``UptimeCheckServiceTransport`` is the ABC for all transports. + +- public child ``UptimeCheckServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``UptimeCheckServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseUptimeCheckServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``UptimeCheckServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/base.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/base.py index d821e90c617c..efe3939214af 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/base.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py index 36d7273cf8fc..35622b6885f4 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc.py @@ -56,7 +56,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -91,7 +91,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py index 4199188076a3..05a363873794 100644 --- a/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-monitoring/google/cloud/monitoring_v3/services/uptime_check_service/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -97,7 +97,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-monitoring/noxfile.py b/packages/google-cloud-monitoring/noxfile.py index ada94e76ff6d..9ffcb322ca2e 100644 --- a/packages/google-cloud-monitoring/noxfile.py +++ b/packages/google-cloud-monitoring/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -107,6 +106,9 @@ def mypy(session): "mypy", "-p", "google", + # TODO(https://github.com/googleapis/google-cloud-python/issues/16083) + # "--check-untyped-defs", + *session.posargs, ) @@ -298,7 +300,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -528,7 +533,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -623,7 +628,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-monitoring/setup.py b/packages/google-cloud-monitoring/setup.py index 5ca3e112112d..f3e56abf85b5 100644 --- a/packages/google-cloud-monitoring/setup.py +++ b/packages/google-cloud-monitoring/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,9 +47,9 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] -extras = {"pandas": "pandas >= 0.23.2"} +extras = {"pandas": "pandas >= 1.1.3"} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-monitoring" @@ -80,8 +80,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -93,7 +91,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-monitoring/testing/constraints-3.7.txt b/packages/google-cloud-monitoring/testing/constraints-3.7.txt deleted file mode 100644 index f5773fddd064..000000000000 --- a/packages/google-cloud-monitoring/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -pandas==0.23.2 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-monitoring/testing/constraints-3.8.txt b/packages/google-cloud-monitoring/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-monitoring/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-monitoring/testing/constraints-3.9.txt b/packages/google-cloud-monitoring/testing/constraints-3.9.txt index 7599dea499ed..71ede56a80fb 100644 --- a/packages/google-cloud-monitoring/testing/constraints-3.9.txt +++ b/packages/google-cloud-monitoring/testing/constraints-3.9.txt @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +pandas==1.1.3 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py index 6cea1bc57f8e..a624d95ea958 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_alert_policy_service.py @@ -129,6 +129,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AlertPolicyServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): AlertPolicyServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + AlertPolicyServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1300,11 +1305,13 @@ def test_alert_policy_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3712,11 +3719,14 @@ def test_alert_policy_service_base_transport(): def test_alert_policy_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.alert_policy_service.transports.AlertPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.alert_policy_service.transports.AlertPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlertPolicyServiceTransport( @@ -3737,9 +3747,12 @@ def test_alert_policy_service_base_transport_with_credentials_file(): def test_alert_policy_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.alert_policy_service.transports.AlertPolicyServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.alert_policy_service.transports.AlertPolicyServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.AlertPolicyServiceTransport() @@ -3818,11 +3831,12 @@ def test_alert_policy_service_transport_auth_gdch_credentials(transport_class): def test_alert_policy_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_group_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_group_service.py index ed3bf81e51ca..c2e236f4b796 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_group_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_group_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert GroupServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -138,6 +139,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert GroupServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + GroupServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1241,11 +1246,13 @@ def test_group_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4149,11 +4156,14 @@ def test_group_service_base_transport(): def test_group_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.group_service.transports.GroupServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.group_service.transports.GroupServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroupServiceTransport( @@ -4174,9 +4184,12 @@ def test_group_service_base_transport_with_credentials_file(): def test_group_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.group_service.transports.GroupServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.group_service.transports.GroupServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.GroupServiceTransport() @@ -4255,11 +4268,12 @@ def test_group_service_transport_auth_gdch_credentials(transport_class): def test_group_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_metric_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_metric_service.py index e5fc38a96847..c52b8c5d4c51 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_metric_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_metric_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetricServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -148,6 +149,10 @@ def test__get_default_mtls_endpoint(): assert ( MetricServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + MetricServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1267,11 +1272,13 @@ def test_metric_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5761,11 +5768,14 @@ def test_metric_service_base_transport(): def test_metric_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.metric_service.transports.MetricServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.metric_service.transports.MetricServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricServiceTransport( @@ -5787,9 +5797,12 @@ def test_metric_service_base_transport_with_credentials_file(): def test_metric_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.metric_service.transports.MetricServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.metric_service.transports.MetricServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MetricServiceTransport() @@ -5870,11 +5883,12 @@ def test_metric_service_transport_auth_gdch_credentials(transport_class): def test_metric_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py index 29f51bf6ecc8..d6413e5188b9 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_notification_channel_service.py @@ -127,6 +127,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NotificationChannelServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -151,6 +152,10 @@ def test__get_default_mtls_endpoint(): NotificationChannelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + NotificationChannelServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1339,11 +1344,13 @@ def test_notification_channel_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -6102,11 +6109,14 @@ def test_notification_channel_service_base_transport(): def test_notification_channel_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.notification_channel_service.transports.NotificationChannelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.notification_channel_service.transports.NotificationChannelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NotificationChannelServiceTransport( @@ -6127,9 +6137,12 @@ def test_notification_channel_service_base_transport_with_credentials_file(): def test_notification_channel_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.notification_channel_service.transports.NotificationChannelServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.notification_channel_service.transports.NotificationChannelServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NotificationChannelServiceTransport() @@ -6210,11 +6223,12 @@ def test_notification_channel_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_query_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_query_service.py index 00448784d535..ff989c933c9d 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_query_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_query_service.py @@ -117,6 +117,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert QueryServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -135,6 +136,10 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert QueryServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + QueryServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1238,11 +1243,13 @@ def test_query_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -1949,11 +1956,14 @@ def test_query_service_base_transport(): def test_query_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.query_service.transports.QueryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.query_service.transports.QueryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.QueryServiceTransport( @@ -1974,9 +1984,12 @@ def test_query_service_base_transport_with_credentials_file(): def test_query_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.query_service.transports.QueryServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.query_service.transports.QueryServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.QueryServiceTransport() @@ -2055,11 +2068,12 @@ def test_query_service_transport_auth_gdch_credentials(transport_class): def test_query_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py index 0fcffbdd971b..a6c53c5380fa 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_service_monitoring_service.py @@ -121,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ServiceMonitoringServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -143,6 +144,10 @@ def test__get_default_mtls_endpoint(): ServiceMonitoringServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + ServiceMonitoringServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1314,11 +1319,13 @@ def test_service_monitoring_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -5781,11 +5788,14 @@ def test_service_monitoring_service_base_transport(): def test_service_monitoring_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.service_monitoring_service.transports.ServiceMonitoringServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.service_monitoring_service.transports.ServiceMonitoringServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceMonitoringServiceTransport( @@ -5806,9 +5816,12 @@ def test_service_monitoring_service_base_transport_with_credentials_file(): def test_service_monitoring_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.service_monitoring_service.transports.ServiceMonitoringServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.service_monitoring_service.transports.ServiceMonitoringServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceMonitoringServiceTransport() @@ -5889,11 +5902,12 @@ def test_service_monitoring_service_transport_create_channel( ): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_snooze_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_snooze_service.py index ab69075b743c..05a0fb0f7099 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_snooze_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_snooze_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert SnoozeServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -141,6 +142,10 @@ def test__get_default_mtls_endpoint(): assert ( SnoozeServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + SnoozeServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1260,11 +1265,13 @@ def test_snooze_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -3164,11 +3171,14 @@ def test_snooze_service_base_transport(): def test_snooze_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.snooze_service.transports.SnoozeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.snooze_service.transports.SnoozeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnoozeServiceTransport( @@ -3189,9 +3199,12 @@ def test_snooze_service_base_transport_with_credentials_file(): def test_snooze_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.snooze_service.transports.SnoozeServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.snooze_service.transports.SnoozeServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SnoozeServiceTransport() @@ -3270,11 +3283,12 @@ def test_snooze_service_transport_auth_gdch_credentials(transport_class): def test_snooze_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py index fff2d7f4cf86..4f4f7abd6bbc 100644 --- a/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py +++ b/packages/google-cloud-monitoring/tests/unit/gapic/monitoring_v3/test_uptime_check_service.py @@ -120,6 +120,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert UptimeCheckServiceClient._get_default_mtls_endpoint(None) is None assert ( @@ -142,6 +143,10 @@ def test__get_default_mtls_endpoint(): UptimeCheckServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + UptimeCheckServiceClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1291,11 +1296,13 @@ def test_uptime_check_service_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -4191,11 +4198,14 @@ def test_uptime_check_service_base_transport(): def test_uptime_check_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.monitoring_v3.services.uptime_check_service.transports.UptimeCheckServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.monitoring_v3.services.uptime_check_service.transports.UptimeCheckServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UptimeCheckServiceTransport( @@ -4216,9 +4226,12 @@ def test_uptime_check_service_base_transport_with_credentials_file(): def test_uptime_check_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.monitoring_v3.services.uptime_check_service.transports.UptimeCheckServiceTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.monitoring_v3.services.uptime_check_service.transports.UptimeCheckServiceTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.UptimeCheckServiceTransport() @@ -4297,11 +4310,12 @@ def test_uptime_check_service_transport_auth_gdch_credentials(transport_class): def test_uptime_check_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/async_client.py b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/async_client.py index 3d6381841c48..1f02cc4d84a2 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/async_client.py +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/async_client.py @@ -229,7 +229,7 @@ def transport(self) -> NetAppTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -8841,7 +8841,7 @@ async def sample_delete_host_group(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8867,8 +8867,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8877,7 +8881,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8885,7 +8889,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8896,7 +8900,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8922,8 +8926,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8932,7 +8940,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8940,7 +8948,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -8951,7 +8959,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -8981,8 +8989,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -8991,7 +9003,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -8999,7 +9011,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9007,7 +9019,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9036,8 +9048,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9046,7 +9062,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9054,7 +9070,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9062,7 +9078,7 @@ async def cancel_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9088,8 +9104,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9098,7 +9118,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9106,7 +9126,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9117,7 +9137,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9143,8 +9163,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9153,7 +9177,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9161,7 +9185,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/client.py b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/client.py index 6f8cc1f68bdb..cb04a41b1b39 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/client.py +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/client.py @@ -141,7 +141,7 @@ class NetAppClient(metaclass=NetAppClientMeta): """NetApp Files Google Cloud Service""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -149,7 +149,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -159,6 +159,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -713,7 +717,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -810,7 +814,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -906,7 +910,7 @@ def __init__( self._universe_domain = NetAppClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -9335,7 +9339,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9361,8 +9365,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9371,7 +9379,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9380,7 +9388,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9394,7 +9402,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9420,8 +9428,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9430,7 +9442,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9439,7 +9451,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9453,7 +9465,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9483,8 +9495,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9493,7 +9509,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9501,7 +9517,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9509,7 +9525,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9538,8 +9554,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9548,7 +9568,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9556,7 +9576,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9564,7 +9584,7 @@ def cancel_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9590,8 +9610,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9600,7 +9624,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9609,7 +9633,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -9623,7 +9647,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -9649,8 +9673,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -9659,7 +9687,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -9668,7 +9696,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/README.rst b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/README.rst index 16bd00900281..0d78ef1e2bd3 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/README.rst +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`NetAppTransport` is the ABC for all transports. -- public child `NetAppGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `NetAppGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseNetAppRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `NetAppRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``NetAppTransport`` is the ABC for all transports. + +- public child ``NetAppGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``NetAppGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseNetAppRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``NetAppRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/base.py b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/base.py index e987f9b73fed..461a27873215 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/base.py +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/base.py @@ -104,6 +104,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -153,6 +157,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc.py b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc.py index 9dd740c8facd..94f6dcee0e11 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc.py +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc.py @@ -78,7 +78,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -113,7 +113,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -208,6 +208,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc_asyncio.py b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc_asyncio.py index 350e6824ef69..3c20137223b4 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc_asyncio.py +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/grpc_asyncio.py @@ -84,7 +84,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -119,7 +119,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -259,6 +259,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/rest.py b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/rest.py index f110055041f8..3e661dc4fcdb 100644 --- a/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/rest.py +++ b/packages/google-cloud-netapp/google/cloud/netapp_v1/services/net_app/transports/rest.py @@ -3985,6 +3985,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[NetAppRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. diff --git a/packages/google-cloud-netapp/noxfile.py b/packages/google-cloud-netapp/noxfile.py index 615e36e1427d..fe15bd378bf3 100644 --- a/packages/google-cloud-netapp/noxfile.py +++ b/packages/google-cloud-netapp/noxfile.py @@ -31,8 +31,6 @@ LINT_PATHS.append("samples") ALL_PYTHON = [ - "3.7", - "3.8", "3.9", "3.10", "3.11", @@ -95,8 +93,9 @@ @nox.session(python=ALL_PYTHON) def mypy(session): """Run the type checker.""" + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579): + # use the latest version of mypy session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy "mypy<1.16.0", "types-requests", "types-protobuf", @@ -106,6 +105,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) @@ -297,7 +298,10 @@ def unit(session, protobuf_implementation): def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") + if session.python >= "3.12": + session.install("--pre", "grpcio>=1.75.1") + else: + session.install("--pre", "grpcio<=1.62.2") session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) @@ -527,7 +531,7 @@ def prerelease_deps(session, protobuf_implementation): "google-api-core", "google-auth", "grpc-google-iam-v1", - "grpcio", + "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", "protobuf", "proto-plus", @@ -622,7 +626,7 @@ def core_deps_from_source(session, protobuf_implementation): core_dependencies_from_source = [ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "google-auth @ git+https://github.com/googleapis/google-cloud-python#egg=google-auth&subdirectory=packages/google-auth", "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", "proto-plus @ git+https://github.com/googleapis/google-cloud-python#egg=proto-plus&subdirectory=packages/proto-plus", ] diff --git a/packages/google-cloud-netapp/setup.py b/packages/google-cloud-netapp/setup.py index d1d91065c608..a013c057e857 100644 --- a/packages/google-cloud-netapp/setup.py +++ b/packages/google-cloud-netapp/setup.py @@ -39,7 +39,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "google-api-core[grpc] >= 2.11.0, <3.0.0", # Exclude incompatible versions of `google-auth` # See https://github.com/googleapis/google-cloud-python/issues/12364 "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", @@ -47,7 +47,7 @@ "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", "proto-plus >= 1.22.3, <2.0.0", "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf >= 4.25.8, < 8.0.0", ] extras = {} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-netapp" @@ -79,8 +79,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -92,7 +90,7 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - python_requires=">=3.7", + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, include_package_data=True, diff --git a/packages/google-cloud-netapp/testing/constraints-3.7.txt b/packages/google-cloud-netapp/testing/constraints-3.7.txt deleted file mode 100644 index bbf88e9745ae..000000000000 --- a/packages/google-cloud-netapp/testing/constraints-3.7.txt +++ /dev/null @@ -1,14 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -# cryptography is a direct dependency of google-auth -cryptography==38.0.3 -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) -# Add the minimum supported version of grpcio to constraints files -proto-plus==1.22.3 -protobuf==3.20.2 diff --git a/packages/google-cloud-netapp/testing/constraints-3.8.txt b/packages/google-cloud-netapp/testing/constraints-3.8.txt deleted file mode 100644 index 7599dea499ed..000000000000 --- a/packages/google-cloud-netapp/testing/constraints-3.8.txt +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography diff --git a/packages/google-cloud-netapp/testing/constraints-3.9.txt b/packages/google-cloud-netapp/testing/constraints-3.9.txt index 7599dea499ed..ac3833d41b9a 100644 --- a/packages/google-cloud-netapp/testing/constraints-3.9.txt +++ b/packages/google-cloud-netapp/testing/constraints-3.9.txt @@ -1,10 +1,13 @@ # -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -google-auth -grpcio -proto-plus -protobuf -# cryptography is a direct dependency of google-auth -cryptography +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-netapp/tests/unit/gapic/netapp_v1/test_net_app.py b/packages/google-cloud-netapp/tests/unit/gapic/netapp_v1/test_net_app.py index dc22c91a7d18..dd69375c4af2 100644 --- a/packages/google-cloud-netapp/tests/unit/gapic/netapp_v1/test_net_app.py +++ b/packages/google-cloud-netapp/tests/unit/gapic/netapp_v1/test_net_app.py @@ -153,6 +153,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert NetAppClient._get_default_mtls_endpoint(None) is None assert NetAppClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -168,6 +169,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert NetAppClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert NetAppClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -1246,11 +1248,13 @@ def test_net_app_client_create_channel_credentials_file( ) # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object(grpc_helpers, "create_channel") as create_channel: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object(grpc_helpers, "create_channel") as create_channel, + ): creds = ga_credentials.AnonymousCredentials() file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) @@ -41873,8 +41877,9 @@ def test_list_storage_pools_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -41937,17 +41942,19 @@ def test_list_storage_pools_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_storage_pools" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_storage_pools_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_storage_pools" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_storage_pools" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_storage_pools_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_storage_pools" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42005,8 +42012,9 @@ def test_create_storage_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42162,19 +42170,20 @@ def test_create_storage_pool_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_storage_pool" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_storage_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_storage_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_storage_pool" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_storage_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_storage_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42227,8 +42236,9 @@ def test_get_storage_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42347,17 +42357,19 @@ def test_get_storage_pool_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_storage_pool" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_storage_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_storage_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_storage_pool" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_storage_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_storage_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42414,8 +42426,9 @@ def test_update_storage_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42575,19 +42588,20 @@ def test_update_storage_pool_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_storage_pool" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_storage_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_storage_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_storage_pool" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_storage_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_storage_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42640,8 +42654,9 @@ def test_delete_storage_pool_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42696,19 +42711,20 @@ def test_delete_storage_pool_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_storage_pool" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_storage_pool_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_storage_pool" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_storage_pool" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_storage_pool_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_storage_pool" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42761,8 +42777,9 @@ def test_validate_directory_service_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42817,20 +42834,21 @@ def test_validate_directory_service_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_validate_directory_service" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, - "post_validate_directory_service_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_validate_directory_service" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_validate_directory_service" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_validate_directory_service_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_validate_directory_service" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -42883,8 +42901,9 @@ def test_switch_active_replica_zone_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -42939,20 +42958,21 @@ def test_switch_active_replica_zone_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_switch_active_replica_zone" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, - "post_switch_active_replica_zone_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_switch_active_replica_zone" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_switch_active_replica_zone" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_switch_active_replica_zone_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_switch_active_replica_zone" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43003,8 +43023,9 @@ def test_list_volumes_rest_bad_request(request_type=volume.ListVolumesRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43067,17 +43088,17 @@ def test_list_volumes_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_volumes" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_volumes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_volumes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_volumes" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_volumes_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_list_volumes") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43126,8 +43147,9 @@ def test_get_volume_rest_bad_request(request_type=volume.GetVolumeRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43248,17 +43270,15 @@ def test_get_volume_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_volume" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetAppRestInterceptor, "post_get_volume") as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_volume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_get_volume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43307,8 +43327,9 @@ def test_create_volume_rest_bad_request(request_type=gcn_volume.CreateVolumeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43585,19 +43606,18 @@ def test_create_volume_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_volume" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_volume" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_volume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_create_volume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43648,8 +43668,9 @@ def test_update_volume_rest_bad_request(request_type=gcn_volume.UpdateVolumeRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -43928,19 +43949,18 @@ def test_update_volume_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_volume" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_volume" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_volume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_update_volume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -43989,8 +44009,9 @@ def test_delete_volume_rest_bad_request(request_type=volume.DeleteVolumeRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44045,19 +44066,18 @@ def test_delete_volume_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_volume" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_volume" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_volume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_delete_volume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44106,8 +44126,9 @@ def test_revert_volume_rest_bad_request(request_type=volume.RevertVolumeRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44162,19 +44183,18 @@ def test_revert_volume_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_revert_volume" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_revert_volume_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_revert_volume" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_revert_volume" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_revert_volume_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_revert_volume") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44223,8 +44243,9 @@ def test_list_snapshots_rest_bad_request(request_type=snapshot.ListSnapshotsRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44287,17 +44308,19 @@ def test_list_snapshots_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_snapshots" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_snapshots_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_snapshots" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_snapshots" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_snapshots_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_snapshots" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44350,8 +44373,9 @@ def test_get_snapshot_rest_bad_request(request_type=snapshot.GetSnapshotRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44422,17 +44446,17 @@ def test_get_snapshot_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_snapshot" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_snapshot" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_get_snapshot") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44483,8 +44507,9 @@ def test_create_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44615,19 +44640,20 @@ def test_create_snapshot_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_snapshot" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_snapshot" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44680,8 +44706,9 @@ def test_delete_snapshot_rest_bad_request(request_type=snapshot.DeleteSnapshotRe request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44738,19 +44765,20 @@ def test_delete_snapshot_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_snapshot" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_snapshot" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -44805,8 +44833,9 @@ def test_update_snapshot_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -44941,19 +44970,20 @@ def test_update_snapshot_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_snapshot" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_snapshot_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_snapshot" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_snapshot" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_snapshot_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_snapshot" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45006,8 +45036,9 @@ def test_list_active_directories_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45070,17 +45101,20 @@ def test_list_active_directories_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_active_directories" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_active_directories_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_active_directories" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_active_directories" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_list_active_directories_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_active_directories" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45140,8 +45174,9 @@ def test_get_active_directory_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45242,17 +45277,19 @@ def test_get_active_directory_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_active_directory" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_active_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_active_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_active_directory" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_active_directory_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_active_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45307,8 +45344,9 @@ def test_create_active_directory_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45459,19 +45497,21 @@ def test_create_active_directory_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_active_directory" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_active_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_active_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_active_directory" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_create_active_directory_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_active_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45528,8 +45568,9 @@ def test_update_active_directory_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45684,19 +45725,21 @@ def test_update_active_directory_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_active_directory" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_active_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_active_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_active_directory" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_update_active_directory_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_active_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45751,8 +45794,9 @@ def test_delete_active_directory_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45809,19 +45853,21 @@ def test_delete_active_directory_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_active_directory" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_active_directory_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_active_directory" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_active_directory" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_delete_active_directory_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_active_directory" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45872,8 +45918,9 @@ def test_list_kms_configs_rest_bad_request(request_type=kms.ListKmsConfigsReques request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -45936,17 +45983,19 @@ def test_list_kms_configs_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_kms_configs" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_kms_configs_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_kms_configs" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_kms_configs" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_kms_configs_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_kms_configs" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -45995,8 +46044,9 @@ def test_create_kms_config_rest_bad_request(request_type=kms.CreateKmsConfigRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46129,19 +46179,20 @@ def test_create_kms_config_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_kms_config" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_kms_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_kms_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_kms_config" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_kms_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_kms_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46190,8 +46241,9 @@ def test_get_kms_config_rest_bad_request(request_type=kms.GetKmsConfigRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46264,17 +46316,19 @@ def test_get_kms_config_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_kms_config" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_kms_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_kms_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_kms_config" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_kms_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_kms_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46325,8 +46379,9 @@ def test_update_kms_config_rest_bad_request(request_type=kms.UpdateKmsConfigRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46461,19 +46516,20 @@ def test_update_kms_config_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_kms_config" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_kms_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_kms_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_kms_config" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_kms_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_kms_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46522,8 +46578,9 @@ def test_encrypt_volumes_rest_bad_request(request_type=kms.EncryptVolumesRequest request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46578,19 +46635,20 @@ def test_encrypt_volumes_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_encrypt_volumes" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_encrypt_volumes_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_encrypt_volumes" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_encrypt_volumes" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_encrypt_volumes_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_encrypt_volumes" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46639,8 +46697,9 @@ def test_verify_kms_config_rest_bad_request(request_type=kms.VerifyKmsConfigRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46705,17 +46764,19 @@ def test_verify_kms_config_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_verify_kms_config" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_verify_kms_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_verify_kms_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_verify_kms_config" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_verify_kms_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_verify_kms_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46766,8 +46827,9 @@ def test_delete_kms_config_rest_bad_request(request_type=kms.DeleteKmsConfigRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46822,19 +46884,20 @@ def test_delete_kms_config_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_kms_config" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_kms_config_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_kms_config" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_kms_config" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_kms_config_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_kms_config" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -46885,8 +46948,9 @@ def test_list_replications_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -46949,17 +47013,19 @@ def test_list_replications_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_replications" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_replications_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_replications" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_replications" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_replications_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_replications" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47019,8 +47085,9 @@ def test_get_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47111,17 +47178,19 @@ def test_get_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47174,8 +47243,9 @@ def test_create_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47346,19 +47416,20 @@ def test_create_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47413,8 +47484,9 @@ def test_delete_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47471,19 +47543,20 @@ def test_delete_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47540,8 +47613,9 @@ def test_update_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47716,19 +47790,20 @@ def test_update_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47783,8 +47858,9 @@ def test_stop_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47841,19 +47917,20 @@ def test_stop_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_stop_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_stop_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_stop_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_stop_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_stop_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_stop_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -47908,8 +47985,9 @@ def test_resume_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -47966,19 +48044,20 @@ def test_resume_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_resume_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_resume_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_resume_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_resume_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_resume_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_resume_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48033,8 +48112,9 @@ def test_reverse_replication_direction_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48091,20 +48171,21 @@ def test_reverse_replication_direction_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_reverse_replication_direction" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, - "post_reverse_replication_direction_with_metadata", - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_reverse_replication_direction" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_reverse_replication_direction" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, + "post_reverse_replication_direction_with_metadata", + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_reverse_replication_direction" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48159,8 +48240,9 @@ def test_establish_peering_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48217,19 +48299,20 @@ def test_establish_peering_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_establish_peering" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_establish_peering_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_establish_peering" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_establish_peering" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_establish_peering_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_establish_peering" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48284,8 +48367,9 @@ def test_sync_replication_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48342,19 +48426,20 @@ def test_sync_replication_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_sync_replication" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_sync_replication_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_sync_replication" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_sync_replication" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_sync_replication_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_sync_replication" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48407,8 +48492,9 @@ def test_create_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48552,19 +48638,20 @@ def test_create_backup_vault_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_backup_vault" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_backup_vault" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48617,8 +48704,9 @@ def test_get_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48704,17 +48792,19 @@ def test_get_backup_vault_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_backup_vault" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_backup_vault" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48767,8 +48857,9 @@ def test_list_backup_vaults_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -48831,17 +48922,19 @@ def test_list_backup_vaults_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_backup_vaults" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_backup_vaults_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_backup_vaults" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_backup_vaults" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_backup_vaults_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_backup_vaults" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -48903,8 +48996,9 @@ def test_update_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49052,19 +49146,20 @@ def test_update_backup_vault_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_backup_vault" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_backup_vault" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49117,8 +49212,9 @@ def test_delete_backup_vault_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49173,19 +49269,20 @@ def test_delete_backup_vault_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_backup_vault" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_backup_vault_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_backup_vault" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_backup_vault" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_backup_vault_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_backup_vault" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49236,8 +49333,9 @@ def test_create_backup_rest_bad_request(request_type=gcn_backup.CreateBackupRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49376,19 +49474,18 @@ def test_create_backup_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_backup" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_backup" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_create_backup") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49439,8 +49536,9 @@ def test_get_backup_rest_bad_request(request_type=backup.GetBackupRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49525,17 +49623,15 @@ def test_get_backup_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_backup" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(transports.NetAppRestInterceptor, "post_get_backup") as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_get_backup") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49584,8 +49680,9 @@ def test_list_backups_rest_bad_request(request_type=backup.ListBackupsRequest): request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49648,17 +49745,17 @@ def test_list_backups_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_backups" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_backups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_backups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_backups" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_backups_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_list_backups") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49709,8 +49806,9 @@ def test_delete_backup_rest_bad_request(request_type=backup.DeleteBackupRequest) request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49767,19 +49865,18 @@ def test_delete_backup_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_backup" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_backup" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_delete_backup") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -49832,8 +49929,9 @@ def test_update_backup_rest_bad_request(request_type=gcn_backup.UpdateBackupRequ request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -49976,19 +50074,18 @@ def test_update_backup_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_backup" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_backup_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_backup" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_backup" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_backup_with_metadata" + ) as post_with_metadata, + mock.patch.object(transports.NetAppRestInterceptor, "pre_update_backup") as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50039,8 +50136,9 @@ def test_create_backup_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50176,19 +50274,20 @@ def test_create_backup_policy_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_backup_policy" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_backup_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_backup_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_backup_policy" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_backup_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_backup_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50241,8 +50340,9 @@ def test_get_backup_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50317,17 +50417,19 @@ def test_get_backup_policy_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_backup_policy" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_backup_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_backup_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_backup_policy" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_backup_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_backup_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50380,8 +50482,9 @@ def test_list_backup_policies_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50444,17 +50547,19 @@ def test_list_backup_policies_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_backup_policies" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_backup_policies_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_backup_policies" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_backup_policies" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_backup_policies_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_backup_policies" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50516,8 +50621,9 @@ def test_update_backup_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50657,19 +50763,20 @@ def test_update_backup_policy_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_backup_policy" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_backup_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_backup_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_backup_policy" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_backup_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_backup_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50722,8 +50829,9 @@ def test_delete_backup_policy_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50778,19 +50886,20 @@ def test_delete_backup_policy_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_backup_policy" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_backup_policy_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_backup_policy" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_backup_policy" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_backup_policy_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_backup_policy" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50843,8 +50952,9 @@ def test_list_quota_rules_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -50907,17 +51017,19 @@ def test_list_quota_rules_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_quota_rules" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_quota_rules_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_quota_rules" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_quota_rules" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_quota_rules_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_quota_rules" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -50972,8 +51084,9 @@ def test_get_quota_rule_rest_bad_request(request_type=quota_rule.GetQuotaRuleReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51048,17 +51161,19 @@ def test_get_quota_rule_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_quota_rule" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_quota_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_quota_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_quota_rule" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_quota_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_quota_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51109,8 +51224,9 @@ def test_create_quota_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51243,19 +51359,20 @@ def test_create_quota_rule_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_quota_rule" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_quota_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_quota_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_quota_rule" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_quota_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_quota_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51312,8 +51429,9 @@ def test_update_quota_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51450,19 +51568,20 @@ def test_update_quota_rule_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_quota_rule" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_quota_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_quota_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_quota_rule" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_quota_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_quota_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51517,8 +51636,9 @@ def test_delete_quota_rule_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51575,19 +51695,20 @@ def test_delete_quota_rule_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_quota_rule" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_quota_rule_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_quota_rule" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_quota_rule" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_quota_rule_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_quota_rule" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51640,8 +51761,9 @@ def test_restore_backup_files_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51696,19 +51818,20 @@ def test_restore_backup_files_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_restore_backup_files" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_restore_backup_files_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_restore_backup_files" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_restore_backup_files" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_restore_backup_files_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_restore_backup_files" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51761,8 +51884,9 @@ def test_list_host_groups_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51825,17 +51949,19 @@ def test_list_host_groups_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_host_groups" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_list_host_groups_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_list_host_groups" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_host_groups" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_list_host_groups_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_list_host_groups" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -51888,8 +52014,9 @@ def test_get_host_group_rest_bad_request(request_type=host_group.GetHostGroupReq request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -51960,17 +52087,19 @@ def test_get_host_group_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_host_group" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_get_host_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_get_host_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_host_group" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_get_host_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_get_host_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52021,8 +52150,9 @@ def test_create_host_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52154,19 +52284,20 @@ def test_create_host_group_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_create_host_group" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_create_host_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_create_host_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_host_group" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_create_host_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_create_host_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52221,8 +52352,9 @@ def test_update_host_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52356,19 +52488,20 @@ def test_update_host_group_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_update_host_group" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_update_host_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_update_host_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_host_group" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_update_host_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_update_host_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52421,8 +52554,9 @@ def test_delete_host_group_rest_bad_request( request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = mock.Mock() @@ -52477,19 +52611,20 @@ def test_delete_host_group_rest_interceptors(null_interceptor): ) client = NetAppClient(transport=transport) - with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - operation.Operation, "_set_result_from_operation" - ), mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_host_group" - ) as post, mock.patch.object( - transports.NetAppRestInterceptor, "post_delete_host_group_with_metadata" - ) as post_with_metadata, mock.patch.object( - transports.NetAppRestInterceptor, "pre_delete_host_group" - ) as pre: + with ( + mock.patch.object(type(client.transport._session), "request") as req, + mock.patch.object(path_template, "transcode") as transcode, + mock.patch.object(operation.Operation, "_set_result_from_operation"), + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_host_group" + ) as post, + mock.patch.object( + transports.NetAppRestInterceptor, "post_delete_host_group_with_metadata" + ) as post_with_metadata, + mock.patch.object( + transports.NetAppRestInterceptor, "pre_delete_host_group" + ) as pre, + ): pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -52542,8 +52677,9 @@ def test_get_location_rest_bad_request(request_type=locations_pb2.GetLocationReq ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -52602,8 +52738,9 @@ def test_list_locations_rest_bad_request( request = json_format.ParseDict({"name": "projects/sample1"}, request) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -52664,8 +52801,9 @@ def test_cancel_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -52726,8 +52864,9 @@ def test_delete_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -52788,8 +52927,9 @@ def test_get_operation_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -52850,8 +52990,9 @@ def test_list_operations_rest_bad_request( ) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest + with ( + mock.patch.object(Session, "request") as req, + pytest.raises(core_exceptions.BadRequest), ): # Wrap the value into a proper Response obj response_value = Response() @@ -54448,11 +54589,14 @@ def test_net_app_base_transport(): def test_net_app_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.netapp_v1.services.net_app.transports.NetAppTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, + mock.patch( + "google.cloud.netapp_v1.services.net_app.transports.NetAppTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetAppTransport( @@ -54469,9 +54613,12 @@ def test_net_app_base_transport_with_credentials_file(): def test_net_app_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.netapp_v1.services.net_app.transports.NetAppTransport._prep_wrapped_messages" - ) as Transport: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch( + "google.cloud.netapp_v1.services.net_app.transports.NetAppTransport._prep_wrapped_messages" + ) as Transport, + ): Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.NetAppTransport() @@ -54543,11 +54690,12 @@ def test_net_app_transport_auth_gdch_credentials(transport_class): def test_net_app_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: + with ( + mock.patch.object(google.auth, "default", autospec=True) as adc, + mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel, + ): creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -55629,6 +55777,38 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_delete_operation_flattened(): + client = NetAppClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = NetAppAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + + def test_cancel_operation(transport: str = "grpc"): client = NetAppClient( credentials=ga_credentials.AnonymousCredentials(), @@ -55768,6 +55948,38 @@ async def test_cancel_operation_from_dict_async(): call.assert_called() +def test_cancel_operation_flattened(): + client = NetAppClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = NetAppAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + + def test_get_operation(transport: str = "grpc"): client = NetAppClient( credentials=ga_credentials.AnonymousCredentials(), @@ -55913,6 +56125,40 @@ async def test_get_operation_from_dict_async(): call.assert_called() +def test_get_operation_flattened(): + client = NetAppClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = NetAppAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + + def test_list_operations(transport: str = "grpc"): client = NetAppClient( credentials=ga_credentials.AnonymousCredentials(), @@ -56058,6 +56304,40 @@ async def test_list_operations_from_dict_async(): call.assert_called() +def test_list_operations_flattened(): + client = NetAppClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = NetAppAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + + def test_list_locations(transport: str = "grpc"): client = NetAppClient( credentials=ga_credentials.AnonymousCredentials(), @@ -56203,6 +56483,40 @@ async def test_list_locations_from_dict_async(): call.assert_called() +def test_list_locations_flattened(): + client = NetAppClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = NetAppAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + + def test_get_location(transport: str = "grpc"): client = NetAppClient( credentials=ga_credentials.AnonymousCredentials(), @@ -56344,6 +56658,40 @@ async def test_get_location_from_dict_async(): call.assert_called() +def test_get_location_flattened(): + client = NetAppClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = NetAppAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + + def test_transport_close_grpc(): client = NetAppClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc" diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/async_client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/async_client.py index 69ad7a7e190d..9697d55abca6 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/async_client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/async_client.py @@ -253,7 +253,7 @@ def transport(self) -> CrossNetworkAutomationServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2825,7 +2825,7 @@ async def sample_delete_service_connection_token(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2851,8 +2851,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2861,7 +2865,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2869,7 +2873,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2880,7 +2884,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2906,8 +2910,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2916,7 +2924,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2924,7 +2932,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2935,7 +2943,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2965,8 +2973,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2975,7 +2987,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2983,7 +2995,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2991,7 +3003,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3020,8 +3032,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3030,7 +3046,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3038,7 +3054,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3046,7 +3062,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3138,8 +3154,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3148,7 +3168,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3156,7 +3178,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3167,7 +3189,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3260,8 +3282,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3270,7 +3296,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3278,7 +3306,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3289,7 +3317,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3320,8 +3348,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3332,7 +3364,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3340,7 +3374,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3351,7 +3385,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3377,8 +3411,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3387,7 +3425,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3395,7 +3433,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3406,7 +3444,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3432,8 +3470,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3442,7 +3484,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3450,7 +3492,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/client.py index 5794f375e75e..b950f13833ef 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/client.py @@ -125,7 +125,7 @@ class CrossNetworkAutomationServiceClient( """The service for CrossNetworkAutomation resources.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -133,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -143,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -598,7 +602,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -697,7 +701,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -801,7 +805,7 @@ def __init__( universe_domain_opt, self._universe_domain_env ) ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3349,7 +3353,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3375,8 +3379,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3385,7 +3393,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3394,7 +3402,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3408,7 +3416,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3434,8 +3442,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3444,7 +3456,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3453,7 +3465,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3467,7 +3479,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3497,8 +3509,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3507,7 +3523,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3515,7 +3531,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3523,7 +3539,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3552,8 +3568,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3562,7 +3582,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3570,7 +3590,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3578,7 +3598,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3670,8 +3690,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3680,7 +3704,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3689,7 +3715,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3703,7 +3729,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3796,8 +3822,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3806,7 +3836,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3815,7 +3847,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3829,7 +3861,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3860,8 +3892,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3870,7 +3906,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3879,7 +3917,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3893,7 +3931,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3919,8 +3957,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3929,7 +3971,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3938,7 +3980,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3952,7 +3994,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3978,8 +4020,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3988,7 +4034,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3997,7 +4043,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/README.rst b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/README.rst index 62c230e1561c..e304da45a171 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/README.rst +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`CrossNetworkAutomationServiceTransport` is the ABC for all transports. -- public child `CrossNetworkAutomationServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `CrossNetworkAutomationServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseCrossNetworkAutomationServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `CrossNetworkAutomationServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``CrossNetworkAutomationServiceTransport`` is the ABC for all transports. + +- public child ``CrossNetworkAutomationServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``CrossNetworkAutomationServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseCrossNetworkAutomationServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``CrossNetworkAutomationServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/base.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/base.py index 2cf958b56858..d6c110c468b0 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/base.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc.py index b597f134ec86..3e415205174f 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -192,6 +192,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc_asyncio.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc_asyncio.py index da2b45ea5ba6..03c86d61c338 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/cross_network_automation_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -243,6 +243,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/async_client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/async_client.py index 19ec78abb8a9..21d7ee3409ea 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/async_client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/async_client.py @@ -213,7 +213,7 @@ def transport(self) -> DataTransferServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1950,7 +1950,7 @@ async def sample_list_multicloud_data_transfer_supported_services(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1976,8 +1976,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1986,7 +1990,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1994,7 +1998,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2005,7 +2009,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2031,8 +2035,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2041,7 +2049,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2049,7 +2057,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2060,7 +2068,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2090,8 +2098,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2100,7 +2112,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2108,7 +2120,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2116,7 +2128,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2145,8 +2157,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2155,7 +2171,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2163,7 +2179,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2171,7 +2187,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2263,8 +2279,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2273,7 +2293,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2281,7 +2303,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2292,7 +2314,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2385,8 +2407,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2395,7 +2421,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2403,7 +2431,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2414,7 +2442,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2445,8 +2473,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2457,7 +2489,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2465,7 +2499,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2476,7 +2510,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2502,8 +2536,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2512,7 +2550,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2520,7 +2558,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2531,7 +2569,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2557,8 +2595,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2567,7 +2609,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2575,7 +2617,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/client.py index bd86e31201f0..0733915d64c8 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/client.py @@ -119,7 +119,7 @@ class DataTransferServiceClient(metaclass=DataTransferServiceClientMeta): """DataTransferService is the service for the Data Transfer API.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -127,7 +127,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -137,6 +137,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -492,7 +496,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -589,7 +593,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -689,7 +693,7 @@ def __init__( self._universe_domain = DataTransferServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2406,7 +2410,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2432,8 +2436,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2442,7 +2450,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2451,7 +2459,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2465,7 +2473,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2491,8 +2499,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2501,7 +2513,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2510,7 +2522,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2524,7 +2536,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2554,8 +2566,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2564,7 +2580,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2572,7 +2588,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2580,7 +2596,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2609,8 +2625,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2619,7 +2639,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2627,7 +2647,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2635,7 +2655,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2727,8 +2747,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2737,7 +2761,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2746,7 +2772,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2760,7 +2786,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2853,8 +2879,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2863,7 +2893,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2872,7 +2904,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2886,7 +2918,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2917,8 +2949,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2927,7 +2963,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -2936,7 +2974,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2950,7 +2988,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2976,8 +3014,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2986,7 +3028,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2995,7 +3037,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3009,7 +3051,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3035,8 +3077,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3045,7 +3091,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3054,7 +3100,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/README.rst b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/README.rst index 6f9ef878ffff..0c85aedd771b 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/README.rst +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`DataTransferServiceTransport` is the ABC for all transports. -- public child `DataTransferServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `DataTransferServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseDataTransferServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `DataTransferServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``DataTransferServiceTransport`` is the ABC for all transports. + +- public child ``DataTransferServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``DataTransferServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseDataTransferServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``DataTransferServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/base.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/base.py index a169823fede5..14b9a8a86bfa 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/base.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/base.py @@ -86,6 +86,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -135,6 +139,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc.py index df4d4b6f3462..27d0e496a3dd 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc.py @@ -60,7 +60,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -190,6 +190,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc_asyncio.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc_asyncio.py index e3bfe2c54b95..1d65efb730a6 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/data_transfer_service/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +101,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -241,6 +241,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/async_client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/async_client.py index 87bf56bbf41c..1e4ee062f971 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/async_client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/async_client.py @@ -216,7 +216,7 @@ def transport(self) -> HubServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3367,7 +3367,7 @@ async def sample_update_group(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3393,8 +3393,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3403,7 +3407,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3411,7 +3415,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3422,7 +3426,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3448,8 +3452,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3458,7 +3466,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3466,7 +3474,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3477,7 +3485,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3507,8 +3515,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3517,7 +3529,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3525,7 +3537,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3533,7 +3545,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3562,8 +3574,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3572,7 +3588,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3580,7 +3596,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3588,7 +3604,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3680,8 +3696,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3690,7 +3710,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3698,7 +3720,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3709,7 +3731,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3802,8 +3824,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3812,7 +3838,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3820,7 +3848,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3831,7 +3859,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3862,8 +3890,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3874,7 +3906,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -3882,7 +3916,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3893,7 +3927,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3919,8 +3953,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3929,7 +3967,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3937,7 +3975,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3948,7 +3986,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3974,8 +4012,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3984,7 +4026,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3992,7 +4034,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/client.py index 023928a45b2d..9c176b6d162a 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/client.py @@ -124,7 +124,7 @@ class HubServiceClient(metaclass=HubServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -621,7 +625,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -718,7 +722,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -814,7 +818,7 @@ def __init__( self._universe_domain = HubServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3896,7 +3900,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3922,8 +3926,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3932,7 +3940,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -3941,7 +3949,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -3955,7 +3963,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3981,8 +3989,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3991,7 +4003,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4000,7 +4012,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4014,7 +4026,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4044,8 +4056,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4054,7 +4070,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4062,7 +4078,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4070,7 +4086,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4099,8 +4115,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4109,7 +4129,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4117,7 +4137,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4125,7 +4145,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4217,8 +4237,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4227,7 +4251,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4236,7 +4262,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4250,7 +4276,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4343,8 +4369,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4353,7 +4383,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4362,7 +4394,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4376,7 +4408,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4407,8 +4439,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4417,7 +4453,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -4426,7 +4464,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4440,7 +4478,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4466,8 +4504,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4476,7 +4518,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4485,7 +4527,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -4499,7 +4541,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4525,8 +4567,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4535,7 +4581,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -4544,7 +4590,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/README.rst b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/README.rst index 741809051fa0..5bfd252f1e91 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/README.rst +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`HubServiceTransport` is the ABC for all transports. -- public child `HubServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `HubServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseHubServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `HubServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``HubServiceTransport`` is the ABC for all transports. + +- public child ``HubServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``HubServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseHubServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``HubServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/base.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/base.py index 020c729e7c31..62be4e139223 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/base.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/base.py @@ -87,6 +87,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -136,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc.py index 3e99c16316cb..cddd68235838 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc.py @@ -61,7 +61,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +96,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc_asyncio.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc_asyncio.py index b6c2304028dd..d13bad26ab45 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/hub_service/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +102,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/async_client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/async_client.py index 85b20b40a94f..b5ba951ab3c2 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/async_client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/async_client.py @@ -206,7 +206,7 @@ def transport(self) -> InternalRangeServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -995,7 +995,7 @@ async def sample_delete_internal_range(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1021,8 +1021,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1031,7 +1035,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1039,7 +1043,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1050,7 +1054,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1076,8 +1080,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1086,7 +1094,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1094,7 +1102,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1105,7 +1113,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1135,8 +1143,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1145,7 +1157,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1153,7 +1165,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1161,7 +1173,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1190,8 +1202,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1200,7 +1216,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1208,7 +1224,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1216,7 +1232,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1308,8 +1324,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1318,7 +1338,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1326,7 +1348,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1337,7 +1359,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1430,8 +1452,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1440,7 +1466,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1448,7 +1476,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1459,7 +1487,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1490,8 +1518,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1502,7 +1534,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1510,7 +1544,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1521,7 +1555,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1547,8 +1581,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1557,7 +1595,7 @@ async def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1565,7 +1603,7 @@ async def get_location( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1576,7 +1614,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1602,8 +1640,12 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1612,7 +1654,7 @@ async def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1620,7 +1662,7 @@ async def list_locations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/client.py index 0d49e19f345c..cac512f8a83d 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/client.py @@ -124,7 +124,7 @@ class InternalRangeServiceClient(metaclass=InternalRangeServiceClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -132,7 +132,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -142,6 +142,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -449,7 +453,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -546,7 +550,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -646,7 +650,7 @@ def __init__( self._universe_domain = InternalRangeServiceClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1418,7 +1422,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1444,8 +1448,12 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1454,7 +1462,7 @@ def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1463,7 +1471,7 @@ def list_operations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1477,7 +1485,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1503,8 +1511,12 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1513,7 +1525,7 @@ def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1522,7 +1534,7 @@ def get_operation( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1536,7 +1548,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1566,8 +1578,12 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1576,7 +1592,7 @@ def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1584,7 +1600,7 @@ def delete_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1592,7 +1608,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1621,8 +1637,12 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1631,7 +1651,7 @@ def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1639,7 +1659,7 @@ def cancel_operation( # Send the request. rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1647,7 +1667,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1739,8 +1759,12 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1749,7 +1773,9 @@ def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1758,7 +1784,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1772,7 +1798,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1865,8 +1891,12 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1875,7 +1905,9 @@ def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1884,7 +1916,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1898,7 +1930,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1929,8 +1961,12 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1939,7 +1975,9 @@ def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1948,7 +1986,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1962,7 +2000,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1988,8 +2026,12 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1998,7 +2040,7 @@ def get_location( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2007,7 +2049,7 @@ def get_location( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -2021,7 +2063,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2047,8 +2089,12 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + if request is None: + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2057,7 +2103,7 @@ def list_locations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -2066,7 +2112,7 @@ def list_locations( try: # Send the request. response = rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/README.rst b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/README.rst index 37c58d76c712..04b41fde6641 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/README.rst +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`InternalRangeServiceTransport` is the ABC for all transports. -- public child `InternalRangeServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `InternalRangeServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseInternalRangeServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `InternalRangeServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``InternalRangeServiceTransport`` is the ABC for all transports. + +- public child ``InternalRangeServiceGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``InternalRangeServiceGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseInternalRangeServiceRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``InternalRangeServiceRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/base.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/base.py index 4e54f8b917c3..07f433621a54 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/base.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/base.py @@ -89,6 +89,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Save the scopes. @@ -138,6 +142,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc.py index 6e36a9f9f652..91d38ae4cc2f 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -194,6 +194,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc_asyncio.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc_asyncio.py index dd1d698f85b2..81fe9b89a067 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/internal_range_service/transports/grpc_asyncio.py @@ -69,7 +69,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -104,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -245,6 +245,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/policy_based_routing_service/async_client.py b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/policy_based_routing_service/async_client.py index e29bf289f67f..8ebf9dfb2d5e 100644 --- a/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/policy_based_routing_service/async_client.py +++ b/packages/google-cloud-network-connectivity/google/cloud/networkconnectivity_v1/services/policy_based_routing_service/async_client.py @@ -221,7 +221,7 @@ def transport(self) -> PolicyBasedRoutingServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -887,7 +887,7 @@ async def sample_delete_policy_based_route(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -913,8 +913,12 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + if request is None: + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -923,7 +927,7 @@ async def list_operations( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -931,7 +935,7 @@ async def list_operations( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -942,7 +946,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -968,8 +972,12 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + if request is None: + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -978,7 +986,7 @@ async def get_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -986,7 +994,7 @@ async def get_operation( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -997,7 +1005,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1027,8 +1035,12 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + if request is None: + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1037,7 +1049,7 @@ async def delete_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1045,7 +1057,7 @@ async def delete_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1053,7 +1065,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1082,8 +1094,12 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + if request is None: + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1092,7 +1108,7 @@ async def cancel_operation( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)), ) # Validate the universe domain. @@ -1100,7 +1116,7 @@ async def cancel_operation( # Send the request. await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1108,7 +1124,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1200,8 +1216,12 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1210,7 +1230,9 @@ async def set_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1218,7 +1240,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1229,7 +1251,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1322,8 +1344,12 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + if request is None: + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1332,7 +1358,9 @@ async def get_iam_policy( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1340,7 +1368,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1351,7 +1379,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1382,8 +1410,12 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + if request is None: + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1394,7 +1426,9 @@ async def test_iam_permissions( # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata( + (("resource", request_pb.resource),) + ), ) # Validate the universe domain. @@ -1402,7 +1436,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, + request_pb, retry=retry, timeout=timeout, metadata=metadata, @@ -1413,7 +1447,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1439,8 +1473,12 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + if request is None: + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationReques{"code":"deadline_exceeded","msg":"operation timed out"}